让我们说我在地图集地图上绘制一个形状,并在绘图:crated事件上执行此操作:
e.layer.properties = {};
e.layer.properties.myId = 'This is myId';
Run Code Online (Sandbox Code Playgroud)
如果我这样做featureGroup.toGeoJSON(),geojson功能有一个空的属性对象.有没有什么方法我配置一个传单层,以便当它转换为geoJson时,它将设置某些属性?
ghy*_*ybs 12
实际上,诀窍就是feature用它来定义图层type(必须是a "Feature")和properties(使用后者记录你需要的任何信息).
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
});
Run Code Online (Sandbox Code Playgroud)
另请参阅Leaflet Draw在将FeatureGroup转换为GeoJson时不采用属性并更新geojson的属性以将其与传单一起使用