-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
RMousePosition.tsx
48 lines (43 loc) · 1.39 KB
/
RMousePosition.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {default as OLMousePosition, Options} from 'ol/control/MousePosition';
import {Coordinate} from 'ol/coordinate';
import {ProjectionLike} from 'ol/proj';
import {RContextType} from '../context';
import RControlBase, {RControlProps} from './RControlBase';
/**
* @propsfor RMousePosition
*/
export interface RMousePositionProps extends RControlProps {
/**
* Optional function to change coordinate formatting
*/
coordinateFormat?: (coordinate: Coordinate) => string;
/**
* View projection
* @default Map View's projection
*/
projection?: ProjectionLike;
/**
* Markup to show when the mouse position is unavailable.
* Set to false to retain the last position when the mouse leaves the viewport.
* @default
*/
placeholder?: string;
}
export default class RMousePosition extends RControlBase<
RMousePositionProps,
Record<string, never>
> {
ol: OLMousePosition;
constructor(props: Readonly<RMousePositionProps>, context?: React.Context<RContextType>) {
super(props, context);
this.ol = new OLMousePosition(this.toOLProps(props));
}
toOLProps(props: RMousePositionProps): Options {
return {
...super.toOLProps(props),
coordinateFormat: props.coordinateFormat,
projection: props.projection,
placeholder: props.placeholder || ' '
};
}
}