PageSourceSearch

https://lhopitallegrand.fr/typo3conf/ext/e_magineurs/themes/Resour…/JavaScript/eMapsLeaflet.js?1790261671

js lhopitallegrand.fr collected 2026-09-25 08:20:36 UTC 17,251 bytes, 647 lines download raw bytes

1function eMapsLoadMap(eMaps) {
2	if ($("#eMapsMap__" + eMaps["settings"].map.mapUniqId).length === 0) {
3		return;
4	}
5
6	if (typeof eMaps["settings"].map.zoom.min === "undefined") {
7		eMaps["settings"].map.zoom.min = "0";
8	}
9
10	if (typeof eMaps["settings"].map.zoom.max === "undefined") {
11		eMaps["settings"].map.zoom.max = "0";
12	}
13
14	let openStreetMapLayer = L.tileLayer(
15		"https://{s}.tile.osm.org/{z}/{x}/{y}.png",
16		{
17			attribution:
18				'&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
19		}
20	);
21
22	let openTopoMapLayer = L.tileLayer(
23		"https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png",
24		{
25			attribution:
26				'&copy; <a href="https://opentopomap.org">OpenTopoMap</a> contributors',
27		}
28	);
29	let arcgisSatLayer = L.tileLayer(
30		"https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
31		{
32			attribution:
33				'&copy; <a href="https://www.arcgis.com/">Arcgis</a> contributors',
34			maxNativeZoom: 18,
35			maxZoom: 20,
36		}
37	);
38	// Define the base maps object
39	let baseMaps = {
40		Plan: openStreetMapLayer,
41		Relief: openTopoMapLayer,
42		Satellite: arcgisSatLayer,
43	};
44
45	let defaultLayerKey = "Plan";
46
47	const defaultLayer = baseMaps[defaultLayerKey];
48
49	// Initialize the map with the base layers
50	eMaps["map"] = L.map("eMapsMap__" + eMaps["settings"].map.mapUniqId, {
51		minZoom: parseInt(eMaps["settings"].map.zoom.min),
52		maxZoom:
53			eMaps["settings"].map.zoom.max != "0"
54				? parseInt(eMaps["settings"].map.zoom.max)
55				: 18,
56		scrollWheelZoom: eMaps["settings"].map.zoom.molette != "0",
57		draggable: eMaps["settings"].map.draggable != "0",
58		layers: [defaultLayer],
59	}).setView(
60		[
61			parseFloat(eMaps["settings"].map.center.lat),
62			parseFloat(eMaps["settings"].map.center.lng),
63		],
64		parseInt(eMaps["settings"].map.zoom.value)
65	);
66
67	// Add the layer control to the map
68	L.control
69		.layers(baseMaps, null, { position: "topright" })
70		.addTo(eMaps["map"]);
71
72	// Layer are being cut in half in bigger maps. Due to no padding in canvas renderer.
73
74	const renderer = L.canvas({ padding: 100 });
75	eMaps["map"].getRenderer(renderer).options.padding = 100;
76
77	if (
78		eMaps["settings"].map.recherche.actif == "1" ||
79		eMaps["settings"].map.itineraire.actif == "1"
80	) {
81		eMaps["geocoder"] = new L.Control.Geocoder.Nominatim();
82	}
83
84	if (eMaps["settings"].map.recherche.actif == "1") {
85		$("#eMapsRecherche__" + eMaps["settings"].map.mapUniqId).submit(function (
86			e
87		) {
88			e.preventDefault();
89			eMapsSearch(eMaps);
90		});
91	}
92
93	if (typeof eMaps["settings"].poi !== "undefined") {
94		if (eMaps["settings"].poi.liste == "1") {
95			$(".eMapsLoadInfosPoi__" + eMaps["settings"].map.mapUniqId).click(
96				function (e) {
97					e.preventDefault();
98					$(".title-pois").removeClass("active");
99					$(".title-pois").parents(".collapse").removeClass("show");
100					$(".title-pois").parents(".collapse").prev().addClass("collapsed");
101					$(".title-pois")
102						.parents(".collapse")
103						.prev()
104						.attr("aria-expanded", "false");
105					var matches = $(this)
106						.attr("id")
107						.match(/^1_([A-Za-z0-9_]+)_([0-9]+)/);
108					if (matches !== null) {
109						eMapsLoadInfosPoi(
110							eMaps,
111							eMaps["uidToKey"][matches[1] + "_" + matches[2]],
112							"0",
113							matches[1]
114						);
115						$(this).addClass("active");
116						$(this).parents(".collapse").addClass("show");
117						$(this).parents(".collapse").prev().removeClass("collapsed");
118						$(this).parents(".collapse").prev().attr("aria-expanded", "true");
119					}
120				}
121			);
122		}
123	}
124
125	if (eMaps["settings"].map.itineraire.actif == "1") {
126		eMapsItineraire(eMaps);
127	}
128
129	eMapsLoadPois(eMaps, 0);
130	if (eMaps["kmls"] && eMaps["kmls"].kml && typeof eMapsLoadKmls === "function") {
131		eMapsLoadKmls(eMaps);
132	}
133
134	if (eMaps["settings"].map.cluster.actif == "1") {
135		eMaps["mc"] = L.markerClusterGroup();
136		eMaps["marker"].forEach(function (element) {
137			eMaps["mc"].addLayer(element);
138		});
139		eMaps["map"].addLayer(eMaps["mc"]);
140	}
141
142	if (typeof eMaps["settings"].cat !== "undefined") {
143		if (eMaps["settings"].cat.liste == "1") {
144			eMapsCatInit(eMaps);
145		}
146	}
147
148	if (typeof eMaps["settings"].poi !== "undefined") {
149		if (eMaps["settings"].poi.liste == "1") {
150			// eMapsPoiListeInit(eMaps);
151		}
152	}
153}
154
155
156
157
158
159
160
161
162
163
164
165function eMapsLoadPois(eMaps, backend) {
166	if (eMaps["pois"] && eMaps["pois"].poi) {
167		eMaps["bounds"] = new L.LatLngBounds();
168
169		if (eMaps["pois"].poi.length == undefined) {
170			eMaps["pois"].poi = [eMaps["pois"].poi];
171		}
172
173		for (i = 0; i < eMaps["pois"].poi.length; i++) {
174			eMapsLoadPoi(eMaps, eMaps["pois"].poi[i], backend);
175		}
176
177		if (eMaps["settings"].map.center.type == "auto" && eMaps["bounds"]) {
178			if (eMaps["settings"].map.zoom.value > 0) {
179				eMaps["map"].flyTo(eMaps["bounds"].getCenter());
180			} else {
181				eMaps["map"].fitBounds(eMaps["bounds"]);
182			}
183		}
184
185		if (eMaps["settings"].map.forcePoi) {
186			if (
187				eMapsLoadInfosPoi(
188					eMaps,
189					eMaps["uidToKey"][eMaps["settings"].map.forcePoi],
190					backend,
191					""
192				)
193			) {
194				eMaps["map"].setView(
195					eMaps["marker"][
196						eMaps["uidToKey"][eMaps["settings"].map.forcePoi]
197					].getLatLng()
198				);
199			}
200		}
201	}
202}
203
204function eMapsLoadPoi(eMaps, poi, backend) {
205	key = eMaps["marker"].length;
206
207	if (
208		(typeof poi.lat != "string" && typeof poi.lat != "number") ||
209		(typeof poi.lng != "string" && typeof poi.lng != "number")
210	) {
211		return;
212	}
213
214	if (parseFloat(poi.lat) == NaN || parseFloat(poi.lng) == NaN) {
215		return;
216	}
217
218	position = [poi.lat, poi.lng];
219	eMaps["marker"][key] = new L.Marker(position, { title: poi.title });
220	eMaps["marker"][key].key = key;
221	eMaps["marker"][key].infopoi = poi;
222	if (poi.cats) {
223		eMaps["marker"][key].cats = poi.cats.split(",");
224	} else {
225		eMaps["marker"][key].cats = [];
226	}
227
228	eMaps["uidToKey"][poi.table + "_" + poi.uid] = key;
229
230	if (poi.picto && poi.picto != "") {
231		eMaps["marker"][key].setIcon(new L.Icon({ iconUrl: "/" + poi.picto }));
232	}
233
234	eMaps["marker"][key].addTo(eMaps["map"]);
235
236	eMaps["marker"][key].on("click", function () {
237		eMapsLoadInfosPoi(eMaps, this.key, backend, poi.table);
238	});
239
240	eMaps["bounds"].extend(L.latLng(poi.lat, poi.lng));
241}
242
243function eMapsLoadInfosPoi(eMaps, key, backend, table) {
244	if (!eMaps["marker"][key]) return false;
245
246	if (eMaps["marker"][key].popup) {
247		eMaps["map"].closePopup(eMaps["marker"][key].popup);
248		eMaps["marker"][key].popup = false;
249	} else {
250		eMaps["marker"][key].popup = new L.Popup({}).setLatLng(
251			eMaps["marker"][key].getLatLng()
252		);
253		eMaps["marker"][key].popup.setContent(eMaps["settings"].map.loadingInfo);
254		eMaps["marker"][key].popup.key = key;
255		eMaps["marker"][key].popup.on("popupclose", function () {
256			eMaps["marker"][this.key].popup = false;
257		});
258
259		$.ajax({
260			type: "POST",
261			dataType: "xml",
262			url: "?type=1280988",
263			data: {
264				id: eMaps["settings"].map.id,
265				uidPoi: eMaps["marker"][key].infopoi.uid,
266				typePoi: eMaps["marker"][key].infopoi.type,
267				key: key,
268			},
269			success: function (result) {
270				/*key =  $(result).find("key").text();*/
271				tabs = $(result).find("tab");
272				if (tabs.length > 0) {
273					$(result)
274						.find("tab")
275						.each(function () {
276							label = $(this).find("label").text();
277							content = $(this).find("content").text();
278							eMaps["marker"][key].popup.addTab(label, content);
279						});
280				} else {
281					content = $(result).find("content").text();
282					eMaps["marker"][key].popup.setContent(content);
283				}
284				eMaps["marker"][key].popup.openOn(eMaps["map"]);
285
286				window.setTimeout(function () {
287					eMaps["map"].flyTo(eMaps["marker"][key].getLatLng());
288
289					$(".eMapsYAllerLink").click(function (e) {
290						e.preventDefault();
291						eMapsYAller(
292							eMaps,
293							$(this).attr("data-pos-latitude"),
294							$(this).attr("data-pos-longitude"),
295							$(this).attr("data-pos-address")
296						);
297					});
298				}, 1000);
299			},
300			error: function (error) {
301				console.dir(error);
302				eMaps["map"].closePopup(eMaps["marker"][key].popup);
303				eMaps["marker"][key].popup = false;
304			},
305		});
306
307		if (typeof eMaps["settings"].poi !== "undefined") {
308			if (eMaps["settings"].poi.liste == "1") {
309				var poiDetailKey = key;
310				var poiDetailTable = table;
311				$(".title-pois").each(function () {
312					$(this).removeClass("active");
313					$(this).parents(".collapse").removeClass("show");
314					$(this).parents(".collapse").prev().addClass("collapsed");
315					$(this).parents(".collapse").prev().attr("aria-expanded", "false");
316					var matches = $(this)
317						.attr("id")
318						.match(/^1_([A-Za-z0-9_]+)_([0-9]+)/);
319					var poiButtonKey = eMaps["uidToKey"][matches[1] + "_" + matches[2]];
320					var poiButtonTable = matches[1];
321					if (
322						poiDetailKey == poiButtonKey &&
323						poiDetailTable == poiButtonTable
324					) {
325						$(this).addClass("active");
326						$(this).parents(".collapse").addClass("show");
327						$(this).parents(".collapse").prev().removeClass("collapsed");
328						$(this).parents(".collapse").prev().attr("aria-expanded", "true");
329					}
330				});
331			}
332		}
333	}
334	return true;
335}
336
337function eMapsSearch(eMaps) {
338	if (eMaps["settings"].map.itineraire.actif == "1") {
339		eMapsItineraireReset(eMaps);
340	}
341
342	var address = $("#eMapsAdress__" + eMaps["settings"].map.mapUniqId).val();
343	eMaps["geocoder"].geocode(address, function (results) {
344		eMaps["boundResult"] = results[0].bbox;
345		eMaps["map"].fitBounds(eMaps["boundResult"]);
346
347		if (eMaps["boundResultMarker"]) {
348			eMaps["boundResultMarker"].setLatLng(results[0].center);
349		} else {
350			eMaps["boundResultMarker"] = L.marker(results[0].center).addTo(
351				eMaps["map"]
352			);
353		}
354	});
355}
356
357function eMapsSearchReset(eMaps) {
358	$("#eMapsAdress__" + eMaps["settings"].map.mapUniqId).val("");
359	if (eMaps["boundResultMarker"]) {
360		eMaps["boundResultMarker"].setMap(null);
361		eMaps["boundResultMarker"] = null;
362	}
363}
364
365function eMapsItineraire(eMaps) {
366	eMaps["directionsService"] = new L.Routing.OSRMv1({ language: "fr" });
367	eMaps["routeDisplay"] = null;
368	eMaps["waypointDisplay"] = new L.Routing.Plan().addTo(eMaps["map"]);
369
370	$("#eMapsItineraire__" + eMaps["settings"].map.mapUniqId).submit(function (
371		e
372	) {
373		e.preventDefault();
374
375		address1 = $("#eMapsAdress1__" + eMaps["settings"].map.mapUniqId).val();
376		address2 = $("#eMapsAdress2__" + eMaps["settings"].map.mapUniqId).val();
377
378		eMaps["geocoder"].geocode(address1, function (results) {
379			startPosition = new L.Routing.Waypoint();
380			startPosition.latLng = results[0].center;
381			startPosition.name = address1;
382
383			eMaps["geocoder"].geocode(address2, function (results) {
384				endPosition = new L.Routing.Waypoint();
385				endPosition.latLng = results[0].center;
386				endPosition.name = address2;
387
388				eMaps["directionsService"].route(
389					[startPosition, endPosition],
390					function (errors, results) {
391						if (
392							typeof results !== "undefined" &&
393							typeof results[0] !== "undefined"
394						) {
395							eMaps["waypointDisplay"].setWaypoints(results[0].waypoints);
396							if (eMaps["routeDisplay"] !== null) {
397								eMaps["map"].removeLayer(eMaps["routeDisplay"]);
398							}
399							eMaps["routeDisplay"] = new L.Routing.Line(results[0]).addTo(
400								eMaps["map"]
401							);
402							eMaps["map"].flyToBounds(eMaps["routeDisplay"].getBounds());
403
404							//Build instruction list
405							itinerairePanel = $(
406								"#eMapsItinerairePanel__" + eMaps["settings"].map.mapUniqId
407							);
408
409							if (itinerairePanel.length > 0) {
410								li = $("<ul/>");
411								results[0].instructions.forEach(function (element) {
412									$("<li/>").text(element.text).appendTo(li);
413								});
414
415								itinerairePanel.find("ul").remove();
416								li.appendTo(itinerairePanel);
417							}
418						}
419					}
420				);
421			});
422		});
423	});
424}
425
426function eMapsItineraireReset(eMaps) {
427	$("#eMapsAdress1__" + eMaps["settings"].map.mapUniqId).val("");
428	$("#eMapsAdress2__" + eMaps["settings"].map.mapUniqId).val("");
429	if (eMaps["settings"].map.itineraire.show == "1") {
430		$(
431			"#eMapsType__" +
432			eMaps["settings"].map.mapUniqId +
433			' option[value="' +
434			eMaps["settings"].map.itineraire.type +
435			'"]'
436		).prop("selected", true);
437	}
438
439	if (eMaps["directionsDisplay"]) {
440		eMaps["directionsDisplay"].setDirections({ routes: [] });
441	}
442}
443
444function eMapsYAller(eMaps, lat, lng, adresse) {
445	if (eMaps["directionsService"]) {
446		endPosition = new L.Routing.Waypoint();
447		endPosition.latLng = new L.LatLng(lat, lng);
448		endPosition.name = adresse;
449
450		if (navigator.geolocation) {
451			navigator.geolocation.getCurrentPosition(function (position) {
452				if (eMaps["settings"].map.recherche.actif == "1") {
453					eMapsSearchReset(eMaps);
454				}
455
456				var type = eMaps["settings"].map.itineraire.type.toLowerCase();
457				if (eMaps["settings"].map.itineraire.show == "1") {
458					type = $("#eMapsType__" + eMaps["settings"].map.mapUniqId)
459						.val()
460						.toLowerCase();
461				}
462
463				startPosition = new L.Routing.Waypoint();
464				startPosition.latLng = new L.LatLng(
465					position.coords.latitude,
466					position.coords.longitude
467				);
468
469				eMaps["directionsService"].route(
470					[startPosition, endPosition],
471					function (errors, results) {
472						if (
473							typeof results !== "undefined" &&
474							typeof results[0] !== "undefined"
475						) {
476							eMaps["waypointDisplay"].setWaypoints(results[0].waypoints);
477							if (eMaps["routeDisplay"] !== null) {
478								eMaps["map"].removeLayer(eMaps["routeDisplay"]);
479							}
480							eMaps["routeDisplay"] = new L.Routing.Line(results[0]).addTo(
481								eMaps["map"]
482							);
483							eMaps["map"].flyToBounds(eMaps["routeDisplay"].getBounds());
484
485							//Build instruction list
486							itinerairePanel = $(
487								"#eMapsItinerairePanel__" + eMaps["settings"].map.mapUniqId
488							);
489
490							if (itinerairePanel.length > 0) {
491								li = $("<ul/>");
492								results[0].instructions.forEach(function (element) {
493									$("<li/>").text(element.text).appendTo(li);
494								});
495
496								itinerairePanel.find("ul").remove();
497								li.appendTo(itinerairePanel);
498							}
499						}
500					}
501				);
502			});
503		}
504	}
505
506	destField = $("#eMapsAdress2__" + eMaps["settings"].map.mapUniqId);
507	if (destField.length) {
508		destField.val(adresse);
509	}
510	return false;
511}
512
513function eMapsCatInit(eMaps) {
514	$("input.eMaps_cat").click(function () {
515		eMapsCatCheck(eMaps, this);
516	});
517
518	if (eMaps["settings"].cat.check != "1") {
519		$(".eMaps_cat_racine").click();
520	}
521
522	eMapsCatCheckAllInit(eMaps);
523}
524
525function eMapsCatCheck(eMaps, elem) {
526	var infos = $(elem).attr("id").split("_");
527	var idCat = infos[1];
528	elem = infos[2];
529	var input = $("#eMapscat_" + idCat + "_input");
530	var checked = input.prop("checked");
531
532	if (elem != "input") {
533		input.prop("checked", !checked);
534	} else {
535		checked = !checked;
536	}
537
538	for (var i = 0; i < eMaps["marker"].length; i++) {
539		var poi = eMaps["marker"][i];
540		if (poi.cats.indexOf(idCat) >= 0) {
541			if (checked && eMapsIsNoLastCat(poi)) {
542				eMapsHidePoi(eMaps, poi);
543			} else {
544				eMapsShowPoi(eMaps, poi);
545			}
546		}
547	}
548
549	var childs = $(".eMaps_child_" + idCat);
550	if (childs.length) {
551		childs.each(function () {
552			var childInput = $(this).prev("input.eMaps_cat");
553			if (childInput.length && childInput.prop("checked") !== !checked) {
554				childInput.prop("checked", !checked);
555				eMapsCatCheck(eMaps, childInput[0]);
556			}
557		});
558	}
559}
560
561function eMapsIsNoLastCat(poi) {
562	for (var i = 0; i < poi.cats.length; i++) {
563		var idCat = poi.cats[i];
564		if ($("#eMapscat_" + idCat + "_input").prop("checked")) {
565			return false;
566		}
567	}
568	return true;
569}
570
571function eMapsHidePoi(eMaps, poi) {
572	poi.removeFrom(eMaps["map"]);
573	if (poi.popup) {
574		eMaps["map"].closePopup(poi.popup);
575		poi.popup = false;
576	}
577
578	if (eMaps["settings"].poi.liste == "1") {
579		var table = poi.infopoi.table;
580		var uid = poi.infopoi.uid;
581		var poiElem = $("#emaps_" + table + "_" + uid);
582		poiElem.hide();
583
584		if (eMaps["settings"].map.cluster.actif == "1") {
585			eMaps["mc"].removeLayer(poi);
586		}
587	}
588}
589
590function eMapsShowPoi(eMaps, poi) {
591	poi.addTo(eMaps["map"]);
592	if (eMaps["settings"].poi.liste == "1") {
593		var table = poi.infopoi.table;
594		var uid = poi.infopoi.uid;
595		var poiElem = $("#emaps_" + table + "_" + uid);
596		poiElem.show();
597
598		if (eMaps["settings"].map.cluster.actif == "1") {
599			eMaps["mc"].addLayer(poi);
600		}
601	}
602}
603
604function eMapsCatCheckAllInit(eMaps) {
605	var checkAll = eMaps["labels"]["check"];
606	var uncheckAll = eMaps["labels"]["uncheck"];
607	$("#eMapsCheckAll__" + eMaps["settings"].map.mapUniqId).click(function () {
608		var thisButton = $(this);
609		if (thisButton.hasClass("allchecked")) {
610			$(this).parent().find("input:checkbox").each(function () {
611				if ($(this).prop("checked") == true) {
612					$(this).prop("checked", false);
613					eMapsCatCheck(eMaps, this);
614				}
615			});
616			thisButton
617				.text(checkAll)
618				.removeClass("allchecked")
619				.addClass("allunchecked");
620		} else {
621			$(this).parent().find("input:checkbox").each(function () {
622				if ($(this).prop("checked") == false) {
623					$(this).prop("checked", true);
624					eMapsCatCheck(eMaps, this);
625				}
626			});
627			thisButton
628				.text(uncheckAll)
629				.addClass("allchecked")
630				.removeClass("allunchecked");
631		}
632	});
633}
634
635function eMapsPoiListeInit(eMaps) {
636	eMaps["map"].on("move ", function () {
637		var mapBounds = eMaps["map"].getBounds();
638		for (var i = 0; i < eMaps["marker"].length; i++) {
639			var poi = eMaps["marker"][i];
640			if (mapBounds.contains(poi.getLatLng())) {
641				eMapsShowPoi(eMaps, poi);
642			} else {
643				eMapsHidePoi(eMaps, poi);
644			}
645		}
646	});
647}

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.