Leaflet search

162 просмотра
Перейти к первому непрочитанному сообщению

SL9

не прочитано,
27 июл. 2015 г., 21:10:5127.07.2015
– 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

не прочитано,
31 июл. 2015 г., 04:48:3231.07.2015
– 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);
            }
Ответить всем
Отправить сообщение автору
Переслать
0 новых сообщений