Leaflet search

162 views
Skip to first unread message

SL9

unread,
Jul 27, 2015, 9:10:51 PM7/27/15
to Leaflet
I'm trying to implement search capability on my leaflet map using leaflet-fusesearch

I manage to get the search control added to the map but the search function itself is not working.

Here's how I'm trying to add geojson to the search - any help very much appreciated.

$.ajax({
    beforeSend: function(request) {
        //request.setRequestHeader("X-Mashape-Key", 'key_here');
    },
    dataType: "json",
    success: function(response) {
        geojsonLayer = L.geoJson(response, {
            onEachFeature: function (feature, layer) {
                                            layer.setIcon(incidentIcon);
                                            layer.bindPopup ("Incident<p>Road: "+feature.properties.location.road+"<p>Direction: "+feature.properties.location.direction);
                                            
                                          }
        }).addTo(map);
var props = ['road'];
fuseSearchCtrl.indexFeatures(geojsonLayer.features, props);
    }
});

Matt Travis

unread,
Jul 31, 2015, 4:48:32 AM7/31/15
to Leaflet, saul....@gmail.com
Try adding feature.layer = layer; to your onEachFeature function

Worked for me in this example:

onEachFeature: function (feature, layer) {
feature.layer = layer;
                popupOptions = {maxWidth: 200};
                layer.bindPopup("<h3>" + feature.properties.full_name + "</h3>"
                    ,popupOptions);
            }
Reply all
Reply to author
Forward
0 new messages