PageSourceSearch

https://www.terratech-ngo.de/wp-content/plugins/osm/js/osm-startup-lib.js?ver=6.8.3

js terratech-ngo.de collected 2026-10-02 17:28:07 UTC 11,095 bytes, 331 lines download raw bytes

1/*  Copyright (C) 2020  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 */
84		window[_map].addLayer(window.vectorM[_map][e]);
85
86		/** tracking stuff */
87		if (typeof _paq !== "undefined") {
88			if (!_startUp) { 
89				_paq.push(['trackEvent', translations['openlayer'], jQuery('#layerBox' + e + _map).data('layer_title')]);
90			} else {
91				_paq.push(['trackEvent', translations['openlayerAtStartup'], jQuery('#layerBox' + e + _map).data('layer_title')]);
92			}	
93		}
94	});
95}	
96		
97/** 
98 * for the link to map with choosen layers - collect which are active
99 * @param {string} _map - the #id of the map | data-map ^data-map_name
100 * @returns {string} of comma separated values of active layers of map
101 */
102function checkChoosedLayers(_map) {
103	layers = [];
104	
105	jQuery('.layerOf' + _map).each(function(){
106		if (jQuery(this).data('active') == true) {
107			layers.push( jQuery(this).data('layer'));
108		}
109	});
110	
111	layers.join(); 
112	
113	// because 0 is not NULL and 0 is not 0 and so on ...
114	if (layers != "") {
115
116		return layers;
117	} else {
118
119		return 'none';
120	}
121}
122
123/** 
124 * removes layer from map by click on #layerBox_n tag - also sets visibility features
125 * @param {object} chosen #layerBox
126 */		
127function switchLayerOff(_e) {
128	_e.data('active', false);
129	_e.children('i').removeClass('fa-eye'); 
130	_e.children('i').addClass('fa-eye-slash'); 
131	_e.children('span.layerColor').addClass('layerColorHidden'); 
132	
133	/** window and vectorM are both global */
134	window[_e.data('map')].removeLayer(window.vectorM[_e.data('map')][_e.data('layer')]);
135	
136	/** tracking stuff */
137	if (typeof _paq !== "undefined") {
138		_paq.push(['trackEvent', translations['closeLayer'], _e.text()]);
139	}	
140}	
141	
142/** 
143 * add layer on top of the map by click on #layerBox_n tag - also sets visibility features
144 * @param {object} chosen #layerBox
145 */		
146function switchLayerOn(_e) {
147	_e.data('active', true);
148	_e.children('i').removeClass('fa-eye-slash'); 
149	_e.children('i').addClass('fa-eye'); 
150	_e.children('span.layerColor').removeClass('layerColorHidden'); 
151	
152	
153	/** window and vectorM are both global */
154	window[_e.data('map')].addLayer(window.vectorM[_e.data('map')][_e.data('layer')]);
155	
156	/** tracking stuff */
157	if (typeof _paq !== "undefined") {
158		_paq.push(['trackEvent', translations['openlayer'], _e.text()]);
159	}	
160}
161
162/** after DOM has been rendered this jQuery will be executed */
163jQuery(document).ready(function() { 
164
165	/** 
166	 * event handler 
167	 * @fires prompt with link to page and map and choosen layers, center and zoom
168	 * link contains GET-Parameters in an array with map_name as an index  
169	 */	
170
171	jQuery('.generatedLink').click(function() {
172		if (jQuery(this).data('map_name') == '') {
173			jQuery(this).data('map_name', jQuery(this).data('map'));
174		}
175		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')));
176	});
177	
178	/** 
179	 * event handler 
180	 * @fires prompt with wordpress short code to map_name map and choosen layers, center, zoom and a example string for trigger
181	 */	
182	jQuery('a.generatedShortCode').click(function() {
183		
184		mapName =  jQuery(this).data('map_name');
185		mapCenter = window[jQuery(this).data('map')].getView().getCenter();
186		mapZoom = window[jQuery(this).data('map')].getView().getZoom();
187		mapLayer = checkChoosedLayers(jQuery(this).data('map')) ;
188		
189		string2show = '[osm_map_v3 setup_map_name="' + mapName + '" setup_center="' + mapCenter + '" setup_zoom="' + mapZoom + '" setup_layer="' + mapLayer + '" setup_trigger="' + translations['shortDescription'] + '"]';				
190	
191		window.prompt(translations['generatedShortCode'], string2show);
192	});
193
194	/** 
195	 * event handler 
196	 * @fires prompt with random name of map - it doesn't matter - it just have to be the same in active and passive short code
197	 */	 	
198	jQuery('a.cantGenerateShortCode').click(function() {
199	
200		var randomize = 'map_' + Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);
201		window.prompt(translations['cantGenerateLink'], 'setup_map_name="' + randomize + '"');
202	});
203		
204	/** 
205	 * event handler for text link to control map
206	 * set visibility an layers of map as well as zoom and center
207	 */			
208	jQuery('.setupChange').click(function() {
209	
210		/** 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 */
211		var controlledMap = jQuery('*[data-map_name="' + jQuery(this).data('map_name') + '"]').data('map');
212
213		/** reads from clicked anchor tag data attributes: zoom - get from global: map */
214		window[controlledMap].getView().setZoom(jQuery(this).data('zoom'));
215	
216		/** reads from clicked anchor tag data attributes: center - get from global: map */
217		mapCenter = jQuery(this).data('center').split(',');
218
219		/** this is the difference between OL 3.0 and 4.0 **/
220		mapCenter[0] = parseFloat(mapCenter[0]);
221		mapCenter[1] = parseFloat(mapCenter[1]);
222
223		window[controlledMap].getView().setCenter(mapCenter);
224	
225		/** layers	- via class addressed seams not to be the same as via id ... */
226		/** switch off every shown layer on specific map */
227		jQuery('.layerBoxes').each( function(i){
228			/** keep in mind: multiple maps per page */
229			if (jQuery('#layerBox' + i + controlledMap).length > 0) {
230				switchLayerOff(jQuery('#layerBox' + i + controlledMap));
231			}	
232		});
233		
234		/** switch on layer(s) in given order on specific map */
235		if (jQuery(this).data('layer') != 'none') {
236		                LayerStr = jQuery(this).data('layer');
237			activateLayers(controlledMap, LayerStr , 0) ;
238			
239		}	
240	});
241
242	/** 
243	 * event handler for text link to control map
244	 * decide which function to call by looking at active status of tag
245	 */
246	jQuery('.layerBoxes').click(function() {
247	
248		/** data-attribut active represents visibility */
249		if (jQuery(this).data('active') ==  true) {
250			/** hide (remove layer from map) */
251			switchLayerOff(jQuery(this));
252		
253		} else {
254			/** show (add layer on maps top level) */
255			switchLayerOn(jQuery(this));
256		}
257	});		
258		
259	/** 
260	 * code part for evaluate incoming control data
261	 */ 
262
263	/** decode GET-Parameters, remove leading '?' */
264	var strGET = decodeURIComponent(document.location.search.substr(1, document.location.search.length));
265
266	/** splits by '&' fill array HTTP_GET_VARS with key => val */
267	if (strGET != ''){
268
269		var pairings = strGET.split('&');
270
271		for (var i = 0; i < pairings.length; ++i) {
272			var value = '';
273			pairing = pairings[i].split('=');
274
275			if (pairing.length > 1){
276				value = pairing[1];
277			}
278	
279			HTTP_GET_VARS[unescape(pairing[0])] = unescape(value);
280		}
281	}	
282
283	/** if GET-Parameter set control for map - set values for map -- if mapCenter is set, script supposes everything is set in right order */
284	if (getGET('mapCenter[' + getGET('map') + ']') != 'undefined') {
285	
286		/** mapCenter is an array of 2 values longitude, latitude (different format as long, lat in the entire plugin) */
287		mapCenter = getGET('mapCenter[' + getGET('map') + ']').split(',');
288		mapCenter[0] = parseFloat(mapCenter[0]);
289		mapCenter[1] = parseFloat(mapCenter[1]);
290		
291		/** link between map_name and map id on page, because id is not map specific enough on different content positions */
292		controlledMap = jQuery('*[data-map_name="' + getGET('map') + '"]').data('map');
293		
294		/** setup_map_name not set, content position is hopefully the same (standard at single view) */
295		if (typeof controlledMap == "undefined") {
296			controlledMap = getGET('map');
297		}
298
299		/** set center of GET given map */
300		window[controlledMap].getView().setCenter(mapCenter);
301	}
302
303	/** set zoom of GET given map */
304	if (getGET('mapZoom[' + getGET('map') + ']') != 'undefined') {
305		window[controlledMap].getView().setZoom(getGET('mapZoom[' + getGET('map') + ']') );
306	}
307	
308			
309	/** set layers of GET given map */
310		
311	if (getGET('mapLayers[' + getGET('map') + ']') != 'undefined') {
312	
313		/** show no layers at all - intentionally */
314		if (getGET('mapLayers[' + getGET('map') + ']') != 'none') {
315
316                        	LayerStr = getGET('mapLayers[' + getGET('map') + ']');
317			activateLayers(controlledMap, LayerStr , 0);
318			
319		}
320	}  else {
321		
322		/** no map control is given via GET - make first layer visible - if there is any to choose from */
323		jQuery('.map').each(function() {
324			if (jQuery('.layerOf' + jQuery(this).data('map')).length > 0) {
325			        mapStr = jQuery(this).data('map');
326				activateLayers(mapStr, '0', 1);
327				
328			}
329		});	
330	}	
331});		

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.