Class: DragAndDrop

ol/interaction/DragAndDrop~DragAndDrop


import DragAndDrop from 'ol/interaction/DragAndDrop.js';

通过拖放处理矢量数据的输入。

new DragAndDrop(options)

Name Type Description
formatConstructors Array.<(Class.<module:ol/format/要素~要素Format>|module:ol/format/要素~要素Format)> | undefined

格式构造函数(和/或使用选项预构造的格式)。

source VectorSource | undefined

要添加要素的可选矢量数据源。如果提供了数据源,所有现有要素将被移除,新要素在拖放到目标时将被添加。如果您想向矢量数据源添加要素而不移除现有要素(仅追加),请监听 "addfeatures" 事件,而不是提供 source 选项。

projection ProjectionLike | undefined

目标投影。默认使用地图视图的投影。

target HTMLElement | undefined

用作拖放目标的元素,默认为视口元素。

触发事件:

Extends

Observable Properties

Name Type Settable ObjectEvent type Description
active boolean yes change:active

true 表示交互处于活动状态,否则为 false

Methods

增加修订计数器并分发 'change' 事件。

dispatchEvent(event){boolean | undefined} inherited

分发事件并调用所有监听此类型事件的监听器。事件参数可以是一个字符串或一个 具有 type 属性的对象。

Name Type Description
event BaseEvent | string

事件对象。

返回值:
如果有人在事件对象上调用了 preventDefault 或任何监听器返回 false,则返回 false

获取一个值。

Name Type Description
key string

键名。

返回值:
值。

返回交互当前是否激活。

返回值:
true 表示交互处于活动状态,否则为 false

getKeys(){Array.<string>} inherited

获取对象属性名列表。

返回值:
属性名列表。

获取与此交互关联的地图。

返回值:
地图。

getProperties(){NoInfer.<Properties>} inherited

获取包含所有属性名和值的对象。

返回值:
对象。

getRevision(){number} inherited

获取此对象的版本号。 每次对象被修改时,其版本号将递增。

返回值:
版本号。

handleEvent(mapBrowserEvent){boolean} inherited

Name Type Description
mapBrowserEvent MapBrowserEvent

地图浏览器事件。

返回值:
false to stop event propagation.

on(type, listener){EventsKey | Array<EventsKey>} inherited

监听特定类型的事件。

Name Type Description
type string | Array.<string>

事件类型或事件类型数组。

listener function

监听器函数。

返回值:
监听器的唯一键。如果第一个参数是事件类型数组,则返回键的数组。

once(type, listener){EventsKey | Array<EventsKey>} inherited

仅监听一次特定类型的事件。

Name Type Description
type string | Array.<string>

事件类型或事件类型数组。

listener function

监听器函数。

返回值:
监听器的唯一键。如果第一个参数是事件类型数组,则返回键的数组。

set(key, value, silent) inherited

设置一个值。

Name Type Description
key string

键名。

value *

值。

silent boolean | undefined

更新但不触发事件。

激活或停用交互。

Name Type Description
active boolean

是否激活。

setProperties(values, silent) inherited

设置一组键值对。 注意,这会更改任何现有属性并添加新属性(不会移除任何现有属性)。

Name Type Description
values Partial.<NoInfer.<Properties>>

值。

silent boolean | undefined

更新但不触发事件。

un(type, listener) inherited

取消监听特定类型的事件。

Name Type Description
type string | Array.<string>

事件类型或事件类型数组。

listener function

监听器函数。

unset(key, silent) inherited

取消设置一个属性。

Name Type Description
key string

键名。

silent boolean | undefined

取消设置但不触发事件。