OpenStreetMap

Permalinks at map.atownsend.org.uk

Posted by SomeoneElse on 4 December 2022 in English.

The problem

Historically, the map at map.atownsend.org.uk didn’t change the URL as you moved around, and you had to press a “permalink” button to save the current location. This wasn’t ideal, so I had a look around for alternatives. Helpfully, the Leaflet site has a list of suitable plugins. Of those, leaflet-hash was suggested elsewhere. That seems to be still in use, although it hasn’t been updated for a while. It is spectaculary easy to use, and “does what it does” with no problems.

The challenge is that it stores the current location (for example “https://map.atownsend.org.uk/maps/map/map.html#11/54.4900/-3.1098”) but doesn’t store the current layer. That map currently has a choice of 5 base maps (test instances have 6) and 5 overlays:

Layer selector

How to solve this

I had a look for an alternative, and the nearest that I could find was leaflet-hash-plus. The hosting of that seems not to be there at the moment, so the demo does not currently work, but the code does (if you host it yourself). It’s a bit “some assembly required” though - the way it works is that it allows you to encode layer information in a “meta” array and store and retrieve that when needed, which is a bit of a challenge for someone who (like me) isn’t a Javascript developer.

To do that, I need to add handlers for events so that the code knows when the base layer changes or when overlays are added or removed.

The “meta” that I use is just a list of layers, so “HPN” would mean that the default base layer is used, together with the “LA_PRoW” (“P”) and “No vis paths” (“N”) overlays. When the URL changes, the code must change the displayed layers to match. When layers are changed manually using the layer selector, the URL must change. The code makes sure that only one base layer is selected, and overlay layers are removed as required. The mapping between tile layer URLs and the representation in the current site URL is handled here.

What we can now do

West of Scafell Pike

The URL https://map.atownsend.org.uk/maps/map/map.html#16/54.4540/-3.2155/H/N turns on the “No vis paths” layer so that this path appears. It’s suppressed by default on the default layer because “sac_scale” is set to “demanding_mountain_hiking” and “trail_visibility” is set to “bad”, and it doesn’t have a designation tag on it.

UK/IE/IOM boundary

Boundaries are turned off by default, but a URL of https://map.atownsend.org.uk/maps/map/map.html#8/54.143/-4.878/H/B turns them on.

Jugger Howe

This (https://map.atownsend.org.uk/maps/map/map.html#15/54.3771/-0.5528/H/P/N) shows an overlay of the legal rights of way over surveyed paths of varying visibility, and how they significantly differ from what is actually there.

Location: LCPs of Fylingdales and Hawsker-cum-Stainsacre, North Yorkshire, England, YO22 4QB, United Kingdom

Discussion

Log in to leave a comment