Plugin for Leaflet adding a basic URL hash (fragment identifier) interface to L.Map.
Panning and/or zooming the map results in a hash transparently formatted as #lng=<lng>;lat=<lat>;zoom=<zoom>. And vice versa, altering the hash allows (re)setting the map view; recognized parameters (separated by either ; or &) are:
lng(orlon) andlatas a pair of geographical coordinates orxandyas a pair of cartesian coordinates (dependent on CRS) and- optional
zoom
Tested with Leaflet 1.7.0. Caution: versions 1.7.1 and 1.8.0 have an issue that affects the URL hash.
Demo: https://kluizeberg.github.io/Leaflet.Map-hash/demo.html#lng=-5.71496;lat=50.06582;zoom=10 (map centered on Land's End).
- load
leaflet.js - load
leaflet.map-hash.js - create a
L.Mapinstance with optionurlHashset totrue.
See also demo.html. Linking several maps in one document to the hash may result in unexpected behaviour.
This plugin alters, albeit slightly, Leaflet's main class L.Map and adds a utility function to the L namespace.
L.Map additions:
| Option | Type | Default | Description |
|---|---|---|---|
urlHash |
Boolean |
false |
Set to true to enable URL hash interaction. |
| Function | Returns | Description |
|---|---|---|
parseParamString(<String> str, <Object> result?) |
Object |
Inverse of L.Util.getParamString, parameters to be separated by ; or &. |