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 = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
mapquestLink = '<a href="http://www.mapquest.com//">MapQuest</a>';
mapquestPic = '<img src="http://developer.mapquest.com/content/osm/mq_logo.png">';
//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 = '<i class="fa fa-folder-open"></i>';
//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 ?