-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
38 lines (29 loc) · 856 Bytes
/
index.js
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
import * as maptalks from 'maptalks';
const options = {
position: {bottom: 0, right: 0},
precision: 5,
style: {
padding: '0 5px',
backgroundColor: 'rgba(255,255,255,0.7)',
fontSize: '13px'
}
}
export class MouseCoordinate extends maptalks.control.Control {
buildOn(map) {
const dom = document.createElement('div')
Object.assign(dom.style, this.options.style)
return dom;
}
onAdd() {
this._map.on('mousemove', this.onMouseMove, this)
}
onMouseMove(event) {
const {x, y} = event.coordinate,
precision = this.options.precision
this._controlDom.innerText = x.toFixed(precision) + " : " + y.toFixed(precision)
}
onRemove() {
this._map.off('mouseover', this.onMouseOver)
}
}
MouseCoordinate.mergeOptions(options);