ol/interaction/Select.js
父类
ol/interaction/Interaction-Interaction
主要功能
交互选择矢量要素。
被选中的要素样式会改变。
有三种方式选择要素:
1.使用浏览器condition定义的事件和可选的toggle,add/remove,和multi选项。
2.通过一个layer选择器 。
3.使用filter选项通过feature选择器。
参数:Select({})
参数 | 类型 | 说明 |
---|---|---|
layers | Array.module:ol/layer/Layer~Layer function |
能被选择的图层的列表。 或者一个选择器函数,以图层作为参数,返回true以选择该图层。若layers缺省则所有图层都可被选择。 |
方法
函数名 | 参数 | 源码 | 返回值类型 | 功能 |
---|---|---|---|---|
setDistance(distance) | distance number 像素距离 | source/Cluster.js, line 169 | 无 | 设定聚类像素距离 |
/**
* @module ol/interaction/Select
*/
import Collection from '../Collection.js';
import CollectionEventType from '../CollectionEventType.js';
import Event from '../events/Event.js';
import GeometryType from '../geom/GeometryType.js';
import Interaction from './Interaction.js';
import {
TRUE} from '../functions.js';
import {
clear} from '../obj.js';
import {
createEditingStyle} from '../style/Style.js';
import {
extend, includes} from '../array.js';
import {
getUid} from '../util.js';
import {
never, shiftKeyOnly, singleClick} from '../events/condition.js';
/**
* @enum {string}
*/
const SelectEventType = {
/**
* Triggered when feature(s) has been (de)selected.
* @event SelectEvent#select
* @api
*/
SELECT: 'select',
};
/**
* A function that takes an {@link module:ol/Feature} or
* {@link module:ol/render/Feature} and an
* {@link module:ol/layer/Layer} and returns `true` if the feature may be
* selected or `false` otherwise.
* @typedef {function(import("../Feature.js").FeatureLike, import("../layer/Layer.js").default<import("../source/Source").default>):boolean} FilterFunction
*/
/**
* @typedef {Object} Options
* @property {import("../events/condition.js").Condition} [addCondition] A function
* that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
* boolean to indicate whether that event should be handled.
* By default, this is {@link module:ol/events/condition.never}. Use this if you
* want to use different events for add and remove instead of `toggle`.
* @property {import("../events/condition.js").Condition} [condition] A function that
* takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
* boolean to indicate whether that event should be handled. This is the event
* for the selected features as a whole. By default, this is
* {@link module:ol/events/condition.singleClick}. Clicking on a feature selects that
* feature and removes any that were in the selection. Clicking outside any
* feature removes all from the selection.
* See `toggle`, `add`, `remove` options for adding/removing extra features to/
* from the selection.
* @property {Array<import("../layer/Layer.js").default>|function(import("../layer/Layer.js").default<import("../source/Source").default>): boolean} [layers]
* A list of layers from which features should be selected. Alternatively, a
* filter function can be provided. The function will be called for each layer
* in the map and should return `true` for layers that you want to be
* selectable. If the option is absent, all visible layers will be considered
* selectable.
* @property {import("../style/Style.js").StyleLike|null} [style]
* Style for the selected features. By default the default edit style is used
* (see {@link module:ol/style}). Set to `null` if this interaction should not apply
* any style changes for selected features.
* If set to a falsey value, the selected feature's style will not change.
* @property {import("../events/condition.js").Condition} [removeCondition] A function
* that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
* boolean to indicate whether that event should be handled.
* By default, this is {@link module:ol/events/condition.never}. Use this if you
* want to use different events for add and remove instead of `toggle`.
* @property {import("../events/condition.js").Condition} [toggleCondition] A function
* that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
* boolean to indicate whether that event should be handled. This is in addition
* to the `condition` event. By default,
* {@link module:ol/events/condition.shiftKeyOnly}, i.e. pressing `shift` as
* well as the `condition` event, adds that feature to the current selection if
* it is not currently selected, and removes it if it is. See `add` and `remove`
* if you want to use different events instead of a toggle.
* @property {boolean} [multi=false] A boolean that determines if the default
* behaviour should select only single features or all (overlapping) features at
* the clicked map position. The default of `false` means single select.
* @property {import("../Collection.js").default<import("../Feature.js").default>} [features]
* Collection where the interaction will place selected features. Optional. If
* not set the interaction will create a collection. In any case the collection
* used by the interaction is returned by
* {@link module:ol/interaction/Select~Select#getFeatures}.
* @property {FilterFunction} [filter] A function
* that takes an {@link module:ol/Feature} and an
* {@link module:ol/layer/Layer} and returns `true` if the feature may be
* selected or `false` otherwise.
* @property {number} [hitTolerance=0] Hit-detection tolerance. Pixels inside
* the radius around the given position will be checked for features.
*/
/**
* @classdesc
* Events emitted by {@link module:ol/interaction/Select~Select} instances are instances of
* this type.
*/
export class SelectEvent extends Event {
/**
* @param {SelectEventType} type The event type.
* @param {Array<import("../Feature.js").default>} selected Selected features.
* @param {Array<import("../Feature.js").default>} deselected Deselected features.
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Associated
* {@link module:ol/MapBrowserEvent}.
*/
constructor(type, selected, deselected, mapBrowserEvent) {
super(type);
/**
* Selected features array.
* @type {Array<import("../Feature.js").default>}
* @api
*/
this.selected = selected;
/**
* Deselected features array.
* @type {Array<import("../Feature.js").default>}
* @api
*/
this.deselected = deselected;
/**
* Associated {@link module:ol/MapBrowserEvent}.
* @type {import("../MapBrowserEvent.js").default}
* @api
*/
this.mapBrowserEvent = mapBrowserEvent;
}
}
/**
* Original feature styles to reset to when features are no longer selected.
* @type {Object<number, import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction>}
*/
const originalFeatureStyles = {
};
/***
* @template Return
* @typedef {import("../Observable").OnSignature<import("../Observable").EventTypes, import("../events/Event.js").default, Return> &
* import("../Observable").OnSignature<import("../ObjectEventType").Types|
* 'change:active', import("../Object").ObjectEvent, Return> &
* import("../Observable").OnSignature<'select', SelectEvent, Return> &
* import("../Observable").CombinedOnSignature<import("../Observable").EventTypes|import("../ObjectEventType").Types|
* 'change:active'|'select', Return>} SelectOnSignature
*/
/**
* @classdesc
* Interaction for selecting vector features. By default, selected features are
* styled differently, so this interaction can be used for visual highlighting,
* as well as selecting features for other actions, such as modification or
* output. There are three ways of controlling which