PageSourceSearch

https://rosta.com/typo3conf/ext/ns_open_streetmap/Resources/Public/js/map.js?1771939859

js rosta.com collected 2026-10-08 10:54:41 UTC 40,611 bytes, 749 lines download raw bytes

1(function ($) {
2
3    var loadMap = window.openstreetmap = window.openstreetmap || {};
4    /**
5     * Controller for Map functionality
6     *
7     * @param {HTMLElement} element
8     * @param {loadMap.Data} openstreetmap
9     * @constructor
10     */
11     
12 
13
14    loadMap = function (element, openstreetmap) {
15        var $element = this.element = $(element);
16        this.openstreetmap = openstreetmap;
17        this.data = openstreetmap;
18        var mapID = jQuery("#" + openstreetmap.mapSettings.id);
19        var markers = [];
20           
21        $.each(mapID, function (index, value) {
22            // Set Height of Map
23            openstreetmap.mapSettings.heigth !== '' ? $(mapID).height(openstreetmap.mapSettings.height) : $(mapID).height('500px');
24         
25            if (openstreetmap.locations[0] === undefined) {
26                var map = L.map(value.id, {
27                    center: [21.7484579, 72.136424]
28                });
29                L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
30                    attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
31                }).addTo(map);
32
33                var searchMarker = L.marker([21.7484579, 72.136424]);
34                map.addLayer(searchMarker);
35                     
36                if (openstreetmap.radiussearch2 == true || openstreetmap.storage == true) {
37               
38                    $('#rcd_form_' + openstreetmap.mapSettings.id).submit(function (event) {
39                        event.preventDefault();
40                        var nodata = document.getElementById("nodata");
41                        nodata.style.display = "none";
42
43                        let $formData = $(this).serialize();
44                        let urlSearch = $(this).attr('action');
45                        $.ajax({
46                            method: 'post',
47                            url: urlSearch,
48                            data: $formData,
49                            dataType: 'json',
50                            success: function (response) {
51                                event.preventDefault();
52                                if (response != '') {
53                                    let recordMarker;
54                                    const locations = responseData['records'];
55                                    let i;
56                                    if (locations) {
57                                        map.eachLayer(function (recordMarker) {
58                                            if (recordMarker instanceof L.Marker) {
59                                                map.removeLayer(recordMarker)
60                                            }
61                                        })
62                                        for (i = 0; i < locations.length; i++) {
63                                            var markerLocation = new L.LatLng(locations[i][1], locations[i][2]);
64                                            recordMarker = new L.Marker(markerLocation);
65                                            map.setView([locations[i][1], locations[i][2]], 2);
66                                            map.addLayer(recordMarker);
67                                            recordMarker.bindPopup("<div class='info-window'><div class='title'><b>" + locations[i][0] + "</b></div><div class='address'>" + locations[i][3] + "</div></div>");
68                                        }
69                                        $('#sidebar_' + openstreetmap.mapSettings.id).html("");
70
71                                        if (openstreetmap.showsidebar == 1) {
72                                            $html = '';
73                                            for (let i = 0; i < locations.length; i++) {
74                                                $html += '<div class="map-add" data-markerid="' + i + '" data-lat="' + locations[i][1] + '" data-lng="' + locations[i][2] + '" data-title="' + locations[i][0] + '">' +
75                                                    '<div class="title">' +
76                                                    '<b>' + locations[i][0] + '</b>' +
77                                                    '</div>' +
78                                                    '<div class="address">' + locations[i][3] + '</div>' +
79                                                    '</div>';
80                                            }
81                                            $($html).appendTo('#sidebar_' + openstreetmap.mapSettings.id).fadeIn(1000);
82                                        } else {
83                                            $('#sidebar_' + openstreetmap.mapSettings.id).html("");
84                                        }
85                                    }
86                                }
87                                //Response Not Get
88                                else {
89                                    $('#sidebar_' + openstreetmap.mapSettings.id).html("");
90                                    nodata.style.display = "block";
91                                    map.eachLayer(function (recordMarker) {
92                                        if (recordMarker instanceof L.Marker) {
93                                            map.removeLayer(recordMarker)
94                                        }
95                                    })
96                                }
97                            },
98                            error: function (error) {
99                                alert('Could Not Find Data: error; ' + eval(error));
100                            }
101                        });
102                    });
103                }
104            }
105            /* FullScreen Control Configuration and Create the map  */
106            if (openstreetmap.mapSettings.fullscreenControl === true) {
107                var map = new L.map(value.id, {
108                    fullscreenControl: true,
109                    scrollWheelZoom: false
110                }).setView([openstreetmap.locations[0].latitude, openstreetmap.locations[0].longitude]);
111                var fullScreenPosition = openstreetmap.mapSettings.fullscreenControlOptions.position;
112                switch (fullScreenPosition) {
113                    case 'top_left':
114                        map.fullscreenControl.setPosition('topleft');
115                        break;
116
117                    case 'bottom_left':
118                        map.fullscreenControl.setPosition('bottomleft');
119                        break;
120
121                    case 'bottom_right':
122                        map.fullscreenControl.setPosition('bottomright');
123                        break;
124
125                    default:
126                        map.fullscreenControl.setPosition('topright');
127                        break;
128                }
129            } else {
130                var map = new L.map(value.id, { scrollWheelZoom: false }).setView([openstreetmap.locations[0].latitude, openstreetmap.locations[0].longitude]);
131            }
132            configurationOptions(openstreetmap);
133
134            // Add default Marker     
135            var points = [];
136            $.each(openstreetmap.locations, function (index, value) {
137                points[index] = [value.title, value.address, value.latitude, value.longitude, value.icon, value.infoWindowContent];
138            });
139
140            /*  Scale Control Configuration */
141            var scaleControlsEnable = L.control.scale({ maxWidth: 240, metric: true, position: 'bottomleft' });
142            if (openstreetmap.mapSettings.scaleControl !== false) {
143                scaleControlsEnable.addTo(map);
144            }
145
146            // Placing markers
147            for (var i = 0; i < points.length; i++) {
148                createMarker(points[i][0], points[i][1], points[i][2], points[i][3], points[i][4], points[i][5]);
149            }
150
151            // Add click handler for sidebar elements using event delegation
152            $(document).on('click', '.map-add', function () {
153                var title = $(this).attr('data-title');
154                var lat = $(this).attr('data-lat');
155                var lng = $(this).attr('data-lng');
156                var zoomLevel = parseInt(document.getElementsByName('maxZoom')[0].value) || 16;
157
158                console.log('Sidebar item clicked:', { title: title, lat: lat, lng: lng, zoomLevel: zoomLevel });
159
160                if (lat && lng) {
161                    map.setView([lat, lng], zoomLevel);
162                } else {
163                    console.error('Missing coordinates for sidebar item:', title);
164                }
165            });
166
167            /*---------------------Map Configurations - start----------------*/
168            function configurationOptions(openstreetmap) {
169                /* Zoom Level */
170                if (openstreetmap.mapSettings.zoom !== 0) {
171                    map.setZoom(parseInt(document.getElementsByName('maxZoom')[0].value));
172                }
173
174                //Defaul Map Type Style Option Configuration
175                let OpenStreetMap_Maplink;
176                var mapStyletheme = openstreetmap.defaultMapTypes;
177
178                switch (mapStyletheme) {
179                    case 'satellite':
180                        OpenStreetMap_Maplink = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}.png', {
181                            attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
182                        }).addTo(map);
183                        break;
184
185                    case 'hybrid':
186                        OpenStreetMap_Maplink = L.tileLayer('https://api.maptiler.com/maps/hybrid/{z}/{x}/{y}@2x.jpg?key=DXBhrLVYaeuix0IPoCn3', {
187                            attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
188                        }).addTo(map);
189                        break;
190
191                    case 'terrain':
192                        OpenStreetMap_Maplink = L.tileLayer('https://tiles.stadiamaps.com/tiles/outdoors/{z}/{x}/{y}{r}.png', {
193                            attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
194                        }).addTo(map);
195                        break;
196
197                    default:
198                        OpenStreetMap_Maplink = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
199                            attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
200                        }).addTo(map);
201                        break;
202                }
203
204                /* Map Scrolling zoom */
205                if (openstreetmap.mapSettings.scrollwheel == 'true') {
206                    $('#' + openstreetmap.mapSettings.id).bind('mousewheel DOMMouseScroll', function (event) {
207                        event.stopPropagation();
208                        if (event.ctrlKey == true) {
209                            event.preventDefault();
210                            map.scrollWheelZoom.enable();
211                            $('#' + openstreetmap.mapSettings.id).removeClass('map-scroll');
212                            setTimeout(function () {
213                                map.scrollWheelZoom.disable();
214                            }, 1000);
215                        } else {
216                            $('#' + openstreetmap.mapSettings.id).addClass('map-scroll');
217                            map.scrollWheelZoom.disable();
218                        }
219                    });
220                    $(window).bind('mousewheel DOMMouseScroll', function () {
221                        $('#' + openstreetmap.mapSettings.id).removeClass('map-scroll');
222                    })
223                } else {
224                    map.scrollWheelZoom.disable();
225                }
226
227                /* Map Draggable */
228                openstreetmap.mapSettings.draggable === 'true' ? map.dragging.enable() : map.dragging.disable();
229
230                /* Map Double Click Zoom */
231                openstreetmap.mapSettings.doubleClickZoom === true ? map.doubleClickZoom.enable() : map.doubleClickZoom.disable();
232
233                /* Zoom Control Type Configuration */
234                if (openstreetmap.mapSettings.zoomControl == false) {
235                    map.removeControl(map.zoomControl);
236                } else {
237                    var zoomControlPosition = openstreetmap.mapSettings.zoomControlOptions.position;
238                    switch (zoomControlPosition) {
239                        case 'top_right':
240                            map.zoomControl.setPosition('topright');
241                            break;
242
243                        case 'bottom_left':
244                            map.zoomControl.setPosition('bottomleft');
245                            break;
246
247                        case 'bottom_right':
248                            map.zoomControl.setPosition('bottomright');
249                            break;
250
251                        default:
252                            map.zoomControl.setPosition('topleft');
253                            break;
254                    }
255                }
256            }
257
258            /*----------------------------------End----------------------------------*/
259
260            /**
261             *
262             * @param  title
263             * @param  address
264             * @param  lat
265             * @param  lng
266             * @param  icon
267             * @param  infoWindowContent
268
269             */
270            function createMarker(title, address, lat, lng, icon, infoWindowContent) {
271                var marker;
272                //Set Icon which is uploaded in Backend
273                if (icon !== '') {
274                    var backendIcon = L.icon({
275                        iconUrl: icon
276                    });
277                    marker = L.marker([lat, lng], { icon: backendIcon });
278                } else {
279                    marker = L.marker([lat, lng]);
280                }
281                var labels = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
282                var markerLabel = labels[Math.floor(Math.random() * labels.length)];
283                marker.title = title;
284                marker.alt = address;
285
286                //Show Alphabet Label of marker when mouse hover on marker
287                if (openstreetmap.mapSettings.markerLabel == 1) {
288                    marker.setOpacity(openstreetmap.mapSettings.markerOpacity);
289                    marker.bindTooltip("<div class='info-title'>" + markerLabel + "</div>");
290                    marker.bindPopup(`<div class='info-window'>${infoWindowContent}</div>`);
291                } else {
292                    markerLabel = null;
293                    marker.setOpacity(openstreetmap.mapSettings.markerOpacity);
294                    marker.bindPopup(`<div class='info-window'>${infoWindowContent}</div>`);
295                }
296
297                //Cluster 
298                if (openstreetmap.mapSettings.markerCluster == 1) {
299                    if (markers.length !== marker.length) {
300                        markers.push({
301                            'lat': lat,
302                            'lng': lng,
303                            'infoWindowContent': infoWindowContent,
304                            'markerLabel': markerLabel,
305                            'marker': marker
306                        });
307                    }
308                } else {
309                    marker.addTo(map);
310                }
311            }
312
313            // Initialize marker cluster group if clustering is enabled
314            if (openstreetmap.mapSettings.markerCluster == 1) {
315                var styleIcon = openstreetmap.mapSettings.markerClusterStyle;
316                //Cluster group create with custom icon
317                var markerClusters = new L.markerClusterGroup({
318                    disableClusteringAtZoom: openstreetmap.mapSettings.markerClusterZoom,
319                    spiderfyOnMaxZoom: false,
320                    maxClusterRadius: 50, // Reduce cluster radius for better performance
321                    chunkedLoading: true, // Enable chunked loading for better performance
322                    chunkInterval: 200, // Process markers in chunks of 200ms
323                    chunkDelay: 50, // Delay between chunks
324                    iconCreateFunction: function (cluster) {
325                        if (styleIcon === 0) {
326                            return new L.DivIcon({
327                                html: `<div class="clusters">
328                                    <img src="${openstreetmap.clusterIcon1}" height="30" width="27" />                              
329                                    <div class="childCount">${cluster.getChildCount()}</div>
330                                  </div>`,
331                                className: 'icon',
332                                iconSize: L.point(49, 49)
333                            });
334                        }
335                        if (styleIcon === 1) {
336                            return new L.DivIcon({
337                                html: `<div class="clusters">
338                                    <img src="${openstreetmap.clusterIcon2}" height="30" width="27" />                              
339                                    <div class="childCount">${cluster.getChildCount()}</div>
340                                  </div>`,
341                                className: 'icon',
342                                iconSize: L.point(49, 49)
343                            });
344                        }
345                        if (styleIcon === 2) {
346                            return new L.DivIcon({
347                                html: `<div class="clusters">
348                                    <img src="${openstreetmap.clusterIcon3}" height="30" width="27" />                              
349                                    <div class="childCount">${cluster.getChildCount()}</div>
350                                  </div>`,
351                                className: 'icon',
352                                iconSize: L.point(49, 49)
353                            });
354                        }
355                        if (styleIcon === 3) {
356                            return new L.DivIcon({
357                                html: `<div class="clusters">
358                                    <img src="${openstreetmap.placeIcon}" height="30" width="27" />                              
359                                    <div class="childCount">${cluster.getChildCount()}</div>
360                                  </div>`,
361                                className: 'icon',
362                                iconSize: L.point(49, 49)
363                            });
364                        }
365                        if (styleIcon === -1) {
366                            return new L.DivIcon({
367                                html: `<div class="clusters">
368                                    <img src="${openstreetmap.clusterIcon4}" />                              
369                                    <div class="childCount">${cluster.getChildCount()}</div>
370                                  </div>`,
371                                className: 'icon',
372                                iconSize: L.point(49, 49)
373                            });
374                        }
375                    }
376                });
377
378                // Add markers to cluster group in chunks
379                function addMarkersToCluster() {
380                    var chunkSize = 100;
381                    var i = 0;
382
383                    function processChunk() {
384                        var chunk = markers.slice(i, i + chunkSize);
385                        chunk.forEach(function (markerData) {
386                            var markerClusterIcon = markerData.marker;
387                            if (openstreetmap.mapSettings.markerLabel == 1) {
388                                markerClusterIcon.bindTooltip("<div class='info-title'>" + markerData.markerLabel + "</div>");
389                            }
390                            markerClusterIcon.bindPopup("<div class='info-window'>" + markerData.infoWindowContent + "</div>");
391                            markerClusterIcon.setOpacity(openstreetmap.mapSettings.markerOpacity);
392                            markerClusters.addLayer(markerClusterIcon);
393                        });
394
395                        i += chunkSize;
396                        if (i < markers.length) {
397                            setTimeout(processChunk, 50);
398                        } else {
399                            map.addLayer(markerClusters);
400                        }
401                    }
402
403                    processChunk();
404                }
405
406                // Start adding markers to cluster
407                addMarkersToCluster();
408
409                //Remove Cluster Marker When Record Search Form Submit
410                if (markerClusters !== '' || markerClusters !== undefined && marker !== '') {
411                    $('#rcd_form_' + openstreetmap.mapSettings.id).submit(function (event) {
412                        map.removeLayer(markerClusters);
413                    });
414                }
415            }
416
417            /*---------------------Record Based Search - start----------------*/
418            if (openstreetmap.radiussearch2 == true) {
419                $('#rcd_form_' + openstreetmap.mapSettings.id).submit(function (event) {
420                    event.preventDefault();
421                    var nodata = document.getElementById("nodata");
422                    nodata.style.display = "none";
423
424                    let formData = $(this).serialize();
425                    let urlSearch = $(this).attr('action');
426                    console.log(urlSearch)
427                    $.ajax({
428                        method: 'post',
429                        url: urlSearch,
430                        data: formData,
431                        dataType: 'json',
432                        success: function (responseData) {
433                            event.preventDefault();
434                            if (responseData != '') {
435                                let recordMarker;
436                                const locations = responseData['records'];
437                                let i;
438                                if (locations) {
439                                    map.eachLayer(function (recordMarker) {
440                                        if (recordMarker instanceof L.Marker) {
441                                            map.removeLayer(recordMarker)
442                                        }
443                                    })
444                                    for (i = 0; i < locations.length; i++) {
445                                        var markerLocation = new L.LatLng(locations[i][1], locations[i][2]);
446
447                                        // Check if custom marker icon is available in locations[i][7]
448                                        if (locations[i][7] && locations[i][7] !== '') {
449                                            var customIcon = L.icon({
450                                                iconUrl: locations[i][7]
451                                            });
452                                            recordMarker = new L.Marker(markerLocation, { icon: customIcon });
453                                        } else {
454                                            recordMarker = new L.Marker(markerLocation);
455                                        }
456
457                                        // Set zoom level based on clustering settings
458                                        map.setView([locations[i][1], locations[i][2]], document.getElementsByName('maxZoom')[0].value);
459                                        map.addLayer(recordMarker);
460                                        recordMarker.bindPopup("<div class='info-window'><div class='title'><b>" + locations[i][0] + "</b></div><div class='address'>" + locations[i][3] + "</div></div>");
461                                    }
462                                    $('#sidebar_' + openstreetmap.mapSettings.id).html("");
463
464                                    if (openstreetmap.showsidebar == 1) {
465                                        let $html = '';
466                                        for (let i = 0; i < locations.length; i++) {
467
468                                            $html += `
469                                                <div class="map-add" 
470                                                    data-markerid="${i}" 
471                                                    data-lat="${locations[i][1]}" 
472                                                    data-lng="${locations[i][2]}" 
473                                                    data-title="${locations[i][0]}">
474                                                    <div class="title">
475                                                    ${locations[i][8] ? `<div><img src="${locations[i][8]}" alt="${locations[i][0]}" title="${locations[i][0]}" class="profile-avatar" /></div>`: ''}
476                                                    <b>${locations[i][0]}</b></div>
477                                                    <div class="address">${locations[i][3]}</div>
478                                                    <div class="more-info">${locations[i][6]}</div>
479                                                    ${locations[i][5] == 1 ? `<a href="https://www.openstreetmap.org/?mlat=${locations[i][1]}&mlon=${locations[i][2]}&zoom=16" target="_blank">View on OpenStreetMap</a>`: ''}
480                                                </div>
481                                            `;
482
483                                        }
484
485                                        const mapUid = document.querySelector('input[name="mapUid"]').value;
486                                        const sidebarSelector = '#sidebar_map_' + mapUid;
487
488                                        $($html).appendTo(sidebarSelector).fadeIn(1000)
489                                        $(`#rcd_form_map_${mapUid}`).find('button[type="reset"]')
490                                            .off('click')
491                                            .on('click', function (e) {
492                                                e.preventDefault();
493                                                location.reload();
494                                            })
495                                    }
496
497
498                                    else {
499                                        const mapUid = document.querySelector('input[name="mapUid"]').value;
500                                        const sidebarSelector = '#sidebar_map_' + mapUid;
501                                        $(sidebarSelector).html("");
502                                        $(`#rcd_form_map_${mapUid}`).find('button[type="reset"]')
503                                            .off('click')
504                                            .on('click', function (e) {
505                                                e.preventDefault();
506                                                location.reload();
507                                            })
508
509                                    }
510                                }
511                            }
512                            //Response Not Get
513                            else {
514                                const mapUid = document.querySelector('input[name="mapUid"]').value;
515                                const sidebarSelector = '#sidebar_map_' + mapUid;
516                                nodata.style.display = "block";
517                                $(`#rcd_form_map_${mapUid}`).find('button[type="reset"]')
518                                    .off('click')
519                                    .on('click', function (e) {
520                                        e.preventDefault();
521                                        location.reload();
522                                    })
523                            }
524                        },
525                        error: function (error) {
526
527                            alert('Could Not Find Data: error; ' + eval(error));
528                            const mapUid = document.querySelector('input[name="mapUid"]').value;
529                            $(`#rcd_form_map_${mapUid}`).find('button[type="reset"]')
530
531                        }
532                    });
533                });
534            }
535            /*----------------------------------End----------------------------------*/
536
537
538            /*---------------------Radius Search Options - start----------------*/
539            if (openstreetmap.radiussearch1 == true) {
540
541                /*---------------------Get distance with direction - start----------------*/
542                $('#get_direction_' + openstreetmap.mapSettings.id).click(function () {
543                    var start_point = $('#start_' + openstreetmap.mapSettings.id).val();
544                    var end_point = $('#end_' + openstreetmap.mapSettings.id).val();
545
546                    var xhttp = new XMLHttpRequest();
547                    xhttp.onreadystatechange = function () {
548                        if (this.readyState == 4 && this.status == 200) {
549                            var dataStartPoint = JSON.parse(this.responseText)
550
551                            // check start point coordinates empty or not 
552                            if (dataStartPoint != '') {
553                                var xhttps = new XMLHttpRequest();
554                                xhttps.onreadystatechange = function () {
555                                    if (this.readyState == 4 && this.status == 200) {
556                                        var dataEndPoint = JSON.parse(this.responseText);
557                                        // check end point coordinates empty or not 
558                                        if (dataEndPoint == '') {
559                                            var notfoundmsg = document.getElementById('notfound_' + openstreetmap.mapSettings.id).value;
560                                            window.alert(notfoundmsg);
561                                        } else {
562                                            var wayPoint1 = L.latLng(parseFloat(dataStartPoint[0].lat), parseFloat(dataStartPoint[0].lon));
563                                            var wayPoint2 = L.latLng(parseFloat(dataEndPoint[0].lat), parseFloat(dataEndPoint[0].lon));
564                                            var myRouting = new L.Routing.control({
565                                                waypoints: [wayPoint1, wayPoint2],
566                                                show: false,
567                                                addWaypoints: false,
568                                                autoRoute: true,
569                                                routeWhileDragging: false,
570                                                draggableWaypoints: false,
571                                                useZoomParameter: true,
572                                                showAlternatives: false
573                                            }).addTo(map);
574                                            // Add routing error event handler
575                                            myRouting.on('routingerror', function (e) {
576                                                var notfoundmsg = document.getElementById('notfound_' + openstreetmap.mapSettings.id).value;
577                                                var error = JSON.parse(e.error.target.response);
578                                                window.alert(error.message || notfoundmsg);
579                                            });
580                                            var controlContainer = myRouting.getContainer();
581                                            $('#dis_dir_block_' + openstreetmap.mapSettings.id).html(controlContainer);
582                                            $('#get_direction_' + openstreetmap.mapSettings.id).click(function () {
583                                                myRouting.remove(map);
584                                            });
585                                        }
586                                    }
587                                };
588                                xhttps.open("GET", "https://nominatim.openstreetmap.org/search?format=json&q=" + end_point);
589                                xhttps.send();
590                            } else {
591                                var notfoundmsg = document.getElementById('notfound_' + openstreetmap.mapSettings.id).value;
592                                window.alert(notfoundmsg);
593                            }
594                        }
595                    };
596                    xhttp.open("GET", "https://nominatim.openstreetmap.org/search?format=json&q=" + start_point);
597                    xhttp.send();
598                });
599                /*----------------------------------End----------------------------------*/
600                /*---------------------Auto Complete Location - start----------------*/
601                if (openstreetmap.autocompleteLocations == 1) {
602                    //Autocomplete address 
603                    new Autocomplete('rdus_src_' + openstreetmap.mapSettings.id,
604                        {
605                            selectFirst: true,
606                            insertToInput: true,
607                            cache: true,
608                            howManyCharacters: 2,
609
610                            onSearch: ({ currentValue }) => {
611                                const api = `https://nominatim.openstreetmap.org/search?format=geojson&limit=5&city=${encodeURI(currentValue)}`;
612                                /**
613                                 * Promise
614                                 */
615                                return new Promise((resolve) => {
616                                    fetch(api)
617                                        .then((response) => response.json())
618                                        .then((data) => {
619                                            resolve(data.features);
620                                        })
621                                        .catch((error) => {
622                                            console.error(error);
623                                        });
624                                });
625                            },
626                            // nominatim GeoJSON format
627                            onResults: ({ currentValue, matches, template }) => {
628                                const regex = new RegExp(currentValue, "gi");
629                                // if the result returns 0 we show the no results element
630                                return matches === 0
631                                    ? template
632                                    : matches
633                                        .map((element) => {
634                                            return `
635                                        <li type='none'>
636                                        <p>
637                                            ${element.properties.display_name.replace(
638                                                regex,
639                                                (str) => `<b>${str}</b>`
640                                            )}
641                                        </p>
642                                        </li>`;
643                                        })
644                                        .join("");
645                            },
646                            // the method presents no results
647                            noResults: ({ currentValue, template }) =>
648                                template(`<li type='none'>No results found for "${currentValue}"</li>`),
649                        });
650                }
651                /*----------------------------------End----------------------------------*/
652
653                /*---------------------Allow Current Location to Fill Address - start----------------*/
654                if (openstreetmap.allowcurrentlocation == 1) {
655                    $('#location').click(function () {
656                        navigator.geolocation.getCurrentPosition(function (position) {
657                            var xhttp = new XMLHttpRequest();
658                            xhttp.onreadystatechange = function () {
659                                if (this.readyState == 4 && this.status == 200) {
660                                    var address = JSON.parse(this.responseText)
661                                    $('#rdus_src_' + openstreetmap.mapSettings.id).val(address.display_name);
662                                }
663                            };
664                            xhttp.open("GET", "https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=" + position.coords.latitude + "&lon=" + position.coords.longitude);
665                            xhttp.send();
666                        });
667                    });
668                }
669                /*----------------------------------End----------------------------------*/
670
671                /*---------------------Find places on the map - start----------------*/
672                $('#rdus_btn_' + openstreetmap.mapSettings.id).click(function () {
673                    var placeadd = $('#rdus_src_' + openstreetmap.mapSettings.id).val();
674                    var placetype = $('#rdus_src_type_' + openstreetmap.mapSettings.id).val();
675                    map.removeLayer(markers);
676                    var nodataofplace = document.getElementById('nodataofplace');
677                    var xhttp = new XMLHttpRequest();
678                    xhttp.onreadystatechange = function () {
679                        if (this.readyState == 4 && this.status == 200) {
680                            var data = JSON.parse(this.responseText)
681                            function onEachFeature(feature) {
682                                var placeIcon = L.icon({
683                                    iconUrl: openstreetmap.placeIcon,
684                                    iconSize: [25, 41]
685                                })
686                                var lat = feature.geometry.coordinates[1];
687                                var lng = feature.geometry.coordinates[0];
688                                var address = feature.properties.name;
689
690                                var newMarker = new L.marker([lat, lng], { icon: placeIcon });
691                                newMarker.addTo(map);
692                                newMarker.bindPopup("<div class='info-title'>" + address + "</div>");
693                                map.setView([lat, lng], 13);
694                                map.addLayer(newMarker);
695                                $('#rdus_btn_' + openstreetmap.mapSettings.id).click(function () {
696                                    map.removeLayer(newMarker);
697                                });
698                            }
699
700                            //Check Data is empty or not
701                            if (jQuery.isEmptyObject(data.features) == true) {
702                                nodataofplace.style.display = "block";
703                            } else {
704                                nodataofplace.style.display = "none";
705                            }
706
707                            L.geoJSON(data, {
708                                onEachFeature: onEachFeature
709                            });
710                        }
711                    };
712                    xhttp.open("GET", "https://photon.komoot.io/api/?q=" + placeadd + "&osm_tag=" + placetype);
713                    xhttp.send();
714                });
715                /*----------------------------------End----------------------------------*/
716            }
717            /*----------------------------------End----------------------------------*/
718        });
719        // open info window
720        window.setTimeout(function () {
721            $element.trigger("openinfo");
722        }, 2000);
723    };
724
725    // Create a new OpenStreet Map
726    $.fn.nsopenstreetmap = function (openstreetmap) {
727        alert("when you use this map.js you need to remove line 156 from AddressController.php");
728        var $element = $(this);
729        if (!$element.data('openstreetmap')) {
730            $element.data('openstreetmap', new loadMap($element, openstreetmap));
731        }
732    };
733
734    setTimeout(() => {
735
736        $(document).ready(function () {
737            sideHeight();
738        });
739        $(window).resize(function () {
740            sideHeight();
741        });
742        function sideHeight() {
743            var mapblock = $('.map_canvas').outerHeight();
744            $('.add_sidebar').css('height', mapblock);
745        }
746
747    }, 400);
748
749}(jQuery));    

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.