我想添加双击事件来删除功能。尽管此代码运行良好,但仍存在一个问题:地图无法刷新,此功能仍在地图中,直到我双击下一步。我该怎么办?
_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));
},
答案 0 :(得分:1)
您必须从选择中删除选项中的功能:
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));
否则该功能仍处于选中且可见...