[英]How to send only the modified geometry in OpenLayers 5?
In my map there is multiple parcel which is display, the user cand modify the geometry of the parcel and send it to my API to update the geometry in my database. 在我的地图中,显示了多个宗地,用户可以修改宗地的几何并将其发送到我的API以更新数据库中的几何。 If I select a parcel I want to modify the geometry of, the application will also modify the geometry of all the other parcels that I could have clicked on beforehand. 如果我选择了要修改其几何形状的宗地,则应用程序还将修改我本可以单击的所有其他宗地的几何。 It's like it's keeping in memory everything I selected prior to the parcel that I'm really interested into. 就像将我真正感兴趣的包裹之前选择的所有内容都保留在内存中一样。
the code when i recover the geometry after the modification and before send it to my API : 在修改后并且将其发送到我的API之前恢复几何时的代码:
map.on("click", function (evt) {
map.forEachFeatureAtPixel(evt.pixel, function (feature, layer) {
modify.on('modifyend',function(event) {
var geom = feature.getGeometry().getCoordinates();
var wkt = new ol.format.WKT().writeGeometry(new ol.geom.MultiPolygon(geom));
})
})
})
This is what a parcel looks like : 这是一个包裹的外观:
My question is : How can I modify the geometry of the last parcel I selected (which is the one I'm interested in) without modifying every other one? 我的问题是:如何在不修改其他所有包裹的情况下修改我选择的最后一个包裹的几何形状(这是我感兴趣的包裹)?
You only need to set up a single modifyend
listener, the feature which has been modified can be obtained from the event, also there's no need to create a new geometry from the coordinates of the old one, it will be the same (unless you want to convert a polygon to multipolygon, but that would need extra [ ]
) 您只需要设置一个单独的modifyend
侦听器,就可以从事件中获取已修改的功能,也不需要从旧对象的坐标创建新的几何形状,它将是相同的(除非您想要将多边形转换为多面体,但这需要额外的[ ]
)
modify.on('modifyend',function(event) {
var wkt = new ol.format.WKT().writeGeometry(event.features.getArray()[0].getGeometry());
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.