我正在使用Openlayers范围交互来允许用户选择AOI。在用户执行此操作并删除绘制的范围后,我希望蓝点也消失。目前它只是挂在地图上,然后再次按下交互键后弹回鼠标。
可以在Openlayers范围交互示例here中看到此行为。 Shift +拖动开始范围交互。 Shift +单击删除范围,但蓝色点保留在那里。有没有办法删除这个?一旦移除范围,蓝点就没有其他可能的交互,那么它的目的是什么呢?
答案 0 :(得分:1)
如果您查看了ol.interaction.Extent
您可以将样式传递给pointerStyle
以更新点的样式。
var extent = new ol.interaction.Extent({
condition: ol.events.condition.platformModifierKeyOnly,
pointerStyle: [] // <-- Makes the dot invisible
});
var vectorSource = new ol.source.Vector({
url: 'https://openlayers.org/en/v3.20.1/examples/data/geojson/countries.geojson',
format: new ol.format.GeoJSON()
});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
new ol.layer.Vector({
source: vectorSource
})
],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
var extent = new ol.interaction.Extent({
condition: ol.events.condition.platformModifierKeyOnly,
pointerStyle: []
});
map.addInteraction(extent);
extent.setActive(false);
//Enable interaction by holding shift
this.addEventListener('keydown', function(event) {
if (event.keyCode == 16) {
extent.setActive(true);
}
});
this.addEventListener('keyup', function(event) {
if (event.keyCode == 16) {
extent.setActive(false);
}
});
&#13;
<link href="https://openlayers.org/en/v3.20.1/css/ol.css" rel="stylesheet" />
<script src="https://openlayers.org/en/v3.20.1/build/ol.js"></script>
<div id="map" class="map"></div>
&#13;