2015-04-19 78 views
8

可以說,我畫一個mapbox地圖上的形狀,而做到這一點的平局:裝箱事件:添加屬性的瓣葉層,將成爲GeoJSON的選項

如果我做了featureGroup.toGeoJSON()的GeoJSON的特點有一個空的屬性對象。有沒有什麼方法可以配置一個傳單層,以便當它轉換爲geoJson時,它會設置某些屬性?

回答

1

您可以修改傳單來源或編寫自己的函數來處理圖層並設置要查找的屬性。

6

其實,問題是把與它的type(必須是"Feature")和properties定義層feature(用後者來記錄你需要的任何信息)。

map.on('draw:created', function (event) { 
    var layer = event.layer, 
     feature = layer.feature = layer.feature || {}; // Initialize feature 

    feature.type = feature.type || "Feature"; // Initialize feature.type 
    var props = feature.properties = feature.properties || {}; // Initialize feature.properties 
    props.myId = 'This is myId'; 
    drawnItems.addLayer(layer); // whatever you want to do with the created layer 
}); 

又見Leaflet Draw not taking properties when converting FeatureGroup to GeoJsonupdate properties of geojson to use it with leaflet

相關問題