PageSourceSearch

https://www.ronc-on.it/assets_frontend/general/js/maps.js?rel=0.38

js ronc-on.it collected 2026-09-26 13:29:20 UTC 13,897 bytes, 361 lines download raw bytes

1// Ottieni l'URL della pagina corrente
2const url = window.location.href;
3const hash = simpleHash(url);
4
5if (document.getElementById('map') != null) {
6    const category = {};
7    let m = [];
8    var initial_zoom = 14
9
10    if (typeof markers !== 'undefined' && markers.markers.length > 0 && markers.markers.length < 2) {
11
12        if (typeof markers.markers[0].lat) {
13            initial_lat = markers.markers[0].lat
14        }
15
16        if (markers.markers[0].lng) {
17            initial_lng = markers.markers[0].lng
18        }
19    }
20
21
22    if (typeof maps_config !== 'undefined' && typeof maps_config.initial_zoom !== 'undefined') {
23        initial_zoom = maps_config.initial_zoom
24        initial_lat = maps_config.initial_lat
25        initial_lng = maps_config.initial_lng
26    }
27
28
29    const locale = getLocaleFromUrl();
30
31    function getLocaleFromUrl() {
32        const pathSegments = window.location.pathname.split('/');
33        return pathSegments[1]; // Adjust this number based on where the locale is in your URL
34    }
35
36
37    function disableMap(map) {
38        map.dragging.disable();
39        map.touchZoom.disable();
40        map.doubleClickZoom.disable();
41        map.scrollWheelZoom.disable();
42        map.zoomControl.disable();
43    }
44
45    function enableMap(map) {
46        map.dragging.enable();
47        map.touchZoom.enable();
48        map.doubleClickZoom.enable();
49        map.scrollWheelZoom.enable();
50        map.zoomControl.enable();
51    }
52
53    var currentMarker = null;
54    function currentPositionGen(map, center = false) {
55        if (navigator.geolocation) {
56            navigator.geolocation.getCurrentPosition(function (position) {
57                user_lat = position.coords.latitude;
58                user_lng = position.coords.longitude;
59
60                const distance = distanceBetweenPoints(initial_lat, initial_lng, user_lat, user_lng);
61                if (distance.toFixed(2) < 0.5 && center == true) {
62                    map.setView([user_lat, user_lng], 17);
63                }
64                var iconaLampeggiante = L.icon({
65                    iconUrl: '/assets_frontend/general/image/current_position.gif', // Sostituisci con l'URL della tua GIF animata
66                    iconSize: [38, 58], // Dimensioni dell'icona. Modifica secondo le dimensioni della tua GIF
67                    iconAnchor: [14, 55], // Punto dell'icona che corrisponderà esattamente alla posizione del marker
68                });
69                if (currentMarker) {
70                    currentMarker.setLatLng([user_lat, user_lng]);
71                } else {
72                    currentMarker = L.marker([user_lat, user_lng], { icon: iconaLampeggiante }).addTo(map);
73                }
74            })
75        }
76
77    }
78
79    function generateMaps() {
80        console.log('generateMaps');
81        
82        var osm = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
83            maxZoom: 20,
84            attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
85        });
86
87        var map = L.map('map', {
88            center: [initial_lat, initial_lng],
89            zoom: initial_zoom,
90            layers: [osm]
91        });
92
93
94
95
96        // disabilita la funzione nella pagina di singolo luogo
97        // if (typeof markers !== 'undefined' && typeof maps_config !== 'undefined' && maps_config.dragging == false) {
98        //     disableMap(map)
99        //     currentPositionGen(map, false)
100
101        // } else {
102        //     disableMap(map)
103        //     currentPositionGen(map, true)
104        //     map.on('click', function (e) {
105        //         enableMap(map);
106        //     });
107        //     map.on('mouseout', function (e) {
108        //         disableMap(map);
109        //     });
110        // }
111
112
113
114        disableMap(map)
115        currentPositionGen(map, true)
116        map.on('click', function (e) {
117            enableMap(map);
118        });
119        map.on('mouseout', function (e) {
120            disableMap(map);
121        });
122
123        setInterval(function () {
124            currentPositionGen(map, false);
125        }, 5000);
126
127        if (typeof markers !== 'undefined') {
128            m = insertMarkersInMap(map, m);
129
130            // Al click sulle chexbox sotto la mappa
131            $("#category_map").delegate('.filter_category_map', 'change', function () {
132                insertMarkersInMap(map, m, 0);
133            })
134
135            // if (typeof category !== 'undefined' && Object.keys(category).length > 1) {
136            //     var overlayMaps = {};
137
138            //     for (const key in category) {
139            //         var mar = [];
140            //         category[key].forEach(element => {
141            //             mar.push(m[element]);
142            //         });
143            //         overlayMaps[key] = L.layerGroup(mar)
144            //         overlayMaps[key].addTo(map)
145            //     }
146            //     var layerControl = L.control.layers({}, overlayMaps).addTo(map);
147            // }
148
149        }
150
151        if (typeof coords == 'undefined') return;
152
153        var drawnItems = new L.FeatureGroup();
154
155        if (typeof gpx_file !== 'undefined' && gpx_file.length > 0) {
156            gpx_file.forEach(element => {
157                new L.GPX('/' + element, {
158                    async: true,
159                    marker_options: {
160                        startIconUrl: '/assets_admin/img/pin-icon-start.png',
161                        endIconUrl: '/assets_admin/img/pin-icon-end.png',
162                        shadowUrl: '/assets_admin/img/pin-shadow.png',
163                    },
164                }).addTo(map);
165            });
166        }
167
168        if (coords.length > 0) {
169            coords.forEach(element => {
170                var polyline_new = L.polyline(element.coords, { color: 'red' }).addTo(map);
171                polyline_new.id = element.coordinate_id;
172                drawnItems.addLayer(polyline_new);
173            });
174        }
175
176
177        map.addLayer(drawnItems);
178
179
180
181
182    }
183    const mapElement = document.getElementById('map');
184    if (mapElement != null && mapElement.getAttribute('data-autostart') !== 'false') {
185        generateMaps();
186    }
187}
188
189function slugify(str) {
190    str = str.replace(/^\s+|\s+$/g, ''); // trim leading/trailing white space
191    str = str.toLowerCase(); // convert string to lowercase
192    str = str.replace(/[^a-z0-9 -]/g, '') // remove any non-alphanumeric characters
193        .replace(/\s+/g, '-') // replace spaces with hyphens
194        .replace(/-+/g, '-'); // remove consecutive hyphens
195    return str;
196}
197
198
199function insertMarkersInMap(map, m, regenerate = 1) {
200    m.forEach(marker => marker.remove())
201
202    if (regenerate == 1 && maps_config.multiple == true) {
203        let category = {}
204        let filter = null;
205
206        for (let i = 0; i < markers.markers.length; i++) {
207            if (markers.markers[i].category.title) {
208                if (typeof category[markers.markers[i].category.title] == 'undefined') {
209                    category[markers.markers[i].category.id] = {};
210                }
211                category[markers.markers[i].category.id].title = markers.markers[i].category.title;
212                category[markers.markers[i].category.id].pointer_color = markers.markers[i].category.pointer_color;
213                category[markers.markers[i].category.id].pointer_text_color = markers.markers[i].category.pointer_text_color;
214                category[markers.markers[i].category.id].pointer = markers.markers[i].category.pointer;
215                let visible = 1;
216                if (filter = sessionStorage.getItem(`filter_category_map_${hash}`)) {
217                    visible = JSON.parse(filter).includes(markers.markers[i].category.id) ? 1 : 0
218                } else {
219                    visible = markers.markers[i].category.default_visible
220                    if (markers.markers[i].category.id == 0) {
221                        visible = 1
222                    }
223                }
224                category[markers.markers[i].category.id].default_visible = visible;
225            }
226        }
227        $('#category_map').html('');
228
229        for (var key in category) {
230            $('#category_map').append(`
231                <style>
232                    .filter_category_map_wrap_${key} label:before {
233                        border-color: ${category[key]['pointer_color']};
234                    }
235                    .filter_category_map_wrap_${key} input[type=checkbox]:checked+label {
236                        background:${category[key]['pointer_color']};
237                        color: ${category[key]['pointer_text_color']};
238                    }
239                    .filter_category_map_wrap_${key} input[type=checkbox]:checked+label:before {
240                        background:${category[key]['pointer_color']};
241                        border-color: ${category[key]['pointer_color']};
242                    }
243                    .filter_category_map_wrap_${key}:before {
244                        border-color: ${category[key]['pointer_color']};
245                    }
246                </style>
247                <div class="filter_category_map_wrap filter_category_map_wrap_${key}" data-pointer-color="${category[key]['pointer_color']}">
248                    <input ${category[key]['default_visible'] == 1 ? 'checked' : ''} type="checkbox" class="filter_category_map" id="filter_category_map_${key}" data-category-id=${key} value="${key}_${category[key]['title']}" />
249                    <label for="filter_category_map_${key}" class="d-flex align-items-center">
250                        <span class="material-symbols-outlined">
251                            ${category[key]['pointer']}
252						</span>
253                        <span class="ms-2">${category[key]['title']}</span>
254                    </label>
255                </div>
256            `)
257        }
258        // $('.filter_category_map_wrap').each(function () {
259        //     console.log($(this).data('pointer-color'))
260        // })
261    }
262
263    const filter_checked = [];
264    $('.filter_category_map:checked').each(function () {
265        filter_checked.push($(this).data('categoryId'));
266    })
267    sessionStorage.setItem(`filter_category_map_${hash}`, JSON.stringify(filter_checked))
268
269
270    let addToUrl = '';
271
272    if (typeof itinerari_id != 'undefined') {
273        if (itinerari_id > 0) {
274
275            addToUrl = `?fromItinerario=${itinerari_id}`
276        }
277    }
278
279
280    for (let i = 0; i < markers.markers.length; i++) {
281        if (maps_config.multiple == false || ($(`#filter_category_map_${markers.markers[i].category.id}`).is(':checked') || (markers.markers[i].category.id == 0 && $(`#filter_category_map_0`).is(':checked')))) {
282
283            const id = markers.markers[i].id;
284            const lat = markers.markers[i].lat;
285            const lng = markers.markers[i].lng;
286            const title = markers.markers[i].title;
287            const desc = markers.markers[i].desc;
288            const img = markers.markers[i].img;
289            let addStyle = '';
290            if (typeof this_point != 'undefined' && this_point == id) {
291                addStyle = 'border:5px black solid;';
292            }
293            var myIcon = L.divIcon({
294                className: 'my-custom-pointer', // Aggiungi qui eventuali classi personalizzate
295                html: '<div class="pin shadow" style="' + addStyle + 'background: ' + markers.markers[i].category.pointer_color + ';color: ' + markers.markers[i].category.pointer_text_color + '"><span class="material-symbols-outlined">' + markers.markers[i].category.pointer + '</span></div>', // Usa il nome dell'icona che desideri
296                iconSize: [30, 40], // Dimensioni del div icona in pixel
297                iconAnchor: [15, 40], // Punto dell'icona che corrisponde alla posizione del marker
298                popupAnchor: [-3, -76] // Punto da cui il popup si aprirà rispetto all'icona
299            });
300
301
302
303
304            if (maps_config.popup === false) {
305                m[i] = L.marker([lat, lng], { icon: myIcon }).addTo(map);
306            } else {
307                m[i] = L.marker([lat, lng], { icon: myIcon }).bindPopup(`
308            <div class="row">
309                <div class="col-12">
310                    <div class="row">
311                        <div class="col">
312                            <h4>${title}</h4>
313                        </div>
314                        ${img ? `<div class="col-4"><img class="img-fluid" src="${img}" /></div>` : ''}
315                    </div>
316                </div>
317                <div class="col-12">
318                    ${desc ? `<p>${desc}</p>` : ''}
319                    <a href="/${getLocaleFromUrl()}/luoghi/${id}_${slugify(title)}.php${addToUrl}">${btn_text}</a>
320                </div>
321            </div>
322            `).addTo(map);
323            }
324        }
325    }
326
327    return m;
328}
329
330function simpleHash(str) {
331    let hash = 0;
332    if (str.length === 0) return hash;
333    for (let i = 0; i < str.length; i++) {
334        const char = str.charCodeAt(i);
335        hash = (hash << 5) - hash + char;
336        hash |= 0; // Converti in intero a 32-bit
337    }
338    return hash;
339}
340
341
342function toRadians(degrees) {
343    return degrees * Math.PI / 180;
344}
345
346function distanceBetweenPoints(lat1, lon1, lat2, lon2) {
347    const earthRadiusKm = 6371;
348
349    const dLat = toRadians(lat2 - lat1);
350    const dLon = toRadians(lon2 - lon1);
351
352    const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
353        Math.cos(toRadians(lat1)) * Math.cos(toRadians(lat2)) *
354        Math.sin(dLon / 2) * Math.sin(dLon / 2);
355
356    const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
357
358    const distance = earthRadiusKm * c;
359    return distance;
360}
361

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.