Class: MousePosition

ol/control/MousePosition~MousePosition


import MousePosition from 'ol/control/MousePosition';

A control to show the 2D coordinates of the mouse cursor. By default, these are in the view projection, but can be in any supported projection. By default the control is shown in the top right corner of the map, but this can be changed by using the css selector .ol-mouse-position.

new MousePosition(opt_options)

control/MousePosition.js, line 49
Name Type Description
options

Mouse position options.

Name Type Default Description
className string 'ol-mouse-position'

CSS class name.

coordinateFormat module:ol/coordinate~CoordinateFormat

Coordinate format.

projection module:ol/proj~ProjectionLike

Projection.

render function

Function called when the control should be re-rendered. This is called in a requestAnimationFrame callback.

target Element | string

Specify a target if you want the control to be rendered outside of the map's viewport.

undefinedHTML string ' '

Markup to show when coordinates are not available (e.g. when the pointer leaves the map viewport). By default, the last position will be replaced with ' ' when the pointer leaves the viewport. To retain the last rendered position, set this option to something falsey (like an empty string '').

Methods

getCoordinateFormat(){module:ol/coordinate~CoordinateFormat|undefined}

control/MousePosition.js, line 131

Return the coordinate format type used to render the current position or undefined.

Returns:
The format to render the current position in.

getProjection(){module:ol/proj/Projection~Projection|undefined}

control/MousePosition.js, line 144

Return the projection that is used to report the mouse position.

Returns:
The projection to report mouse position in.

setCoordinateFormat(format)

control/MousePosition.js, line 195

Set the coordinate format type used to render the current position.

Name Type Description
format module:ol/coordinate~CoordinateFormat

The format to render the current position in.

setMap()

control/MousePosition.js, line 173

setProjection(projection)

control/MousePosition.js, line 206

Set the projection that is used to report the mouse position.

Name Type Description
projection module:ol/proj~ProjectionLike

The projection to report mouse position in.