PageSourceSearch

https://gk-atelier.com/wp-content/plugins/osm/js/OSeaM/map_utils.js?ver=7.1.3

js gk-atelier.com collected 2026-10-09 02:04:49 UTC 7,155 bytes, 241 lines download raw bytes

1/******************************************************************************
2 Javascript OpenLayers map_utils
3 author Olaf Hannemann
4 license GPL V3
5 version 0.1.3
6 date 11.09.2011
7
8 This file is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This file is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License (http://www.gnu.org/licenses/) for more details.
17 ******************************************************************************/
18
19// Constants-------------------------------------------------------------------
20var earthRadius = 6371.221; //Km
21
22// Projections-----------------------------------------------------------------
23var projMerc = new OpenLayers.Projection("EPSG:900913");
24var proj4326 = new OpenLayers.Projection("EPSG:4326");
25
26// Zoom------------------------------------------------------------------------
27var zoomUnits= [
28    30*3600,    // zoom=0
29    30*3600,
30    15*3600,
31    10*3600,
32    5*3600,
33    5*3600,
34    2*3600,
35    1*3600,
36    30*60,
37    20*60,
38    10*60,      // zoom=10
39    5*60,
40    2*60,
41    1*60,
42    30,
43    30,
44    12,
45    6,
46    6,
47    3           // zoom=19
48];
49
50// Transformations-------------------------------------------------------------
51function Lon2Merc(value) {
52    return 20037508.34 * value / 180;
53}
54
55function Lat2Merc(value) {
56    var PI = 3.14159265358979323846;
57    lat = Math.log(Math.tan( (90 + value) * PI / 360)) / (PI / 180);
58    return 20037508.34 * value / 180;
59}
60
61function plusfacteur(a) {
62    return a * (20037508.34 / 180);
63}
64
65function moinsfacteur(a) {
66    return a / (20037508.34 / 180);
67}
68
69function y2lat(a) {
70    return 180/Math.PI * (2 * Math.atan(Math.exp(moinsfacteur(a)*Math.PI/180)) - Math.PI/2);
71}
72
73function lat2y(a) {
74    return plusfacteur(180/Math.PI * Math.log(Math.tan(Math.PI/4+a*(Math.PI/180)/2)));
75}
76
77function x2lon(a) {
78    return moinsfacteur(a);
79}
80
81function lon2x(a) {
82    return plusfacteur(a);
83}
84
85function km2nm(a) {
86    return a * 0.540;
87}
88
89function lat2DegreeMinute(buffLat) {
90    var ns = buffLat >= 0 ? 'N' : 'S';
91    var lat_m = Math.abs(buffLat*60).toFixed(3);
92    var lat_d = Math.floor (lat_m/60);
93    lat_m -= lat_d*60;
94
95    return ns + lat_d + "°" + format2FixedLenght(lat_m, 6, 3) + "'";
96}
97
98function lon2DegreeMinute(buffLon) {
99    var we = buffLon >= 0 ? 'E' : 'W';
100    var lon_m = Math.abs(buffLon*60).toFixed(3);
101    var lon_d = Math.floor (lon_m/60);
102    lon_m -= lon_d*60;
103
104    return we + lon_d + "°" + format2FixedLenght(lon_m, 6, 3) + "'";
105}
106
107function lonLatToMercator(ll) {
108    return new OpenLayers.LonLat(lon2x(ll.lon), lat2y(ll.lat));
109}
110
111// shorten coordinate to 5 digits in decimal fraction
112function shorter_coord(coord) {
113    return Math.round(coord*100000)/100000;
114}
115
116
117// Common utilities------------------------------------------------------------
118function jumpTo(lon, lat, zoom) {
119    var lonlat = new OpenLayers.LonLat(lon, lat);
120    lonlat.transform(proj4326, projMerc);
121    map.setCenter(lonlat, zoom);
122}
123
124function getTileURL(bounds) {
125    var res = this.map.getResolution();
126    var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
127    var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
128    var z = this.map.getZoom();
129    var limit = Math.pow(2, z);
130    if (y < 0 || y >= limit) {
131        return null;
132    } else {
133        x = ((x % limit) + limit) % limit;
134        url = this.url;
135        path= z + "/" + x + "/" + y + "." + this.type;
136        if (url instanceof Array) {
137            url = this.selectUrl(path, url);
138        }
139        return url+path;
140    }
141}
142
143function getTileURLAsParams(bounds) {
144    var res = this.map.getResolution();
145    var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
146    var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
147    var z = this.map.getZoom();
148
149    var limit = Math.pow(2, z);
150
151    if (y < 0 || y >= limit) {
152        return OpenLayers.Util.getImagesLocation() + "404.png";
153    } else {
154        x = ((x % limit) + limit) % limit;
155        return this.url + "x=" + x + "&y=" + y + "&z=" + z;
156    }
157}
158
159function addMarker(layer, buffLon, buffLat, popupContentHTML) {
160    var pos = new OpenLayers.LonLat(buffLon, buffLat);
161    pos.transform(proj4326, projMerc);
162    var mFeature = new OpenLayers.Feature(layer, pos);
163    mFeature.closeBox = true;
164    mFeature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {minSize: new OpenLayers.Size(260, 100) } );
165    mFeature.data.popupContentHTML = popupContentHTML;
166
167    var size = new OpenLayers.Size(32,32);
168    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
169    var icon = new OpenLayers.Icon('resources/icons/Needle_Red_32.png', size, offset);
170
171    var marker = new OpenLayers.Marker(pos, icon);
172    marker.feature = mFeature;
173
174    var markerClick = function(evt) {
175        if (this.popup == null) {
176            this.popup = this.createPopup(this.closeBox);
177            map.addPopup(this.popup);
178            this.popup.show();
179        } else {
180            this.popup.toggle();
181        }
182        OpenLayers.Event.stop(evt);
183    };
184
185
186    layer.addMarker(marker);
187    if (popupContentHTML != -1) {
188        marker.events.register("mousedown", mFeature, markerClick);
189        map.addPopup(mFeature.createPopup(mFeature.closeBox));
190    }
191}
192
193// Vector layer utilities------------------------------------------------------
194function getLineSegments(line) {
195    var numSegments = line.components.length - 1;
196    var segments = new Array(numSegments), point1, point2;
197    for(var i = 0; i < numSegments; ++i) {
198        point1 = line.components[i];
199        point2 = line.components[i + 1];
200        segments[i] = {
201            x1: point1.x,
202            y1: point1.y,
203            x2: point2.x,
204            y2: point2.y
205        };
206    }
207
208    return segments;
209}
210
211function getLineSegmentLength(segment) {
212    return Math.sqrt( Math.pow((segment.x2 -segment.x1),2) + Math.pow((segment.y2 -segment.y1),2) );
213}
214
215function getDistance(latA, latB, lonA, lonB) {
216    var dLat = OpenLayers.Util.rad(latB - latA);
217    var dLon = OpenLayers.Util.rad(lonB - lonA);
218    var lat1 = OpenLayers.Util.rad(latA);
219    var lat2 = OpenLayers.Util.rad(latB);
220
221    var a = Math.PI/2-lat2;
222    var b = Math.PI/2-lat1;
223    var c = Math.acos(Math.cos(a)*Math.cos(b)+Math.sin(a)*Math.sin(b)*Math.cos(dLon));
224    var d = km2nm(earthRadius * c);
225
226    return d;
227}
228
229function getBearing(latA, latB, lonA, lonB) {
230    var dLat = OpenLayers.Util.rad(latB-latA);
231    var dLon = OpenLayers.Util.rad(lonB-lonA);
232    var lat1 = OpenLayers.Util.rad(latA);
233    var lat2 = OpenLayers.Util.rad(latB);
234
235    var y = Math.sin(dLon) * Math.cos(lat2);
236    var x = Math.cos(lat1)*Math.sin(lat2) -
237        Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
238    var brng = OpenLayers.Util.deg(Math.atan2(y, x));
239
240    return (brng + 360) % 360;
241}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.