I'm writing a browser extension which paints over the map of komoot.com/plan . Currently I do this by placing a canvas
on top of the existing canvas
.
This works well but it is static and does not yet react to when the user moves the map around or zooms into it or the website focusses a particular location on the map.
How do I best tie into this event loop of map updates?
I could mimic / reimplement how komoot processes user input, but this sounds fragile and unreliable and messy. I would do this by adding listeners for mouse button events and cursor movement, etc.
The page's URL contains the lat and long coordinates together with the zoom level, eg, https://www.komoot.com/plan/@49.9535480,5.3956956,11.345z
. It changes after the map has changed. I assume there's a way to be notified of changes in the URL. If so I could then dynamically update my canvas
.
You don't seem to have mentioned the obvious way: use the move
event:
map.on('move',e => {...
// get center with map.getCenter()
});
But it's not really clear exactly what you're trying to do, so hard to advise more specifically.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.