問題描述
我想與 L.
領(lǐng)域之外的傳單驅(qū)動地圖的 GeoJson 覆蓋(多邊形)進行交互,但我似乎無法訪問由 創(chuàng)建的對象L.
.
I want to interact with a leaflet powered map's GeoJson overlay (polygons) from outside of L.
's realm, but I don't seem to be able to access objects created by L.
.
互動包括:
- getBounds(myFeature)
- fitBounds(myFeature)
- 設(shè)置樣式等等
我可以看到 Leaflet 暴露了 L.GeoJSON.getFeature(),但我似乎無法從中擠出任何東西.沒有文檔,檢查員似乎建議它不接受參數(shù)...:
I can see Leaflet exposing L.GeoJSON.getFeature(), but I don't seem to be able to squeeze anything out of it. No documentation, and the inspector seems to suggest it does not take arguments... :
這只是為了未來的發(fā)展嗎?
Is this just there for future development?
推薦答案
您可以使用 getLayer 通過其 id 獲取該功能.
http://leafletjs.com/reference.html#layergroup-getlayer
You may use getLayer to get the feature by its id.
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);
這篇關(guān)于從外部訪問 Leaflet.js GeoJson 功能的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!