admin管理员组文章数量:1313121
I want to retrieve polygon data from a database, then edit it. I can retrieve the polygons (stored as geojson), but cannot make them editable. How can I do this?
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
edit: {
featureGroup: drawnItems
}
});
map.addControl(drawControl);
map.on('draw:created',function(e) {
e.layer.addTo(drawnItems);
});
L.control.layers(baseLayers).addTo(map);
var oldPolygon = null;
function showOnMap(rowid){
if(oldPolygon != null){
map.removeLayer(oldPolygon);
}
$.get("testdbextract.php?show="+rowid,function(data){
var newPolygon = L.geoJson(data);
newPolygon.addTo(drawnItems); // or drawnItems.addLayer(newPolygon);
oldPolygon = newPolygon;
});
}
I want to retrieve polygon data from a database, then edit it. I can retrieve the polygons (stored as geojson), but cannot make them editable. How can I do this?
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
edit: {
featureGroup: drawnItems
}
});
map.addControl(drawControl);
map.on('draw:created',function(e) {
e.layer.addTo(drawnItems);
});
L.control.layers(baseLayers).addTo(map);
var oldPolygon = null;
function showOnMap(rowid){
if(oldPolygon != null){
map.removeLayer(oldPolygon);
}
$.get("testdbextract.php?show="+rowid,function(data){
var newPolygon = L.geoJson(data);
newPolygon.addTo(drawnItems); // or drawnItems.addLayer(newPolygon);
oldPolygon = newPolygon;
});
}
Share
Improve this question
edited Mar 6, 2019 at 20:48
meetar
7,6118 gold badges43 silver badges74 bronze badges
asked May 21, 2016 at 12:07
BehattedBehatted
331 silver badge5 bronze badges
1 Answer
Reset to default 9In your example, you need to parse the geojson data you receive, create layers and initialize drawnItems
To make it easier you can create a GeoJson layer like this:
// Create a GeoJson layer without adding it to the map
L.geoJson(geojsonFeatures, {
onEachFeature: onEachFeature
});
// Take advantage of the onEachFeature callback to initialize drawnItems
function onEachFeature(feature, layer) {
drawnItems.addLayer(layer);
}
Here is an example
In your code, it could be used like that
$.get("testdbextract.php?show="+rowid,function(data){
L.geoJson(data, {
onEachFeature: onEachFeature
});
});
本文标签: javascriptHow to edit loaded geoJson with LeafletStack Overflow
版权声明:本文标题:javascript - How to edit loaded geoJson with Leaflet - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741877881a2402571.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论