gpt4 book ai didi

javascript - openlayer4 : how to delete a feature in a layer and refresh the map

转载 作者:行者123 更新时间:2023-11-30 20:30:55 27 4
gpt4 key购买 nike

我想添加一个双击事件来删除一个特征。尽管此代码运行良好,但存在一个问题: 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com