@giapspzoo/use-map-cursor-coords
v1.0.0
Published
A React hook to retrieve the current cursor coordinates from an OpenLayers map.
Downloads
48
Readme
@giapspzoo/use-map-cursor-coords
A React hook to retrieve the current cursor coordinates from an OpenLayers map.
Installation
npm i @giapspzoo/use-map-cursor-coordsAPI
useMapCursorCoords(map, options?) => [string, string];
Parameters
| Name | Type | Description | Default value | Required |
|-|-|-|-|-|
| map | Map | A reference to an OpenLayers map instance. | - | Yes |
| options | TUseMapCursorCoordsOptions | Configuration object. | {} | No |
| options.coordinateRoundValue | number | Number of decimal places of coordinate values. | 5 | No |
| options.resultCrs | ProjectionLike | Result coordinate system. Accepts the ProjectionLike type from OpenLayers. | "EPSG:4326" | No |
Examples
import useMapCursorCoords from '@giapspzoo/use-map-cursor-coords';
// ...
const cursorCoords = useMapCursorCoords(map);
// Result: coords e.g. ['19.47999', '52.06485'] (or `null` if map is not defined)
const cursorCoords = useMapCursorCoords(map, {
coordinateRoundValue: 2
});
// Result: coords e.g. ['19.47', '52.06'] (or `null` if map is not defined)
const cursorCoords = useMapCursorCoords(map, {
resultCrs: 'EPSG:3857'
});
// Result: coords e.g. ['2168502.567458', '6811859.670340'] (or `null` if map is not defined)