简体   繁体   English

OpenLayers 3禁用多选

[英]OpenLayers 3 Disable Multi-Select

有没有办法在OpenLayers 3中使用selectInteraction ,只允许一次选择一个功能?

define select interaction as follow : 定义选择交互如下

select = new ol.interaction.Select (
    toggleCondition: ol.events.condition.never
)

Not really sure I understood well. 不太确定我理解得很好。

If you go to the API doc for OpenLayers 3.4 and untick Stable Only on the page top right, you will see a multi option to manage this. 如果您转到OpenLayers 3.4的API文档并在右上角的页面上取消选中Stable Only ,您将看到一个multi选项来管理它。 Normally, according to the doc, what you are asking is already by default. 通常,根据文档,您要求的是默认情况。

Multi A boolean that determines if the default behaviour should select only single features or all (overlapping) features at the clicked map position. Multi一个布尔值,用于确定默认行为是否应仅在单击的地图位置选择单个要素或所有(重叠)要素。 Default is false ie single select 默认值为false,即单选

For OpenLayers4 this can easily be done by combining conditions. 对于OpenLayers4,可以通过组合条件轻松完成。

For example a condition that only selects on singleClick and not when shiftKey is pressed: 例如,仅在按下shiftKey时才选择的条件,而不是按下shiftKey时:

const select = new Select({
  condition: (mapBrowserEvent) => {
    return singleClick(mapBrowserEvent) && !shiftKeyOnly(mapBrowserEvent)},
  layers: [layer]
});

Find more conditions in the API doc: http://openlayers.org/en/latest/apidoc/module-ol_events_condition.html 在API文档中查找更多条件: http//openlayers.org/en/latest/apidoc/module-ol_events_condition.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM