简体   繁体   English

如何仅在OpenLayers 5中发送修改后的几何图形?

[英]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.

相关问题 OpenLayers将几何渲染到画布 - OpenLayers rendering Geometry to Canvas OpenLayers-获取几何投影 - OpenLayers - Get Geometry Projection 如何通过VectorTile强制OpenLayers 3在每次缩放时使用新的几何 - How can OpenLayers 3 be forced to use new geometry on each zoom with VectorTile 如何 select 在 OpenLayers 中重叠或相同几何图形的情况下具有覆盖功能 - How to select which feature overlay in case of overlapping or same geometry in OpenLayers Openlayers中的投影和OpenLayers.Geometry.Point - Projections and OpenLayers.Geometry.Point in openlayers OpenLayers点几何永远不会调整大小 - OpenLayers Point Geometry never resizes 我如何缩放到 openlayers 中的特定几何图形,从下拉列表中选择 - how can i zoom to specific geometry in openlayers , selected from drop down 如何从JSON文件中在OpenLayers中绘制点类型几何 - How can I plot Point type geometry in OpenLayers from a JSON file 我如何在OpenLayers 3中动态更新ol.Features几何属性(坐标) - how can i dynamically update a ol.Features geometry property ( coordinates ) in OpenLayers 3 如何从 OpenLayers 中获取地图的当前视口作为几何、边界框或 wkt? - How to get the current viewport of the map out of OpenLayers as geometry, bounding box or wkt?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM