小编Bil*_*ill的帖子

绘图后将样式附加到要素

ol.Interaction.Draw用来在地图上绘制多边形.我希望在绘制后为各个特征设置样式.

当我检测到一个DRAWEND事件时,我尝试将一个样式附加到最后绘制的特征,但是只有一般的图层样式出现在屏幕上,虽然我在通过调试器搜索特征本身时看到它.

map.addInteraction( drawInter = new ol.interaction.Draw({           
                features: drawLayer.getFeatures(),                      
                type: "Polygon" 
                })                                                  
            );

drawInter.on('drawend', function(e) {                           
    var style = new ol.style.Style({                                    
        fill: new ol.style.Fill({ color: newColor })
        });

    var features = drawLayer.getFeatures().getArray();                  
    var last = features.length-1;
    features[last].setStyle(style); 
});
Run Code Online (Sandbox Code Playgroud)

openlayers-3

3
推荐指数
1
解决办法
4702
查看次数

标签 统计

openlayers-3 ×1