javascript - OpenLayers 3 Draw Interaction onFeature 添加事件

标签 javascript openlayers-3

在 OL2 中我能够执行以下操作:

var drawControl = new ol.Control.DrawFeature(
    myLayer,
    ol.Handler.RegularPolygon, {
        handlerOptions: {
            sides: 4,
            irregular: true
        },
        eventListeners: {
            featureadded: function( e ) {
                // process features
            }
        }
    }
);

有没有办法访问 OL3 中添加的功能?我想做的是在绘制特征后对其进行投影。理想情况下,如果可能的话,我会在绘制它们之前对其进行投影。

最佳答案

// draw is an instance of ol.interaction.Draw
// when draw ended but the feature was not added yet to ol.source.Vector
draw.on('drawend', function(evt){
  console.info(evt.feature);
});

// vectorSource is an instance of ol.source.Vector
// added to source
vectorSource.on('addfeature', function(evt) {
    console.info(evt.feature);
});

关于javascript - OpenLayers 3 Draw Interaction onFeature 添加事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37923155/

相关文章:

javascript - 从 testcafe 中打开的第 N 个模态中选择确定按钮

javascript - 如何使用 Twitter Bootstrap 设置下拉子菜单

javascript - 到达 scrollspy 部分的末尾时强制停止滚动

javascript - Openlayers 访问低级 WebGL 着色器

openlayers-3 - 无法为矢量图层中单击的要素设置样式

google-maps - 打开第 3 层搜索功能以查找 map 位置?

javascript - 如何正确设置 brain.js 神经网络

javascript - 我不明白以下javascript代码:的意义

mouseevent - 右键单击Openlayer 3

javascript - 在指定图层的 pointermove 上更改光标样式