source: binary-improvements/webserver/js/leaflet.control.coordinates.js@ 416

Last change on this file since 416 was 364, checked in by alloc, 3 years ago

Fixed: Coordinates display

File size: 1.3 KB
Line 
1L.Control.Coordinates = L.Control.extend({
2 options: {
3 position: 'bottomleft'
4 },
5
6 onAdd: function (map) {
7 var name = 'control-coordinates',
8 container = L.DomUtil.create('div', name + ' webmap-control');
9
10 container.innerHTML = "Mouse pos: - E / - N<br/>Last click: - E / - N"
11 L.DomEvent.on (container, 'mousemove', L.DomEvent.stopPropagation);
12
13 this._map = map;
14 this._div = container;
15
16 map.on('mousemove', this._onMouseMove, this);
17 map.on('mouseout', this._onMouseOut, this);
18 map.on('click', this._onClick, this);
19
20 return container;
21 },
22
23 onRemove: function (map) {
24 },
25
26 _onMouseMove: function (e) {
27 this.lastPos = e.latlng;
28 this._updateText ();
29 },
30
31 _onMouseOut: function (e) {
32 this.lastPos = false;
33 this._updateText ();
34 },
35
36 _onClick: function (e) {
37 this.lastClick = e.latlng;
38 this._updateText ();
39 },
40
41 _updateText: function (e) {
42 this._div.innerHTML = "Mouse pos: " + this._formatCoord(this.lastPos) + "<br/>" +
43 "Last click: " + this._formatCoord(this.lastClick);
44 },
45
46 _formatCoord: function(latlng) {
47 if (latlng == false)
48 return "- E / - N";
49 else
50 return "" +
51 Math.abs(latlng.lat).toFixed(0) + (latlng.lat>=0 ? " E" : " W") + " / " +
52 Math.abs(latlng.lng).toFixed(0) + (latlng.lng>=0 ? " N" : " S");
53 },
54
55 lastPos: false,
56 lastClick: false
57
58});
59
Note: See TracBrowser for help on using the repository browser.