简体   繁体   中英

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. 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. Default is false ie single select

For OpenLayers4 this can easily be done by combining conditions.

For example a condition that only selects on singleClick and not when shiftKey is pressed:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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