External access to Leaflet.js GeoJson functions

I want to interact with the GeoJson board with a label with an elevator (polygons) from outside the area L., but I seem to be unable to access the objects created with L..

The interaction will include:

  • getBounds (myFeature)
  • fitBounds (myFeature)
  • SetStyle etc.

I see Leaflet exposing L.GeoJSON.getFeature (), but I can't seem to squeeze anything out of it. There is no documentation, and the inspector seems to suggest that she not accept the arguments ...: \

Is it just for future development?

enter image description here

+4
source share
1 answer

getLayer .
http://leafletjs.com/reference.html#layergroup-getlayer

var geojsonLayer = L.geoJson(data,{
    onEachFeature: function(feature, layer) {
        layer._leaflet_id = feature.id;                                    
    }});
geojsonLayer.addTo(map);

feature = geojsonLayer.getLayer(12345); //your feature id here
alert(feature.feature.id);
+7

All Articles