Open Layers 3: How to create listener for a modify interaction

守給你的承諾、 提交于 2019-11-30 22:28:35

I found a solution.

The high-level-explanation is here: http://boundlessgeo.com/2014/06/openlayers-editing-wfs-t/

Basically you don't listen to changes in the modify-interaction (like you do in the draw-interaction). Instead, you listen to changes in the selected features themselves.

Here's a short extract:

// get the features from the select interaction
var selected_features = select_interaction.getFeatures();
// when a feature is selected...
selected_features.on('add', function(event) {
    // get the feature
    var feature = event.element;
    // ...listen for changes on it
    feature.on('change', function(event) {
        // got it!
    });
});

Here is a complete working example: http://codepen.io/barbalex/pen/fBpyb

for this, you have to use like following :

feature.once('change', function(bool) {if (bool) {document.getElementById('my_input_text').value='feature changed'}})

you have to use 'once' instead of 'on' to avoid multiple check and use boolean variable to check if feature is changed or not.

Hope this help

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!