leaflet-fullHash
leaflet-fullHash copied to clipboard
Ready for Leaflet 1?
In Leaflet 1 probably do not works :(. URLs with hash tags exist, but link heads to default zoom.
Has anyone looked into this, or an alternate solution?
As far as I could see, the update method is not called until after onMapMove, which overwrites the hash before it is being parsed for the first time. However, If I add some checks around this, it still only removes unselected layers from the default, but does not add the ones from my hash.
That is, I managed to get the positioning and layer selection working with the following code.
https://gist.github.com/relet/6b73fccc6cb2636f1e60c6a5ddc6bf1b
What is missing still seems to be some sort of refresh on the map object. In my tests, when I load the map from a URL with hash:
- the background layer is correctly set, and the map moved to the correct position.
- background and overlays are correctly ticked off in the layer selector
- overlays are not displayed until a refresh, e.g. if the map window is resized
What is confusing me is that the entire vector (geojson) overlay system seems to be disabled until I resize the viewport (either by resizing the window, or opening the debug console). None of the geojson layers appear when I pan or zoom, not even when I select other layers in the layer selector.
Any update on this one? I need it badly.
Works fine for me on Leaflet 1.3.3
I can confirm, with the latest stable version of leaflet, the viewport issue has disappeared.