How to use leaflet-search for a geojson feature property?

المشرف العام

Administrator
طاقم الإدارة
All,

I'm trying to use the leaflet-search plugin to search for a specific geojson property (i.e. 'Name'). The trick part of this is I want to perform a search on a Geojson file thats loaded in via the FileLayerLoad plugin for leaflet.

So far my code is:

var map = L.map('map').setView([43.7001100, -79.4163000], 17); mapLink = 'OpenStreetMap'; mapquestLink = 'MapQuest'; mapquestPic = '
'; //Main map layer: L.tileLayer( 'http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png', { attribution: '© '+mapLink+'. Tiles courtesy of '+mapquestLink+mapquestPic, maxZoom: 18, subdomains: '1234', }).addTo(map); var style = {color: "green", opacity: 1.0, fillOpacity: .5, weight: 2, clickable: true ,smoothFactor:10,noClip:true,lineCap:"round"}; L.Control.FileLayerLoad.LABEL = ''; //Loads external geojson file: var control = new L.Control.fileLayerLoad({ fileSizeLimit: 5000, fitBounds: true, //MOVE THE CENTER OF THE SCREEN layerOptions: {style: style, onEachFeature: function(feature, layer) { layer.bindPopup( "Name: " + feature.properties.Name ); } } }).addTo(map); //Search within specified layer: map.addControl(L.control.search({layer: control, propertyName: 'Name', circleLocation:true})); The problem in the above code is in the L.control.search({layer:control... line, it calls the 'control' variable, which interprets this as a new fileLayerLoad call. I'm wondering how do I search within the layer thats already loaded ?

Any help would be much appreciated.

Thanks,

P



أكثر...
 
أعلى