PageSourceSearch

https://www.crcc-hdf.fr/wp-content/plugins/ultimate-maps-by-supsys…/maps/js/engines/core.leaflet.js?ver=1.2.4

js crcc-hdf.fr collected 2026-10-06 22:47:33 UTC 14,601 bytes, 424 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		};
134	}
135	return this._providers;
136};
137umsLeafletMap.prototype._getProviderData = function(provider) {
138	this._getProviders();
139	return this._providers[ provider ] ? this._providers[ provider ] : false;
140};
141umsLeafletMap.prototype._getProviderEngine = function() {
142	if(this._fullEngine.indexOf('l-') === 0) {
143		// like "l-mapbox" for example
144		return this._fullEngine.split('-')[1];
145	}
146	return this._fullEngine;
147};
148umsLeafletMap.prototype._afterInit = function() {
149	if(typeof(this._mapParams.zoom_control) !== 'undefined'
150		&& this._mapParams.zoom_control !== 'none'
151	) {
152		this.enbZoom(true);
153	}
154	umsLeafletMap.superclass._afterInit.apply(this, arguments);
155};
156umsLeafletMap.prototype.addEventListener = function(event, clb) {
157	if(event === 'zoom_changed') {
158		event = 'zoomend';
159	}
160	this._mapObj.addEventListener(event, clb);
161};
162umsLeafletMap.prototype.enbZoom = function(mode) {
163	var self = this;
164	var removeCtrl = function(ctrl) {
165		switch(ctrl) {
166			case 'zoom':
167				if(self._zoomControl) {
168					self._zoomControl.remove();
169					self._zoomControl = null;
170				}
171				break;
172			case 'scale':
173				if(self._scaleControl) {
174					self._scaleControl.remove();
175					self._scaleControl = null;
176				}
177				break;
178		}
179	};
180	if(mode) {
181		var mode = typeof(this._mapParams.navigation_bar_mode) !== 'undefined'
182			? this._mapParams.navigation_bar_mode
183			: 'full';
184		if(toeInArrayUms(mode, ['full', 'zoom_only']) && !this._zoomControl) {
185			this._zoomControl = new L.control.zoom();
186			this._mapObj.addControl(this._zoomControl);
187			if(mode !== 'full') {
188				removeCtrl('scale');
189			}
190		}
191		if(toeInArrayUms(mode, ['full', 'scale_only']) && !this._scaleControl) {
192			this._scaleControl = new L.control.scale();
193			this._mapObj.addControl(this._scaleControl);
194			if(mode !== 'full') {
195				removeCtrl('zoom');
196			}
197		}
198	} else {
199		removeCtrl('zoom');
200		removeCtrl('scale');
201	}
202};
203umsLeafletMap.prototype.enbDraggable = function(mode) {
204	var isMobile = ( navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i) ) ? true : false;
205	switch (mode) {
206		case 'enable':
207			this._mapObj.dragging.enable();
208			break;
209		case 'disable':
210			this._mapObj.dragging.disable();
211			break;
212		case 'desktop':
213			if (!isMobile) {
214				this._mapObj.dragging.enable();
215			} else {
216				this._mapObj.dragging.disable();
217			}
218			break;
219		case 'mobile':
220			if (isMobile) {
221				this._mapObj.dragging.enable();
222			} else {
223				this._mapObj.dragging.disable();
224			}
225			break;
226	}
227};
228umsLeafletMap.prototype.setCenter = function (lat, lng) {
229	this._mapObj.panTo([lat, lng]);
230};
231umsLeafletMap.prototype.getCenter = function () {
232	var center = this._mapObj.getCenter();
233	return {lat: center.lat, lng: center.lng};
234};
235umsLeafletMap.prototype.setZoom = function (zoomLevel) {
236	this._mapObj.setZoom(zoomLevel);
237};
238umsLeafletMap.prototype.getZoom = function () {
239	return this._mapObj.getZoom();
240};
241umsLeafletMap.prototype.setNavigationBarMode = function(mode) {
242	if(typeof(this._mapParams.zoom_control) !== 'undefined'
243		&& this._mapParams.zoom_control !== 'none'
244	) {
245		this._mapParams.navigation_bar_mode = mode;
246		this.enbZoom(false);
247		this.enbZoom(true);
248	}
249};
250umsLeafletMap.prototype.enbWheelZoom = function(mode) {
251	mode
252		? this._mapObj.scrollWheelZoom.enable()
253		: this._mapObj.scrollWheelZoom.disable();
254};
255umsLeafletMap.prototype.getNavigationBarMode = function() {
256	this._methodRedefineNotice('umsLeafletMap.prototype.getNavigationBarMode');
257};
258umsLeafletMap.prototype.setMapType = function (mapType) {
259	if(this._providerData && this._providerData.typeToUrl) {
260		this._mainLayer.setUrl(this._providerData.typeToUrl(mapType));
261	} else {
262		this._mainLayer.setUrl(mapType);
263	}
264};
265umsLeafletMap.prototype.geocodeQuery = function(search, clb, errorClb) {
266	// Leaflet don't have it's own geocode. So use nominatim service. maybe we need to push it as a default fallback?
267	jQuery.ajax({
268		url: 'https://nominatim.openstreetmap.org/?q='+ search+ '&format=json'
269	,	dataType: 'text'
270	,	success: function(data) {
271			if(clb) {
272				if(data) {
273					var r = JSON.parse(data);
274					if(r) {
275						var formattedResult = [];
276						if(r && r.length > 0) {
277							for(var i = 0; i < r.length; i++) {
278								// All addresses in all geocoders should have same - our - format results
279								formattedResult.push({
280									formatted_address: r[ i ].display_name
281								,	lat: r[ i ].lat
282								,	lng: r[ i ].lon
283								});
284							}
285							clb(formattedResult);
286						}
287						return;
288					}
289				}
290				errorClb(data);
291				return;
292			} else
293				console.log('So, what should I do next, ha?');
294		}
295	});
296};
297umsLeafletMap.prototype._generateMarkerInfoWndStyle = function() {
298	var res = [];
299	// Width
300
301	res.push(this._elementId+ ' .marker-cluster {background-color: '+ this.getParam('marker_clasterer_border_color') + '; opacity:1;}');
302	res.push(this._elementId+ ' .marker-cluster {color: '+ this.getParam('marker_clasterer_text_color') + ';}');
303	res.push(this._elementId+ ' .marker-cluster div {background-color: '+ this.getParam('marker_clasterer_background_color') + '; opacity:1;}');
304
305
306	if(this.getParam('marker_infownd_width_units') === 'px') {
307		res.push(this._elementId+ ' .leaflet-popup-content {width: '+ this.getParam('marker_infownd_width')+ 'px;}');
308	}
309	// Height
310	if(this.getParam('marker_infownd_height_units') === 'px') {
311		res.push(this._elementId+ ' .leaflet-popup-content {height: '+ this.getParam('marker_infownd_height')+ 'px;}');
312	}
313	// Title style
314	res.push(this._elementId+ ' .leaflet-popup-content .umsMarkerTitle {color: '+ this.getParam('marker_title_color')
315			+ '; font-size: '+ this.getParam('marker_title_size')+ 'px}');
316	// Description
317	res.push(this._elementId+ ' .leaflet-popup-content .umsMarkerDesc, '+ this._elementId+ ' .leaflet-popup-content .umsMarkerDesc * {font-size: '+ this.getParam('marker_desc_size')+ 'px}');
318	// Background
319	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')+ ';}');
320	return res.join('');
321};
322umsLeafletMap.prototype._mapTypeExists = function(typeUrl) {
323	this._getMapTypes();
324	if(typeof(this._mapTypes[ typeUrl ]) !== 'undefined')
325		return true;
326	/*if(this._providerData && this._providerData.types && this._providerData.types.indexOf(typeUrl) !== -1)
327		return true;*/
328	return false;
329};
330umsLeafletMap.prototype._getMapTypes = function() {
331	if(!this._mapTypes) {
332		var attr = '';
333		this._mapTypes = {};
334		var typesVarName = 'umsLeaFletTypes__'+ (this._provider ? this._provider : this._fullEngine);
335		if(this._providerData) {
336			this._mapTypes[ this._providerData.url ] = {
337				// In first element there should be attr
338				'attr': window[ typesVarName ][ Object.keys(window[ typesVarName ])[0] ].attr
339			};
340		}
341		for(var typeName in window[ typesVarName ]) {
342			if(typeof(window[ typesVarName ][ typeName ]) === 'object') {
343				attr = window[ typesVarName ][ typeName ]['attr'];
344			}
345			this._mapTypes[ typeName ] = {
346				'attr': attr
347			};
348		}
349	}
350	return this._mapTypes;
351};
352umsLeafletMap.prototype._getAttributions = function(typeUrl) {
353	this._getMapTypes();
354	return this._mapTypes[ typeUrl ].attr;
355};
356umsLeafletMap.prototype.enableClasterization = function(clasterType, needTrigger) {
357	switch(clasterType) {
358		case 'MarkerClusterer':	// Support only this one for now
359			this._clearCluster();
360			this._createCluster();
361			this._addMarkersToCluster();
362			this._mapObj.addLayer(this._clasterer);
363			break;
364	}
365	this._clastererEnabled = true;
366};
367umsLeafletMap.prototype._addMarkersToCluster = function() {
368	if(this._markers.length > 0) {
369		for(var i = 0; i < this._markers.length; i++) {
370			this._clasterer.addLayer(this._markers[ i ].getRawMarkerInstance());
371			this._markers[i].removeFromMap();
372		}
373	}
374};
375umsLeafletMap.prototype.disableClasterization = function() {
376	this._clearCluster();
377	if(this._markers.length > 0) {
378		for(var i = 0; i < this._markers.length; i++) {
379			this._markers[i].addToMap();
380		}
381	}
382	this._clastererEnabled = false;
383};
384umsLeafletMap.prototype._clearCluster = function() {
385	if(this._clasterer) {
386		this._clasterer.remove();
387		this._clasterer = null;
388	}
389};
390umsLeafletMap.prototype._createCluster = function() {
391	if(!this._clasterer) {
392		var clasterGridSize = parseInt(this.getParam('marker_clasterer_grid_size'));
393		if(!clasterGridSize)
394			clasterGridSize = 60;
395		var opts = {
396			maxClusterRadius: clasterGridSize,
397		};
398		this._clasterer = new L.MarkerClusterGroup(opts);
399	}
400};
401umsLeafletMap.prototype._refreshCluster = function() {
402	this._clearCluster();
403	this._createCluster();
404	this._addMarkersToCluster();
405	this._mapObj.addLayer(this._clasterer);
406};
407umsLeafletMap.prototype.setClusterSize = function(size) {
408	this.setParam('marker_clasterer_grid_size', size);
409	this._refreshCluster();
410};
411umsLeafletMap.prototype._setMinZoomLevel = function() {
412	umsLeafletMap.superclass._setMinZoomLevel.apply(this, arguments);
413	var minZoom = parseInt(this._mapParams.zoom_min) ? parseInt(this._mapParams.zoom_min) : null;
414	this._mapObj.setMinZoom(minZoom);
415};
416umsLeafletMap.prototype._setMaxZoomLevel = function() {
417	umsLeafletMap.superclass._setMaxZoomLevel.apply(this, arguments);
418	var maxZoom = parseInt(this._mapParams.zoom_max) ? parseInt(this._mapParams.zoom_max) : null;
419	this._mapObj.setMaxZoom(maxZoom);
420};
421function umsLeafletMapsLoadComplete() {
422	g_umsMapLoadObserver.setLoaded('leaflet')
423}
424umsLeafletMapsLoadComplete();

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.