PageSourceSearch

https://www.graine-bourgogne-franche-comte.fr/wp-content/themes/avante-child/js/map.js

js graine-bourgogne-franche-comte.fr collected 2026-09-26 10:21:19 UTC 6,540 bytes, 224 lines download raw bytes

1jQuery(document).ready(function($){
2
3	function initMap() {
4		if(!document.querySelector(".map")){
5			return;
6		}
7
8		var iconCustomUrl = $(".map").attr('data-icon');
9		
10		const clustering = false;
11
12		if(document.querySelector(".map").classList.contains("ecoles-map")){
13			return;
14		}
15
16        if ($(".map")[0]) {
17
18            const macarte = L.map('map', { 
19                zoom: 8,
20                zoomSnap: 0.1,
21                gestureHandling: true,
22                gestureHandlingOptions: {
23                    duration: 5000,
24                    text: {
25                        touch: "Vous pouvez zoomer sur la carte à l'aide de vos deux doigts",
26                        scroll: "Vous pouvez zoomer sur la carte à l'aide de CTRL + Molette de défilement",
27                        scrollMac: "Vous pouvez zoomer sur la carte à l'aide de \u2318 + Molette de défilement"
28                    }
29                }
30            });
31			
32			// VOIR : http://leaflet-extras.github.io/leaflet-providers/preview/index.html			
33			//var tilesURL =  'https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png';
34			var tilesURL = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
35			//var tilesURL = 'https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png';
36			//var tilesURL = 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png';
37
38            L.tileLayer(tilesURL, {
39                attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors &copy; <a href="https://carto.com/attributions">CARTO</a>',
40                minZoom: 4,
41                maxZoom: 16
42            }).addTo(macarte);
43			
44			
45			
46			
47			var myStyle = {				
48				weight: 5,
49				opacity: 0.7,
50				//color: '#CBCC02',
51				color: '#E26A0B',
52				//fillColor: 'green',
53				fillOpacity: 0
54			};
55			
56			// Load GEOJSON
57			fetch("/wp-content/themes/avante-child/kml/region-BFC.geojson")
58			.then(function(response) {
59				return response.json();
60			})
61			.then(function(data) {
62				var myGeoJSON  = L.geoJSON(data, {style: myStyle} ).addTo(macarte);
63				macarte.fitBounds(myGeoJSON.getBounds());
64			});
65			
66			
67			
68			
69			// Load kml file
70			// VOIR https://github.com/windycom/leaflet-kml			
71            /*
72		    fetch('/wp-content/themes/avante-child/kml/bourgogne-franche-comte-2023.kml')
73			.then(res => res.text())
74			.then(kmltext => {
75				// Create new kml overlay
76				const parser = new DOMParser();
77				const kml = parser.parseFromString(kmltext, 'text/xml');
78				const track = new L.KML(kml);
79				macarte.addLayer(track);
80
81				// Adjust map to show the kml
82				const bounds = track.getBounds();
83				macarte.fitBounds(bounds);
84			});
85			*/
86			
87			
88			// GET ALL customMarkers
89            const customMarkers = [];
90            const customMarkersCoordinates = [];
91
92            $( ".data-custommarker" ).each(function( index ) {
93
94                const customMarker = [];
95                const customMarkerCoordinates = [];
96
97                //lat 0
98                var lat = $(this).attr('data-lat');
99                customMarker.push(lat);
100                customMarkerCoordinates.push(lat);  
101
102                //longitude 1
103                var long = $(this).attr('data-lng');
104                customMarker.push(long);
105                customMarkerCoordinates.push(long);
106
107                //customMarker 2
108                var customMarker_id = $(this).attr('data-custommarker');
109                customMarker.push(customMarker_id);
110
111                //add customMarker to customMarkers
112                customMarkers.push(customMarker);
113
114                //add coordinates to coordinates customMarkers
115                if (customMarkerCoordinates[0] !== null && customMarkerCoordinates[1] !== null) {
116                	customMarkersCoordinates.push(customMarkerCoordinates);
117                }
118
119            });
120			
121			
122			if (clustering == false)
123			{
124				
125				
126				customMarkers.forEach(function(customMarker, index) {
127
128					var myIcon = L.icon({
129						iconUrl: iconCustomUrl,
130						iconSize: [25, 25],
131						iconAnchor: [25, 50],
132						popupAnchor: [-12, -50],
133					});
134					
135					 marker = new L.marker([customMarker[0], customMarker[1]], {icon: myIcon}).on('click', function(e){
136	
137						jQuery.ajax({
138							url: '/wp-admin/admin-ajax.php',
139							type: 'post',
140							data: { 
141								action: 'data_fetch',
142								markerId: customMarker[2],
143							},
144							success: function(data) {    
145								$(".popup_customMarker").append(data);    
146							}, error: function(data){
147								console.log(data);
148							}
149						});
150	
151						// ON décale légèrement vers le bas pour avoir la popup dans la zone de la carte
152						macarte.setView([e.target.getLatLng().lat+0.015, e.target.getLatLng().lng] , 13);
153	
154					});
155					
156					marker.bindPopup('<strong class="popup_customMarker"></strong>');
157					marker.addTo(macarte);
158					
159					// Si on ferme la popup, on recentre sur le marker
160					marker.getPopup().on('remove', function(e) {
161						macarte.setView(e.target.getLatLng());
162					});
163	
164				});
165				
166				
167			}
168			else
169			{
170				
171				var markers = new L.MarkerClusterGroup();
172
173				customMarkers.forEach(function(customMarker, index) {
174	
175					var myIcon = L.icon({
176						iconUrl: iconCustomUrl,
177						iconSize: [25, 25],
178						iconAnchor: [25, 50],
179						popupAnchor: [-12, -50],
180					});
181	
182					//ACTION POPUP
183					markers.addLayer(L.marker([customMarker[0], customMarker[1]], {icon: myIcon}).on('click', function(e){
184	
185						jQuery.ajax({
186							url: '/wp-admin/admin-ajax.php',
187							type: 'post',
188							data: { 
189								action: 'data_fetch',
190								markerId: customMarker[2],
191							},
192							success: function(data) {
193		
194								$(".popup_customMarker").append(data);
195		
196							}, error: function(data){
197								console.log(data);
198							}
199						});
200	
201						// ON décale légèrement vers le bas pour avoir la popup dans la zone de la carte
202						macarte.setView([e.target.getLatLng().lat+0.015, e.target.getLatLng().lng] , 13);
203	
204					}).bindPopup('<strong class="popup_customMarker"></strong>'));
205	
206				});
207	
208				macarte.addLayer(markers);					
209			
210			} 
211
212            var bounds = new L.LatLngBounds(customMarkersCoordinates);
213
214            macarte.fitBounds(bounds, {padding: [75, 75]});   
215            
216            macarte.invalidateSize();
217
218        }
219
220    }
221
222    initMap(); 
223    
224});

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.