PageSourceSearch

https://beleefvenetie.nl/wp-content/plugins/osm/js/osm-startup-lib.js?ver=V6.2.6

js beleefvenetie.nl collected 2026-10-02 14:25:28 UTC 12,721 bytes, 377 lines download raw bytes

1/*  Copyright (C) 2026  Matthias Greiling (https://westrad.de)
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 3 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, see <http://www.gnu.org/licenses/>.
15
16*/
17
18	
19/** 
20 * get method for stored GET-Parameters
21 * @param {string} _attribut - key of array
22 * @returns {string} val of array at given index or 'undefined'
23 */
24function getGET(_attribut) {
25	if(!HTTP_GET_VARS[_attribut]){
26		return 'undefined';
27	}
28
29	return HTTP_GET_VARS[_attribut];
30}
31
32/** fix IE - add methode "includes" to string */
33if (!String.prototype.includes) {
34	String.prototype.includes = function(search, start) {
35		if (typeof start !== 'number') {
36			start = 0;
37		}
38
39		if (start + search.length > this.length) {
40			return false;
41		} else {
42			return this.indexOf(search, start) !== -1;
43		}	
44	};
45}
46
47/** 
48 * put layer on top of map 
49 * @param {string} _map - the #id of the map | data-map ^data-map_name
50 * @param {string} _layers - comma separated values
51 */
52function activateLayers(_map, _layers, _startUp) {
53
54	/** _layers comma separated values? layers is an array - even with one layer */
55	layers = [];
56	comma = ',';
57	
58	
59	if (typeof _layers.includes === "function" && !_startUp) {
60		if (_layers.includes(comma)) {
61			layers = _layers.split(',');
62		}	
63	} else {
64		layers[0] = _layers;
65	}	
66	
67	// via GET given param at startup - just layer 0
68	if (_layers == 0) {
69		layers[0] = _layers;
70	}
71
72	
73	/** every layer stored in array switch its layerBox 'visible' and added global layer to global map */
74	jQuery(layers).each(function(i,e){
75	
76		/** visibility and fancy looking */
77		jQuery('#layerBox' + e + _map).children('i').removeClass('fa-eye-slash'); 
78		jQuery('#layerBox' + e + _map).children('i').addClass('fa-eye'); 
79	    jQuery('#layerBox' + e + _map).children('span.layerColor').removeClass('layerColorHidden'); 
80		jQuery('#layerBox' + e + _map).css({'background-color':'rgb(250,255,255)' });
81		jQuery('#layerBox' + e + _map).data('active', true);
82		
83		/** real action - OL 10.x throws on duplicates, so guard first */
84		if (window[_map].getLayers().getArray().indexOf(window.vectorM[_map][e]) === -1) {
85			window[_map].addLayer(window.vectorM[_map][e]);
86		}
87
88		/** tracking stuff */
89		if (typeof _paq !== "undefined") {
90			if (!_startUp) { 
91				_paq.push(['trackEvent', translations['openlayer'], jQuery('#layerBox' + e + _map).data('layer_title')]);
92			} else {
93				_paq.push(['trackEvent', translations['openlayerAtStartup'], jQuery('#layerBox' + e + _map).data('layer_title')]);
94			}	
95		}
96	});
97}	
98		
99/** 
100 * for the link to map with choosen layers - collect which are active
101 * @param {string} _map - the #id of the map | data-map ^data-map_name
102 * @returns {string} of comma separated values of active layers of map
103 */
104function checkChoosedLayers(_map) {
105	layers = [];
106	
107	jQuery('.layerOf' + _map).each(function(){
108		if (jQuery(this).data('active') == true) {
109			layers.push( jQuery(this).data('layer'));
110		}
111	});
112	
113	layers.join(); 
114	
115	// because 0 is not NULL and 0 is not 0 and so on ...
116	if (layers != "") {
117
118		return layers;
119	} else {
120
121		return 'none';
122	}
123}
124
125/** 
126 * removes layer from map by click on #layerBox_n tag - also sets visibility features
127 * @param {object} chosen #layerBox
128 */		
129function switchLayerOff(_e) {
130	_e.data('active', false);
131	_e.children('i').removeClass('fa-eye'); 
132	_e.children('i').addClass('fa-eye-slash'); 
133	_e.children('span.layerColor').addClass('layerColorHidden'); 
134	
135	/** window and vectorM are both global */
136	window[_e.data('map')].removeLayer(window.vectorM[_e.data('map')][_e.data('layer')]);
137	
138	/** tracking stuff */
139	if (typeof _paq !== "undefined") {
140		_paq.push(['trackEvent', translations['closeLayer'], _e.text()]);
141	}	
142}	
143	
144/** 
145 * add layer on top of the map by click on #layerBox_n tag - also sets visibility features
146 * @param {object} chosen #layerBox
147 */		
148function switchLayerOn(_e) {
149	_e.data('active', true);
150	_e.children('i').removeClass('fa-eye-slash'); 
151	_e.children('i').addClass('fa-eye'); 
152	_e.children('span.layerColor').removeClass('layerColorHidden'); 
153	
154	
155	/** window and vectorM are both global - OL 10.x throws on duplicates, so guard first */
156	var _mapName = _e.data('map');
157	var _layer = window.vectorM[_mapName][_e.data('layer')];
158	if (window[_mapName].getLayers().getArray().indexOf(_layer) === -1) {
159		window[_mapName].addLayer(_layer);
160	}
161	
162	/** tracking stuff */
163	if (typeof _paq !== "undefined") {
164		_paq.push(['trackEvent', translations['openlayer'], _e.text()]);
165	}	
166}
167
168/** after DOM has been rendered this jQuery will be executed */
169jQuery(document).ready(function() { 
170
171	/** 
172	 * event handler 
173	 * @fires prompt with link to page and map and choosen layers, center and zoom
174	 * link contains GET-Parameters in an array with map_name as an index  
175	 */	
176
177	jQuery('.generatedLink').click(function() {
178		if (jQuery(this).data('map_name') == '') {
179			jQuery(this).data('map_name', jQuery(this).data('map'));
180		}
181		window.prompt(translations['generateLink'], location.protocol + '//' + location.host + location.pathname + '?map=' + jQuery(this).data('map_name') + '&mapCenter[' + jQuery(this).data('map_name') + ']=' + window[jQuery(this).data('map')].getView().getCenter() + '&mapZoom[' + jQuery(this).data('map_name') + ']=' + window[jQuery(this).data('map')].getView().getZoom() + '&mapLayers[' + jQuery(this).data('map_name') + ']=' + checkChoosedLayers(jQuery(this).data('map')));
182	});
183	
184	/** 
185	 * event handler 
186	 * @fires prompt with wordpress short code to map_name map and choosen layers, center, zoom and a example string for trigger
187	 */	
188	jQuery('a.generatedShortCode').click(function() {
189		
190		mapName =  jQuery(this).data('map_name');
191		mapCenter = window[jQuery(this).data('map')].getView().getCenter();
192		mapZoom = window[jQuery(this).data('map')].getView().getZoom();
193		mapLayer = checkChoosedLayers(jQuery(this).data('map')) ;
194		
195		string2show = '[osm_map_v3 setup_map_name="' + mapName + '" setup_center="' + mapCenter + '" setup_zoom="' + mapZoom + '" setup_layer="' + mapLayer + '" setup_trigger="' + translations['shortDescription'] + '"]';				
196	
197		window.prompt(translations['generatedShortCode'], string2show);
198	});
199
200	/** 
201	 * event handler 
202	 * @fires prompt with random name of map - it doesn't matter - it just have to be the same in active and passive short code
203	 */	 	
204	jQuery('a.cantGenerateShortCode').click(function() {
205	
206		var randomize = 'map_' + Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
207		window.prompt(translations['cantGenerateLink'], 'setup_map_name="' + randomize + '"');
208	});
209		
210	/** 
211	 * event handler for text link to control map
212	 * set visibility an layers of map as well as zoom and center
213	 */			
214	jQuery('.setupChange').click(function() {
215	
216		/** the name of the map have to be unique to be controlled via text link - but have to be translated to the real id in the document */
217		var controlledMap = jQuery('*[data-map_name="' + jQuery(this).data('map_name') + '"]').data('map');
218
219		/** reads from clicked anchor tag data attributes: zoom - get from global: map */
220		window[controlledMap].getView().setZoom(jQuery(this).data('zoom'));
221	
222		/** reads from clicked anchor tag data attributes: center - get from global: map */
223		mapCenter = jQuery(this).data('center').split(',');
224
225		/** this is the difference between OL 3.0 and 4.0 **/
226		mapCenter[0] = parseFloat(mapCenter[0]);
227		mapCenter[1] = parseFloat(mapCenter[1]);
228
229		window[controlledMap].getView().setCenter(mapCenter);
230	
231		/** layers	- via class addressed seams not to be the same as via id ... */
232		/** switch off every shown layer on specific map */
233		jQuery('.layerBoxes').each( function(i){
234			/** keep in mind: multiple maps per page */
235			if (jQuery('#layerBox' + i + controlledMap).length > 0) {
236				switchLayerOff(jQuery('#layerBox' + i + controlledMap));
237			}	
238		});
239		
240		/** switch on layer(s) in given order on specific map */
241		if (jQuery(this).data('layer') != 'none') {
242		                LayerStr = jQuery(this).data('layer');
243			activateLayers(controlledMap, LayerStr , 0) ;
244			
245		}	
246	});
247
248	/**
249	 * event handler for 'show all' button
250	 */
251	jQuery(document).on('click', '.layerBoxesAll', function() {
252		var _map = jQuery(this).attr('data-map');
253		var layerIndices = jQuery(this).attr('data-layer-indices').toString().split(',');
254		// check if all layers are currently active
255		var allActive = true;
256		jQuery.each(layerIndices, function(i, idx) {
257			var e = parseInt(idx, 10);
258			if (jQuery('#layerBox' + e + _map).data('active') !== true) {
259				allActive = false;
260				return false; // break
261			}
262		});
263		// toggle: hide all if all active, show all otherwise
264		jQuery.each(layerIndices, function(i, idx) {
265			var e = parseInt(idx, 10);
266			var layerBox = jQuery('#layerBox' + e + _map);
267			if (layerBox.length > 0) {
268				if (allActive) {
269					switchLayerOff(layerBox);
270				} else if (layerBox.data('active') !== true) {
271					switchLayerOn(layerBox);
272				}
273			}
274		});
275		// update icon on the "Show all" button
276		if (allActive) {
277			jQuery(this).children('i').removeClass('fa-eye').addClass('fa-eye-slash');
278		} else {
279			jQuery(this).children('i').removeClass('fa-eye-slash').addClass('fa-eye');
280		}
281	});
282
283	/** 
284	 * event handler for text link to control map
285	 * decide which function to call by looking at active status of tag
286	 */
287	jQuery('.layerBoxes').click(function() {
288	
289		/** data-attribut active represents visibility */
290		if (jQuery(this).data('active') ==  true) {
291			/** hide (remove layer from map) */
292			switchLayerOff(jQuery(this));
293		
294		} else {
295			/** show (add layer on maps top level) */
296			switchLayerOn(jQuery(this));
297		}
298	});		
299		
300	/** 
301	 * code part for evaluate incoming control data
302	 */ 
303
304	/** decode GET-Parameters, remove leading '?' */
305	var strGET = decodeURIComponent(document.location.search.substr(1, document.location.search.length));
306
307	/** splits by '&' fill array HTTP_GET_VARS with key => val */
308	if (strGET != ''){
309
310		var pairings = strGET.split('&');
311
312		for (var i = 0; i < pairings.length; ++i) {
313			var value = '';
314			pairing = pairings[i].split('=');
315
316			if (pairing.length > 1){
317				value = pairing[1];
318			}
319	
320			HTTP_GET_VARS[unescape(pairing[0])] = unescape(value);
321		}
322	}	
323
324	/** if GET-Parameter set control for map - set values for map -- if mapCenter is set, script supposes everything is set in right order */
325	if (getGET('mapCenter[' + getGET('map') + ']') != 'undefined') {
326	
327		/** mapCenter is an array of 2 values longitude, latitude (different format as long, lat in the entire plugin) */
328		mapCenter = getGET('mapCenter[' + getGET('map') + ']').split(',');
329		mapCenter[0] = parseFloat(mapCenter[0]);
330		mapCenter[1] = parseFloat(mapCenter[1]);
331		
332		/** link between map_name and map id on page, because id is not map specific enough on different content positions */
333		controlledMap = jQuery('*[data-map_name="' + getGET('map') + '"]').data('map');
334		
335		/** setup_map_name not set, content position is hopefully the same (standard at single view) */
336		if (typeof controlledMap == "undefined") {
337			controlledMap = getGET('map');
338		}
339
340		/** set center of GET given map */
341		window[controlledMap].getView().setCenter(mapCenter);
342	}
343
344	/** set zoom of GET given map */
345	if (getGET('mapZoom[' + getGET('map') + ']') != 'undefined') {
346		window[controlledMap].getView().setZoom(getGET('mapZoom[' + getGET('map') + ']') );
347	}
348	
349			
350	/** set layers of GET given map */
351		
352	if (getGET('mapLayers[' + getGET('map') + ']') != 'undefined') {
353	
354		/** show no layers at all - intentionally */
355		if (getGET('mapLayers[' + getGET('map') + ']') != 'none') {
356
357                        	LayerStr = getGET('mapLayers[' + getGET('map') + ']');
358			activateLayers(controlledMap, LayerStr , 0);
359			
360		}
361	}  else {
362		
363		/** no map control is given via GET - make first layer visible - if there is any to choose from */
364		jQuery('.osm-map-container').each(function() {
365			if (jQuery('.layerOf' + jQuery(this).data('map')).length > 0) {
366			        mapStr = jQuery(this).data('map');
367			        if (jQuery(this).attr('data-autoshow') === 'all') {
368		        	jQuery('.layerOf' + mapStr).each(function() {
369		        		switchLayerOn(jQuery(this));
370		        	});
371			        } else {
372					activateLayers(mapStr, '0', 1);
373				}
374			}
375		});	
376	}	
377});		

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.