PageSourceSearch

https://www.nationalpark-unteres-odertal.de/wp-content/plugins/osm/js/osm-v3-plugin-lib.js?ver=1.0.0

js nationalpark-unteres-odertal.de collected 2026-09-24 23:16:40 UTC 16,068 bytes, 508 lines download raw bytes

1/*  (c) Copyright 2022  MiKa (http://wp-osm-plugin.Hyumika.com)
2
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2 of the License, or
6    (at your option) any later version.
7
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16*/
17 
18function osm_addClusterPopupClickhandler(a_MapObj, a_MapStr) {
19
20  var container_div_id = a_MapStr + "_popup";
21  var content_div_id = a_MapStr + "_popup-content";
22  var closer_div_id = a_MapStr + "_popup-closer";
23
24  var container = document.getElementById(container_div_id);
25  var content = document.getElementById(content_div_id);
26  var closer = document.getElementById(closer_div_id);
27
28  var popup = new ol.Overlay(/** @type {olx.OverlayOptions} */ ({
29    element: container,
30    autoPan: true,
31    autoPanAnimation: {
32      duration: 250
33    }
34  }));
35        
36  closer.onclick = function() {
37    popup.setPosition(undefined);
38    closer.blur();
39    return false;
40  };
41            
42  a_MapObj.addOverlay(popup);
43
44  var ClickdisplayFeatureInfo = function(a_evt) {
45    var lonlat = ol.proj.transform(a_evt.coordinate, "EPSG:3857", "EPSG:4326");
46    var lon = lonlat[0];
47    var lat = lonlat[1];
48
49	 pixel = a_evt.pixel;
50		
51    var features = [];
52    var NumOfNamedFeatures = 0;
53    a_MapObj.forEachFeatureAtPixel(pixel, function(feature, layer) {
54      features.push(feature);
55    });
56    if (features.length > 0) {
57      
58      var name_str, desc_str, info = [];
59      var description_str = [];
60      var i, ii;
61      for (i = 0, ii = features.length; i < ii; ++i) {
62        var cluster_features = features[i].get('features');
63        if (cluster_features.length == 1){
64        if (cluster_features[i].get("name")){
65          NumOfNamedFeatures++;
66          name_str = cluster_features[i].get("name");
67          desc_str = cluster_features[i].get("desc");
68          description_str = features[i].get("description");
69          if (desc_str != undefined){
70            name_str = name_str + "<br>" + desc_str;
71          }
72          if (description_str != undefined){
73            name_str = name_str + "<br>" + description_str;
74          }
75          if (cluster_features[i].length > 0) {name_str = name_str + "<br>"}
76        }
77        else{
78
79        }
80        info.push(name_str);
81      }
82      }
83
84        content.innerHTML = info.join("") || "(unknown)";
85        if (NumOfNamedFeatures > 0){
86          popup.setPosition(a_evt.coordinate);
87        }
88         else {
89           popup.setPosition(undefined);
90        }
91      } 
92    };
93    a_MapObj.on("singleclick", function(evt) {ClickdisplayFeatureInfo(evt);}); 
94}
95
96
97
98function osm_addPopupClickhandler(a_MapObj, a_MapStr) {
99  var container_div_id = a_MapStr + "_popup";
100  var content_div_id = a_MapStr + "_popup-content";
101  var closer_div_id = a_MapStr + "_popup-closer";
102
103  var container = document.getElementById(container_div_id);
104  var content = document.getElementById(content_div_id);
105  var closer = document.getElementById(closer_div_id);
106
107  var popup = new ol.Overlay(/** @type {olx.OverlayOptions} */ ({
108    element: container,
109    autoPan: true,
110    autoPanAnimation: {
111      duration: 250
112    }
113  }));
114        
115  closer.onclick = function() {
116    popup.setPosition(undefined);
117    closer.blur();
118    return false;
119  };
120            
121  a_MapObj.addOverlay(popup);
122
123  var ClickdisplayFeatureInfo = function(a_evt) {
124    var lonlat = ol.proj.transform(a_evt.coordinate, "EPSG:3857", "EPSG:4326");
125    var lon = lonlat[0];
126    var lat = lonlat[1];
127
128	 pixel = a_evt.pixel;
129		
130    var features = [];
131    var NumOfNamedFeatures = 0;
132    a_MapObj.forEachFeatureAtPixel(pixel, function(feature, layer) {
133      features.push(feature);
134    });
135    if (features.length > 0) {
136      var name_str, desc_str, info = [];
137      var description_str = [];
138      var i, ii;
139      for (i = 0, ii = features.length; i < ii; ++i) {
140        if (features[i].get("name")){
141          NumOfNamedFeatures++;
142          name_str = features[i].get("name");
143          desc_str = features[i].get("desc");
144          description_str = features[i].get("description");
145          if (desc_str != undefined){
146            name_str = name_str + "<br>" + desc_str;
147          }
148          if (description_str != undefined){
149            name_str = name_str + "<br>" + description_str;
150          }
151          if (features.length > 0) {name_str = name_str + "<br>"}
152        }
153        else{
154          //name_str = "empty";
155        }
156        info.push(name_str);
157      }
158
159        content.innerHTML = info.join("") || "(unknown)";
160        if (NumOfNamedFeatures > 0){
161          popup.setPosition(a_evt.coordinate);
162        }
163         else {
164           popup.setPosition(undefined);
165        }
166      } 
167    };
168    a_MapObj.on("singleclick", function(evt) {ClickdisplayFeatureInfo(evt);}); 
169}
170
171
172
173
174function osm_addMarkerLayer(a_mapname, a_lon, a_lat, a_MarkerIcon, a_MarkerXAnchor, a_MarkerYAnchor, a_MarkerText) {
175  var iconFeature = new ol.Feature({
176    geometry: new ol.geom.Point(
177      ol.proj.transform([a_lon,a_lat], "EPSG:4326", "EPSG:3857")),
178    name: a_MarkerText
179  });
180  var iconStyle = new ol.style.Style({
181    image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
182      anchor: [(a_MarkerXAnchor * -1),(a_MarkerYAnchor * -1)],
183      anchorXUnits: "pixels",
184      anchorYUnits: "pixels",
185      opacity: 0.9,
186      src: a_MarkerIcon
187    }))
188  });
189  iconFeature.setStyle(iconStyle);
190
191  var vectorMarkerSource = new ol.source.Vector({
192    features: [iconFeature]
193  });
194
195  var vectorMarkerLayer = new ol.layer.Vector({
196    source: vectorMarkerSource,
197    zIndex: 92
198  });
199
200  a_mapname.addLayer(vectorMarkerLayer);
201}
202
203function osm_addMouseHover(a_mapname){
204  a_mapname.on('pointermove', function(evt) {
205    a_mapname.getTargetElement().style.cursor =
206      a_mapname.hasFeatureAtPixel(evt.pixel) ? 'pointer' : '';
207  });
208}
209
210function getTileLayer(a_source, a_api_key) {
211
212/* ++++++++ quickfix since stamen is now hosted by Stadia Maps */
213  if ((a_source == "stamen_toner") || (a_source == "stamen_watercolor") || (a_source == "stamen_terrain")||(a_source == "stamen_terrain-labels")){
214    a_source = "osm";
215  } 
216/*  ------- */
217
218  if ((a_source == "osm") || (a_source == "brezhoneg")||(a_source == "openseamap")){
219   return new ol.layer.Tile({
220        source: new ol.source.OSM({ }),
221        zIndex: 90
222      });
223  }
224  else if (a_source == "hot"){
225      return new ol.layer.Tile({
226            source: new ol.source.OSM({
227               attributions: "Maps &copy; " +
228               "<a href=\"http://hot.openstreetmap.org/\">Humanitarian OpenStreetMap Team.</a>" + ol.source.OSM.ATTRIBUTION,
229               url: "https://{a-c}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png"
230             }),
231             zIndex: 90
232           });
233    }	
234	 else if (a_source == "opentopomap"){
235      return new ol.layer.Tile({
236            source: new ol.source.XYZ({
237               attributions: "Kartendarstellung: &copy;" + "<a href=\"https://opentopomap.org\">OpenTopoMap</a> (<a href=\"https://creativecommons.org/licenses/by-sa/3.0/\">CC-BY-SA</a>)" + "Maps &copy; " +
238               "<a href=\"http://viewfinderpanoramas.org\">SRTM</a>" + ol.source.OSM.ATTRIBUTION,
239               url: "https://{a-c}.tile.opentopomap.org/{z}/{x}/{y}.png"
240             }),
241             zIndex: 90
242           });
243    }
244    else if (a_source == "stamen_toner"){
245      return new ol.layer.Tile({
246        source: new ol.source.Stamen({
247            layer: "toner"
248          }),
249          zIndex: 90
250        });
251     }
252	  else if (a_source == "stamen_watercolor"){
253      return new ol.layer.Tile({
254        source: new ol.source.Stamen({
255            layer: "watercolor"
256          }),
257          zIndex: 90
258        });
259      }
260      else if (a_source == "stamen_terrain"){
261      return new ol.layer.Tile({
262        source: new ol.source.Stamen({
263            layer: "terrain"
264          }),
265          zIndex: 90
266        });
267      }
268      else if (a_source == "stamen_terrain-labels"){
269        return new ol.layer.Tile({
270          source: new ol.source.Stamen({
271          	layer: "terrain-labels"}),
272          zIndex: 90
273        });
274      }  
275	  else if (a_source == "cyclemap"){
276       return new ol.layer.Tile({
277            source: new ol.source.OSM({
278              attributions: "Maps &copy; " +
279              "<a href=\"http://www.thunderforest.com/\">Thunderforest, Data.</a>" + ol.source.OSM.ATTRIBUTION,
280              url:   "https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png?apikey="+ a_api_key                           
281             }),
282             zIndex: 90
283           });
284     }
285     else if (a_source == "outdoor"){
286          return new ol.layer.Tile({
287            source: new ol.source.OSM({
288              attributions: "Maps &copy; " +
289              "<a href=\"http://www.thunderforest.com/\">Thunderforest, Data.</a>" + ol.source.OSM.ATTRIBUTION,
290              url: "https://{a-c}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png?apikey="+ a_api_key
291             }),
292             zIndex: 90
293           });
294      }
295
296    else if (a_source == "landscape"){
297      return new ol.layer.Tile({
298        source: new ol.source.OSM({
299        attributions: "Maps &copy; " +
300              "<a href=\"http://www.thunderforest.com/\">Thunderforest, Data.</a>" + ol.source.OSM.ATTRIBUTION,
301              url: "https://{a-c}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png?apikey="+ a_api_key
302             }),
303             zIndex: 90
304           });
305    }
306
307    else if (a_source == "spinal"){
308          return new ol.layer.Tile({
309            source: new ol.source.OSM({
310              attributions: "Maps &copy; " +
311              "<a href=\"http://www.thunderforest.com/\">Thunderforest, Data.</a>" + ol.source.OSM.ATTRIBUTION,
312              url: "https://{a-c}.tile.thunderforest.com/spinal-map/{z}/{x}/{y}.png?apikey="+ a_api_key
313             }),
314             zIndex: 90
315           });
316    }
317     else if (a_source == "pioneer"){
318          return new ol.layer.Tile({
319            source: new ol.source.OSM({
320               attributions: "Maps &copy; " +
321               "<a href=\"http://www.thunderforest.com/\">Thunderforest, Data.</a>" + ol.source.OSM.ATTRIBUTION,
322               url: "https://{a-c}.tile.thunderforest.com/pioneer/{z}/{x}/{y}.png?apikey="+ a_api_key
323             }),
324             zIndex: 90
325           });
326          
327    }
328
329    else if (a_source == "basemap_at"){
330
331      var template = "{Layer}/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png";
332      var urls_basemap = [
333        "https://maps1.wien.gv.at/basemap/" + template,
334        "https://maps2.wien.gv.at/basemap/" + template,
335        "https://maps3.wien.gv.at/basemap/" + template,
336        "https://maps4.wien.gv.at/basemap/" + template,
337        "https://maps.wien.gv.at/basemap/" + template
338      ];
339
340      // HiDPI support:
341      // * Use "bmaphidpi" layer (pixel ratio 2) for device pixel ratio > 1
342      // * Use "geolandbasemap" layer (pixel ratio 1) for device pixel ratio == 1
343      var hiDPI = ol.has.DEVICE_PIXEL_RATIO > 1;
344
345      var source_basemap = new ol.source.WMTS({
346        projection: "EPSG:3857",
347        //layer: hiDPI ? "bmaphidpi" : "geolandbasemap",
348        layer: "geolandbasemap",
349        tilePixelRatio: hiDPI ? 2 : 1,
350        style: "normal",
351        matrixSet: "google3857",
352        urls: urls_basemap,
353        requestEncoding: "REST",
354        tileGrid: new ol.tilegrid.WMTS({
355          origin: [-20037508.3428, 20037508.3428],
356            resolutions: [
357            559082264.029 * 0.28E-3,
358            279541132.015 * 0.28E-3,
359            139770566.007 * 0.28E-3,
360            69885283.0036 * 0.28E-3,
361            34942641.5018 * 0.28E-3,
362            17471320.7509 * 0.28E-3,
363            8735660.37545 * 0.28E-3,
364            4367830.18773 * 0.28E-3,
365            2183915.09386 * 0.28E-3,
366            1091957.54693 * 0.28E-3,
367            545978.773466 * 0.28E-3,
368            272989.386733 * 0.28E-3,
369            136494.693366 * 0.28E-3,
370            68247.3466832 * 0.28E-3,
371            34123.6733416 * 0.28E-3,
372            17061.8366708 * 0.28E-3,
373            8530.91833540 * 0.28E-3,
374            4265.45916770 * 0.28E-3,
375            2132.72958385 * 0.28E-3,
376            1066.36479193 * 0.28E-3
377            ],
378            matrixIds: [
379              0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
380            ]
381       }),
382
383       attributions: "Tiles &copy; " +
384       "<a href=\"http://www.basemap.at/\">basemap.at</a>" + ol.source.OSM.ATTRIBUTION,
385   });
386
387
388    return new ol.layer.Tile({
389				 extent: [977844.377599999, 5837774.6617, 1915609.8654, 6295560.8122],
390				 source: source_basemap
391			   })
392
393      }
394
395      else {// unknwon => OSM map
396        return new ol.layer.Tile({
397          source: new ol.source.OSM()
398        });
399     }      
400}
401
402function getVectorClusterLayer(a_vectorMarkerSource, a_taggedborderColor, a_taggedinnerColor, a_IconURL, a_IconOffsetwidth, a_IconOffsetheight) {
403			
404  var clusterSource = new ol.source.Cluster({
405    distance: 30,
406    source: a_vectorMarkerSource,
407    zIndex: 92
408  });
409  
410  var styleCache = {};
411  var vectorMarkerLayer = new ol.layer.Vector({
412    source: clusterSource,
413	 zIndex: 92,
414	 style: function(feature, resolution) {
415	   var size = feature.get("features").length;
416		 var features = feature.get("features");
417
418       if (size > 1){
419	      var style = styleCache[size];
420		   if (!style) {
421		     style = [new ol.style.Style({
422			    image: new ol.style.Circle({
423				   radius: 12,
424				   stroke: new ol.style.Stroke({
425					  color: a_taggedborderColor,
426					  width: 6,
427				   }),
428				   fill: new ol.style.Fill({
429					  color: a_taggedinnerColor
430				   })
431				 }),
432				 text: new ol.style.Text({
433				   text: size.toString(),
434				   fill: new ol.style.Fill({
435					  color: "#fff"
436				   })
437				 })
438			  })];
439			  styleCache[size] = style;
440			}
441			return style;
442			}
443			else {
444			  var style = styleCache[size];
445			  if (!style) {
446			  style = [new ol.style.Style({
447				image: new ol.style.Icon(({
448					anchor: [(a_IconOffsetwidth*-1),(a_IconOffsetheight*-1)],
449					anchorXUnits: "pixels",
450					anchorYUnits: "pixels",
451					opacity: 0.9,
452					src: a_IconURL}))
453			  })];
454			  styleCache[size] = style;
455			}
456			return style;
457			}
458		  }
459		});
460		return vectorMarkerLayer;
461				
462}
463
464function addControls2Map(a_map, MousePosition, OverviewMap, Rotate,Scaleline,Zoom,ZoomSlider,ZoomToExtent,FullScreen, Attribution) {
465  
466  var osm_controls = [
467		new ol.control.Attribution(),
468		new ol.control.MousePosition({
469		  undefinedHTML: "outside",
470			projection: "EPSG:4326",
471			coordinateFormat: function(coordinate) {
472			  return ol.coordinate.format(coordinate, "{y}, {x}", 5);
473			}
474		}),
475		new ol.control.OverviewMap({
476        layers: [
477          new ol.layer.Tile({
478            source: new ol.source.OSM(),
479          }),
480        ],
481        collapsed: false,
482		 }),
483		new ol.control.Rotate({
484		  autoHide: false
485		}),
486		new ol.control.ScaleLine(),
487		new ol.control.Zoom(),
488		new ol.control.ZoomSlider(),
489		new ol.control.ZoomToExtent({
490        extent: [-11243808.051695308, 1.202710291, 9561377.290892059, 6852382.107835932]
491      }),
492		new ol.control.FullScreen()
493	]; 	
494	
495	if (Scaleline == 1){a_map.addControl(osm_controls[4]);}
496   if (MousePosition == 1){a_map.addControl(osm_controls[1]);}
497   if (OverviewMap == 1){a_map.addControl(osm_controls[2]);}
498	if (FullScreen == 1){a_map.addControl(osm_controls[8]);}	 
499	if (Attribution == 0){
500     a_map.getControls().forEach(function(control) {
501       if (control instanceof ol.control.Attribution) {
502         a_map.removeControl(control);
503       }
504     }, this);	
505   }	
506	  
507}
508

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.