PageSourceSearch

https://nightlinebielefeld.com/wp-content/plugins/ultimate-maps-by…/maps/js/engines/core.leaflet.js?ver=1.2.14

js nightlinebielefeld.com collected 2026-10-08 14:54:40 UTC 15,081 bytes, 443 lines download raw bytes

1function umsLeafletMap(elementId, mapData, engine) {
2	this._zoomControl = null;
3	this._mainLayer = null;
4	this._mapTypes = null;
5	this._providers = null;
6	this._scaleControl = null;
7	this._provider = false;
8	this._providerData = null;
9	umsLeafletMap.superclass.constructor.apply(this, arguments);
10}
11extendUms(umsLeafletMap, umsBaseMap);
12umsLeafletMap.prototype._beforeInit = function() {
13	this._mapParams.zoom = this._mapParams.zoom ? parseInt(this._mapParams.zoom) : 10;
14
15	if(typeof(this._mapParams.zoom_min) !== 'undefined') {
16		this._mapParams.minZoom = parseInt(this._mapParams.zoom_min);
17	}
18	if(typeof(this._mapParams.zoom_max) !== 'undefined') {
19		this._mapParams.maxZoom = parseInt(this._mapParams.zoom_max);
20	}
21	if(typeof(this._mapParams.mouse_wheel_zoom) !== 'undefined') {
22		this._mapParams.scrollWheelZoom = parseInt(this._mapParams.mouse_wheel_zoom);
23	}
24	if(typeof(this._mapParams.draggable) !== 'undefined') {
25		var isMobile = ( navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i) ) ? true : false;
26		switch (this._mapParams.draggable) {
27			case 'enable':
28				this._mapParams.dragging = 1;
29				break;
30			case 'disable':
31				this._mapParams.dragging = 0;
32				break;
33			case 'desktop':
34				if (!isMobile) {
35					this._mapParams.dragging = 1;
36				} else {
37					this._mapParams.dragging  = 0;
38				}
39				break;
40			case 'mobile':
41				if (isMobile) {
42					this._mapParams.dragging = 1;
43				} else {
44					this._mapParams.dragging = 0;
45				}
46				break;
47		}
48	}
49	if(typeof(this._mapParams.dbl_click_zoom) !== 'undefined') {
50		this._mapParams.doubleClickZoom = parseInt(this._mapParams.dbl_click_zoom);
51	}
52	// We will do this after map will be init - to have zoom control object in our class
53	this._mapParams.zoomControl = false;
54	umsLeafletMap.superclass._beforeInit.apply(this, arguments);
55};
56umsLeafletMap.prototype._createMapObj = function() {
57	var centerCoords = this._getCreateCoords()
58	,	params = jQuery.extend(this._mapParams, {
59			center: [centerCoords.coord_x, centerCoords.coord_y]
60		});
61	this._mapObj = L.map(this._clearElementId, params);
62	this._provider = this._getProviderEngine();
63	this._mainLayer = this._createMainLayer();
64};
65umsLeafletMap.prototype._createMainLayer = function(provider) {
66	var typeUrl = '';
67
68	this._providerData = this._getProviderData( this._provider );
69	if(this._providerData) {
70		typeUrl = this._providerData.url;
71	} else if(typeof(this._mapParams.map_type) !== 'undefined' && this._mapTypeExists(this._mapParams.map_type)) {
72		typeUrl = this._providerData && this._providerData.typeToUrl
73			? this._providerData.typeToUrl(this._mapParams.map_type)
74			: this._mapParams.map_type;
75	} else {
76		typeUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
77	}
78	var props = {
79		attribution: this._getAttributions(typeUrl)
80	};
81	if(this._providerData) {
82		if(this._providerData.props) {
83			props = jQuery.extend(props, this._providerData.props);
84		}
85		if(this._providerData.prepareProps) {
86			props = this._providerData.prepareProps(props);
87		}
88	}
89	return L.tileLayer(typeUrl, props).addTo(this._mapObj);
90};
91umsLeafletMap.prototype._getProviders = function() {
92	if(!this._providers) {
93		var self = this;
94		this._providers = {
95			'mapbox': {
96			   url:  'https://api.mapbox.com/styles/v1/mapbox/{id}/tiles/256/{z}/{x}/{y}?access_token={accessToken}'
97			,	props: {id: 'streets-v11', accessToken: UMS_DATA.mapboxKey}
98			/*,	types: [
99					'mapbox.streets', 'mapbox.outdoors',
100					'mapbox.light','mapbox.dark','mapbox.satellite',
101					'mapbox.satellite-streets','mapbox.navigation-preview-day',
102					'mapbox.navigation-preview-night','mapbox.navigation-guidance-day','mapbox.navigation-guidance-night',
103					'mapbox.terrain-rgb'
104				]*/
105			,	typeToUrl: function(type) {
106					return str_replace(this.url, '{id}', type);
107				}
108			,	prepareProps: function(props) {
109					if(typeof(self._mapParams.map_type) !== 'undefined' && self._mapTypeExists(self._mapParams.map_type)) {
110						props.id = self._mapParams.map_type;
111					}
112					return props;
113				}
114			}
115		,	'thunderforest': {
116				url: 'https://tile.thunderforest.com/{id}/{z}/{x}/{y}.png?apikey={apikey}'
117			,	props: {id: 'cycle', apikey: UMS_DATA.thunderforestKey}
118			//,	attr: '&copy; <a href="http://www.thunderforest.com/">Thunderforest</a>, &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
119			/*,	types: [
120					'cycle', 'transport', 'landscape', 'outdoors', 'transport-dark', 'spinal-map',
121					'pioneer', 'mobile-atlas', 'neighbourhood'
122				]*/
123			,	typeToUrl: function(type) {
124					return str_replace(this.url, '{id}', type);
125				}
126			,	prepareProps: function(props) {
127					if(typeof(self._mapParams.map_type) !== 'undefined' && self._mapTypeExists(self._mapParams.map_type)) {
128						props.id = self._mapParams.map_type;
129					}
130					return props;
131				}
132			}
133			,	'maptiles': {
134					url: 'https://maptiles.p.rapidapi.com/{id}/map/v1/{z}/{x}/{y}.png?rapidapi-key={apikey}'
135					// url: 'https://maptiles.p.rapidapi.com/{id}/map/v1/{z}/{x}/{y}.png?rapidapi-key={apikey}'
136				,	props: {id: 'en', apikey: UMS_DATA.rapidapiKey}
137				//,	attr: '&copy; <a href="http://www.thunderforest.com/">Thunderforest</a>, &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
138				/*,	types: [
139						'cycle', 'transport', 'landscape', 'outdoors', 'transport-dark', 'spinal-map',
140						'pioneer', 'mobile-atlas', 'neighbourhood'
141					]*/
142				,	typeToUrl: function(type) {
143						return str_replace(this.url, '{id}', type);
144					}
145				,	prepareProps: function(props) {
146						if(typeof(self._mapParams.map_type) !== 'undefined' && self._mapTypeExists(self._mapParams.map_type)) {
147							props.id = self._mapParams.map_type;
148						}
149						return props;
150					}
151				}
152		};
153	}
154	return this._providers;
155};
156umsLeafletMap.prototype._getProviderData = function(provider) {
157	this._getProviders();
158	return this._providers[ provider ] ? this._providers[ provider ] : false;
159};
160umsLeafletMap.prototype._getProviderEngine = function() {
161	if(this._fullEngine.indexOf('l-') === 0) {
162		// like "l-mapbox" for example
163		return this._fullEngine.split('-')[1];
164	}
165	return this._fullEngine;
166};
167umsLeafletMap.prototype._afterInit = function() {
168	if(typeof(this._mapParams.zoom_control) !== 'undefined'
169		&& this._mapParams.zoom_control !== 'none'
170	) {
171		this.enbZoom(true);
172	}
173	umsLeafletMap.superclass._afterInit.apply(this, arguments);
174};
175umsLeafletMap.prototype.addEventListener = function(event, clb) {
176	if(event === 'zoom_changed') {
177		event = 'zoomend';
178	}
179	this._mapObj.addEventListener(event, clb);
180};
181umsLeafletMap.prototype.enbZoom = function(mode) {
182	var self = this;
183	var removeCtrl = function(ctrl) {
184		switch(ctrl) {
185			case 'zoom':
186				if(self._zoomControl) {
187					self._zoomControl.remove();
188					self._zoomControl = null;
189				}
190				break;
191			case 'scale':
192				if(self._scaleControl) {
193					self._scaleControl.remove();
194					self._scaleControl = null;
195				}
196				break;
197		}
198	};
199	if(mode) {
200		var mode = typeof(this._mapParams.navigation_bar_mode) !== 'undefined'
201			? this._mapParams.navigation_bar_mode
202			: 'full';
203		if(toeInArrayUms(mode, ['full', 'zoom_only']) && !this._zoomControl) {
204			this._zoomControl = new L.control.zoom();
205			this._mapObj.addControl(this._zoomControl);
206			if(mode !== 'full') {
207				removeCtrl('scale');
208			}
209		}
210		if(toeInArrayUms(mode, ['full', 'scale_only']) && !this._scaleControl) {
211			this._scaleControl = new L.control.scale();
212			this._mapObj.addControl(this._scaleControl);
213			if(mode !== 'full') {
214				removeCtrl('zoom');
215			}
216		}
217	} else {
218		removeCtrl('zoom');
219		removeCtrl('scale');
220	}
221};
222umsLeafletMap.prototype.enbDraggable = function(mode) {
223	var isMobile = ( navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i) ) ? true : false;
224	switch (mode) {
225		case 'enable':
226			this._mapObj.dragging.enable();
227			break;
228		case 'disable':
229			this._mapObj.dragging.disable();
230			break;
231		case 'desktop':
232			if (!isMobile) {
233				this._mapObj.dragging.enable();
234			} else {
235				this._mapObj.dragging.disable();
236			}
237			break;
238		case 'mobile':
239			if (isMobile) {
240				this._mapObj.dragging.enable();
241			} else {
242				this._mapObj.dragging.disable();
243			}
244			break;
245	}
246};
247umsLeafletMap.prototype.setCenter = function (lat, lng) {
248	this._mapObj.panTo([lat, lng]);
249};
250umsLeafletMap.prototype.getCenter = function () {
251	var center = this._mapObj.getCenter();
252	return {lat: center.lat, lng: center.lng};
253};
254umsLeafletMap.prototype.setZoom = function (zoomLevel) {
255	this._mapObj.setZoom(zoomLevel);
256};
257umsLeafletMap.prototype.getZoom = function () {
258	return this._mapObj.getZoom();
259};
260umsLeafletMap.prototype.setNavigationBarMode = function(mode) {
261	if(typeof(this._mapParams.zoom_control) !== 'undefined'
262		&& this._mapParams.zoom_control !== 'none'
263	) {
264		this._mapParams.navigation_bar_mode = mode;
265		this.enbZoom(false);
266		this.enbZoom(true);
267	}
268};
269umsLeafletMap.prototype.enbWheelZoom = function(mode) {
270	mode
271		? this._mapObj.scrollWheelZoom.enable()
272		: this._mapObj.scrollWheelZoom.disable();
273};
274umsLeafletMap.prototype.getNavigationBarMode = function() {
275	this._methodRedefineNotice('umsLeafletMap.prototype.getNavigationBarMode');
276};
277umsLeafletMap.prototype.setMapType = function (mapType) {
278	if(this._providerData && this._providerData.typeToUrl) {
279		this._mainLayer.setUrl(this._providerData.typeToUrl(mapType));
280	} else {
281		this._mainLayer.setUrl(mapType);
282	}
283};
284umsLeafletMap.prototype.geocodeQuery = function(search, clb, errorClb) {
285	// Leaflet don't have it's own geocode. So use nominatim service. maybe we need to push it as a default fallback?
286	jQuery.ajax({
287		url: 'https://nominatim.openstreetmap.org/?q='+ search+ '&format=json'
288	,	dataType: 'text'
289	,	success: function(data) {
290			if(clb) {
291				if(data) {
292					var r = JSON.parse(data);
293					if(r) {
294						var formattedResult = [];
295						if(r && r.length > 0) {
296							for(var i = 0; i < r.length; i++) {
297								// All addresses in all geocoders should have same - our - format results
298								formattedResult.push({
299									formatted_address: r[ i ].display_name
300								,	lat: r[ i ].lat
301								,	lng: r[ i ].lon
302								});
303							}
304							clb(formattedResult);
305						}
306						return;
307					}
308				}
309				errorClb(data);
310				return;
311			} else
312				console.log('So, what should I do next, ha?');
313		}
314	});
315};
316umsLeafletMap.prototype._generateMarkerInfoWndStyle = function() {
317	var res = [];
318	// Width
319
320	res.push(this._elementId+ ' .marker-cluster {background-color: '+ this.getParam('marker_clasterer_border_color') + '; opacity:1;}');
321	res.push(this._elementId+ ' .marker-cluster {color: '+ this.getParam('marker_clasterer_text_color') + ';}');
322	res.push(this._elementId+ ' .marker-cluster div {background-color: '+ this.getParam('marker_clasterer_background_color') + '; opacity:1;}');
323
324
325	if(this.getParam('marker_infownd_width_units') === 'px') {
326		res.push(this._elementId+ ' .leaflet-popup-content {width: '+ this.getParam('marker_infownd_width')+ 'px;}');
327	}
328	// Height
329	if(this.getParam('marker_infownd_height_units') === 'px') {
330		res.push(this._elementId+ ' .leaflet-popup-content {height: '+ this.getParam('marker_infownd_height')+ 'px;}');
331	}
332	// Title style
333	res.push(this._elementId+ ' .leaflet-popup-content .umsMarkerTitle {color: '+ this.getParam('marker_title_color')
334			+ '; font-size: '+ this.getParam('marker_title_size')+ 'px}');
335	// Description
336	res.push(this._elementId+ ' .leaflet-popup-content .umsMarkerDesc, '+ this._elementId+ ' .leaflet-popup-content .umsMarkerDesc * {font-size: '+ this.getParam('marker_desc_size')+ 'px}');
337	// Background
338	res.push(this._elementId+ ' .leaflet-popup .leaflet-popup-content-wrapper, '+ this._elementId+ ' .leaflet-popup .leaflet-popup-tip {background-color: '+ this.getParam('marker_infownd_bg_color')+ ';}');
339	return res.join('');
340};
341umsLeafletMap.prototype._mapTypeExists = function(typeUrl) {
342	this._getMapTypes();
343	if(typeof(this._mapTypes[ typeUrl ]) !== 'undefined')
344		return true;
345	/*if(this._providerData && this._providerData.types && this._providerData.types.indexOf(typeUrl) !== -1)
346		return true;*/
347	return false;
348};
349umsLeafletMap.prototype._getMapTypes = function() {
350	if(!this._mapTypes) {
351		var attr = '';
352		this._mapTypes = {};
353		var typesVarName = 'umsLeaFletTypes__'+ (this._provider ? this._provider : this._fullEngine);
354		if(this._providerData) {
355			this._mapTypes[ this._providerData.url ] = {
356				// In first element there should be attr
357				'attr': window[ typesVarName ][ Object.keys(window[ typesVarName ])[0] ].attr
358			};
359		}
360		for(var typeName in window[ typesVarName ]) {
361			if(typeof(window[ typesVarName ][ typeName ]) === 'object') {
362				attr = window[ typesVarName ][ typeName ]['attr'];
363			}
364			this._mapTypes[ typeName ] = {
365				'attr': attr
366			};
367		}
368	}
369	return this._mapTypes;
370};
371umsLeafletMap.prototype._getAttributions = function(typeUrl) {
372	this._getMapTypes();
373	return this._mapTypes[ typeUrl ].attr;
374};
375umsLeafletMap.prototype.enableClasterization = function(clasterType, needTrigger) {
376	switch(clasterType) {
377		case 'MarkerClusterer':	// Support only this one for now
378			this._clearCluster();
379			this._createCluster();
380			this._addMarkersToCluster();
381			this._mapObj.addLayer(this._clasterer);
382			break;
383	}
384	this._clastererEnabled = true;
385};
386umsLeafletMap.prototype._addMarkersToCluster = function() {
387	if(this._markers.length > 0) {
388		for(var i = 0; i < this._markers.length; i++) {
389			this._clasterer.addLayer(this._markers[ i ].getRawMarkerInstance());
390			this._markers[i].removeFromMap();
391		}
392	}
393};
394umsLeafletMap.prototype.disableClasterization = function() {
395	this._clearCluster();
396	if(this._markers.length > 0) {
397		for(var i = 0; i < this._markers.length; i++) {
398			this._markers[i].addToMap();
399		}
400	}
401	this._clastererEnabled = false;
402};
403umsLeafletMap.prototype._clearCluster = function() {
404	if(this._clasterer) {
405		this._clasterer.remove();
406		this._clasterer = null;
407	}
408};
409umsLeafletMap.prototype._createCluster = function() {
410	if(!this._clasterer) {
411		var clasterGridSize = parseInt(this.getParam('marker_clasterer_grid_size'));
412		if(!clasterGridSize)
413			clasterGridSize = 60;
414		var opts = {
415			maxClusterRadius: clasterGridSize,
416		};
417		this._clasterer = new L.MarkerClusterGroup(opts);
418	}
419};
420umsLeafletMap.prototype._refreshCluster = function() {
421	this._clearCluster();
422	this._createCluster();
423	this._addMarkersToCluster();
424	this._mapObj.addLayer(this._clasterer);
425};
426umsLeafletMap.prototype.setClusterSize = function(size) {
427	this.setParam('marker_clasterer_grid_size', size);
428	this._refreshCluster();
429};
430umsLeafletMap.prototype._setMinZoomLevel = function() {
431	umsLeafletMap.superclass._setMinZoomLevel.apply(this, arguments);
432	var minZoom = parseInt(this._mapParams.zoom_min) ? parseInt(this._mapParams.zoom_min) : null;
433	this._mapObj.setMinZoom(minZoom);
434};
435umsLeafletMap.prototype._setMaxZoomLevel = function() {
436	umsLeafletMap.superclass._setMaxZoomLevel.apply(this, arguments);
437	var maxZoom = parseInt(this._mapParams.zoom_max) ? parseInt(this._mapParams.zoom_max) : null;
438	this._mapObj.setMaxZoom(maxZoom);
439};
440function umsLeafletMapsLoadComplete() {
441	g_umsMapLoadObserver.setLoaded('leaflet')
442}
443umsLeafletMapsLoadComplete();

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.