A Leaflet control to display the coordinates of the map center, especially useful on touch/mobile devices.
The initial idea was based on the plugin Leaflet.MousePosition.
Leaflet v7.x
Tested ok on Leaflet 1.0 beta2
Android 4.4.2: Google Chrome 47 and stock browser
iOS 9.2: Safari
Desktops: Windows 7, Windows 10, Ubuntu 14.04 LTS
Google Chrome 47, Firefox 43, Microsoft Internet Explorer 10, 11 and Edge 25
http://xguaita.github.io/Leaflet.MapCenterCoord/
Sources in /examples folder
-
Download latest release
- Source code in
/src
folder - Minified versions in
/dist
- Source code in
-
Include js and css files located in the
/dist
folder (production) or/src
(development) -
If you want to change the code and build minified versions:
First, install node.js on your system. Then runnpm install
to build the minified js and css into/dist
Add the following line to your map initialization:
L.control.mapCenterCoord().addTo(map);
You can also pass a configuration.
The MapCenterCoord control inherits options from Leaflet Controls.
Option | Type | Default | Description |
---|---|---|---|
position | String | 'bottomleft' |
The standard Leaflet.Control position parameter |
icon | Boolean | true |
Shows crosshair icon on map center |
onMove | Boolean | false |
Update the coordinates of the map center while dragging |
template | String | '{y} | {x}' |
Display template |
latlngFormat | String | 'DD' |
Show lat/lng coordinates in 3 possible formats: Decimal degrees 'DD' (DDD.DDDDD°)Degrees and decimal minutes 'DM' (DDD° MM.MMM')Degrees, minutes and seconds 'DMS' (DDD° MM' SS.S") |
latlngDesignators | Boolean | false |
Show N-S and E-W |
projected | Boolean | false |
Show projected coordinates |
formatProjected | String | '#.##0,0' |
Number format mask for projected coordinates. JavaScript Number Formatter project: sample/help page |
latLngFormatter | Function | undefined |
Function that takes the lattitude and longitude as arguments and returns a single formatted string, e.g.function (lat, lng) { |
This software is released under the MIT license.