我无法使用Leaflet(0.7.7)/Leaflet.Draw(最新)将我的Layer属性转换为GEOJson对象的属性.我的工作流程是:
1创建地图: var map = L.map('#map', options);
2创建FeatureGroup: features= new L.FeatureGroup();
3添加到宣传单地图: map.addLayer(features);
4在draw:created活动中,我正在捕捉e.layer并添加一堆属性:
var layer = e.layer;
layer.properties = { Title: 'Hello' };
features.addLayer(layer);
geo_features = features.toGeoJSON();
但是,我geo_features在每个功能中总是有空属性属性,我无法弄明白!
我需要使用leaflet.js将地图添加到我的网站。该站点具有一个管理视图,管理员可以在其中添加标记,并向每个标记添加描述和图像。
我使用了leaflet.draw插件,并在创建事件上尝试更新event.layer.toGeoJSON()用来添加一些属性(例如图像和文本)的GeoJSON对象,但是没有运气。
谁可以帮我这个事?
var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
osm = L.tileLayer(osmUrl, {
maxZoom: 18,
attribution: osmAttrib
});
map = new L.Map('map', {
layers: [osm],
center: new L.LatLng(31.9500, 35.9333),
zoom: 15
}),
drawnItems = L.geoJson().addTo(map);
map.addControl(new L.Control.Draw({
edit: {
featureGroup: drawnItems
}
}));
map.on('draw:created', function(event) {
var layer = event.layer;
var json = event.layer.toGeoJSON();
json.properties.desc = null;
json.properties.image = null;
drawnItems.addLayer(L.GeoJSON.geometryToLayer(json));
addPopup(layer);
});
function addPopup(layer) {
var content = '<input id="markerDesc" type="text"/ onblur="saveData(layer);">';
layer.bindPopup(content).openPopup(); …Run Code Online (Sandbox Code Playgroud)