PageSourceSearch

https://mairievendes.fr/wp-content/plugins/ultimate-maps-by-supsys…/maps/js/engines/core.leaflet.js?ver=1.3.3

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

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.