作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想添加一个双击事件来删除一个特征。尽管此代码运行良好,但存在一个问题: map 无法刷新,该 map 项仍在 map 中,直到我双击下一步。我该怎么办?
_createDoubleSelectControl: function() {
var selectedStyle = [
new OpenLayers.style.Style({
stroke: new OpenLayers.style.Stroke({
color: '#3399CC',
width: 1.25
})
})
];
this.doubleClickSelector = new OpenLayers.interaction.Select({
condition: OpenLayers.events.condition.doubleClick,
style: selectedStyle,
multi: true,
layers: [this.layers.cellLayer],
filter: function(feature, layer) {
return layer === this.layers.cellLayer;
}.bind(this)
});
this.map.addInteraction(this.doubleClickSelector);
this.doubleClickSelector.on('select', function(event) {
let features = event.target.getFeatures();
features.forEach(function(feature) {
this._cellLayer.getSource().removeFeature(feature);
//this._cellLayer.refresh();
this._cellLayer.refresh({
force: true,
active: true
});
this.map.removeLayer(this._cellLayer);
this.map.addLayer(this._cellLayer);
}.bind(this));
}.bind(this));
},
最佳答案
您必须在选择时从选择中删除该特征:
this.doubleClickSelector.on('select',function(event){
let features =event.target.getFeatures();
// Clear selection
this.doubleClickSelector.getFeatures().clear();
// Remove from layer
features.forEach(function(feature){
this._cellLayer.getSource().removeFeature(feature);
}.bind(this));
}.bind(this));
否则该特征仍处于选中状态并且可见...
关于javascript - openlayer4 : how to delete a feature in a layer and refresh the map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50343358/
我是一名优秀的程序员,十分优秀!