Class: MousePosition

ol/control/MousePosition~MousePosition


import MousePosition from 'ol/control/MousePosition.js';

显示鼠标光标二维坐标的控件。默认情况下,使用视图投影,但也可以使用任何支持的投影。默认情况下,控件显示在地图的右上角,但可以使用 CSS 选择器 .ol-mouse-position 进行更改。

在通常没有鼠标光标的触摸设备上,将显示当前触摸位置的坐标。

new MousePosition(options)

Name Type Description
className string (defaults to 'ol-mouse-position')

CSS 类名。

coordinateFormat CoordinateFormat | undefined

坐标格式。

projection ProjectionLike | undefined

投影。默认为视图投影。

render function | undefined

控件需要重新渲染时调用的函数。此函数在 requestAnimationFrame 回调中调用。

target HTMLElement | string | undefined

如果希望控件在地图视口之外渲染,请指定目标。

placeholder string | undefined

当鼠标位置不可用时显示的标记(例如当指针离开地图视口时)。 默认情况下,初始渲染一个不间断空格,当鼠标离开视口时保留最后的位置。 当提供字符串时(例如 'no position''' 表示空字符串),它将作为占位符使用。

wrapX boolean (defaults to true)

如果是全球投影,在投影的对跖经线上水平环绕世界。

触发事件:

Extends

Observable Properties

Name Type Settable ObjectEvent type Description
coordinateFormat CoordinateFormat | undefined yes change:coordinateformat

渲染当前位置所使用的格式。

projection Projection | undefined yes change:projection

报告鼠标位置时使用的投影。

Methods

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

dispatchEvent(event){boolean | undefined} inherited

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

Name Type Description
event BaseEvent | string

事件对象。

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

获取一个值。

Name Type Description
key string

键名。

返回值:
值。

getCoordinateFormat(){CoordinateFormat | undefined}

返回用于渲染当前位置的坐标格式类型,如果未定义则返回 undefined。

返回值:
The format to render the current position in.

getKeys(){Array.<string>} inherited

获取对象属性名列表。

返回值:
属性名列表。

获取与此控件关联的地图。

返回值:
地图。

getProjection(){Projection | undefined}

返回用于报告鼠标位置的投影。

返回值:
报告鼠标位置时使用的投影。

getProperties(){NoInfer.<Properties>} inherited

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

返回值:
对象。

getRevision(){number} inherited

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

返回值:
版本号。

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

更新但不触发事件。

setCoordinateFormat(format)

设置用于渲染当前位置的坐标格式类型。

Name Type Description
format CoordinateFormat

渲染当前位置所使用的格式。

从当前地图移除控件并将其附加到新地图。 传入 null 仅从当前地图移除控件。 子类可以在此设置事件处理程序以获取地图更改的通知。

Name Type Description
map Map | null

地图。

setProjection(projection)

设置用于报告鼠标位置的投影。

Name Type Description
projection ProjectionLike

报告鼠标位置时使用的投影。

setProperties(values, silent) inherited

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

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

值。

silent boolean | undefined

更新但不触发事件。

此函数用于设置控件的目标元素。如果在控件添加到地图之后调用(即在控件上调用了 setMap 之后),则不会产生任何效果。如果在传递给控件构造函数的选项中没有设置 target,并且也没有调用 setTarget,则控件将被添加到地图的叠加容器中。

Name Type Description
target HTMLElement | string

目标。

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

取消设置但不触发事件。