Leaflet Search for GeoJSON creating duplicate, non-functional buttons

المشرف العام

Administrator
طاقم الإدارة
I added a plugin for searching a GeoJSON file in leaflet, but now there are multiple search buttons and they do not recognize any input. I suspect that it is initializing for every single instance of a feature within the GeoJSON file. How do I change my script to only initialize once? (continued from this question: Activating Search Plugin with JS Leaflet

// load GeoJSON from an external file$.getJSON("Syriashape.json", function (data) {// add GeoJSON layer and popups to the map once the file is loadedvar syriaLayer = L.geoJson(data, { style: function (feature) { return {color: 'red', weight: '1pt'}; }, onEachFeature: function (feature, layer) { layer.bindPopup( "Sheet Number: " + feature.properties.Sheet_Numb + "</br>" + "Catalog Record: " + "" + feature.properties.LOC_Catalo + ""); //activate search button var searchControl = new L.Control.Search({layer: syriaLayer, propertyName: 'Sheet_Numb', circleLocation:false}); searchControl.on('search_locationfound', function(e) { e.layer.setStyle({}); if(e.layer._popup) e.layer.openPopup(); }).on('search_collapsed', function(e) { featuresLayer.eachLayer(function(layer) { //restore feature color featuresLayer.resetStyle(layer); }); }); map.addControl( searchControl ); //inizialize search control }}).addTo(map);});

أكثر...
 
أعلى