在openlayers 3上,如何在更新功能时暂停更改事件? [英] On openlayers 3, how do you pause a change event when updating features?

查看:131
本文介绍了在openlayers 3上,如何在更新功能时暂停更改事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我必须更新多个要素,特别是setGeometry,但是每次对单个要素应用更新时,都会触发change事件,从而导致重新绘制图层.因此,如果更新了500个要素,则该图层将重绘500次. 我想支付重绘事件,直到所有功能都更新.

Basically, i have to update multiple features, specifically setGeometry, but everytime an update is applied on single feature, the change event is triggered, causing the layer to be redrawn. So, if there are 500 features updated, the layer will ve redrawn 500 times. I would like to payse the redraw event, untill all features are updated.

更新: 我能想到的解决方法之一是:

Update: One of the workaround that i can think of is:

  1. getFeatures()
  2. clear(true)
  3. (更新功能)
  4. addFeatures(功能)

但是我不确定是否有比这更干净的方法

But i'm not sure if there's a cleaner way than this

推荐答案

简短答案:

var feature = layer.getFeatureById("myId");
var geometry = new ol.geom.Point(ol.proj.fromLonLat([lon, lat]));
feature.set(feature.getGeometryName(), geometry, true);
........
source.changed()

详细答案:

查看 setGeometry 源代码后( feature.js ),基本上它将在 geometryName _ 上使用 set 方法.因此,通过显式设置相同的属性并将 opt_silent 设置为true,它不会触发更改事件(

After looking at the setGeometry source code (feature.js), basically it will use the set method on geometryName_. So by explicitly setting the same property and set opt_silent to true, it will not fire the change event (object.js).

完成更改后,只需在图层上触发更改事件即可.

Once you have completed the changes, just fire the change event on the layer.

这篇关于在openlayers 3上,如何在更新功能时暂停更改事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆