r-spatial / leafem

leaflet extensions for mapview
https://r-spatial.github.io/leafem/
Other
108 stars 28 forks source link

Feature request: open leaflet map with specific coordinates included in the URL #94

Closed aloboa closed 1 week ago

aloboa commented 1 week ago

I have a region of study with 3 smaller regions of interest. While I want the map to open the wider region by default, in some cases it would be better to include a link to one of the smaller regions of interest within the text. It seems to me that this could be done with this code: https://gis.stackexchange.com/questions/338367/leaflet-map-with-coordinates-included-in-the-url-path

Could this be wrapped or converted into a R function within leafem?

tim-salabim commented 1 week ago

I don't think I completely understand you question... Seems to me you want to host a map generated with leaflet/leafem online and have some special behaviour when the predefined map is rendered. This is what htmlwidgets::onRender() is for. See e.g. this gist for an example of adjusting view/zoom after the map has rendered

aloboa commented 1 week ago

I clarify: Assuming my map would be https://myserver.es/IcelandCampaign2023.html (which opens centered by setView(lat = 65, lng=-18.83 , zoom = 7) )

I would like to be able to link in the text so that the map opens with the view centered in another coordinate, eg something like: https://myserver.es/IcelandCampaign2023.html?lon=-19,lat=65.0,zoom=12 The equivalent to https://www.google.es/maps/@65,-19,12z

tim-salabim commented 1 week ago

If your map is a static html page, I don't know how you could do that. I think you would need an API with a running server to implement what you are after. After all, you'd need to parse the url components and update you map accordingly. This logic needs to happen outside of the map creation call. Once you have to correct coordinates and zoom, then you can create the map with those, but for an existing static html page, this seems impossible. Sounds like something you can implement using either shiny or plumber

aloboa commented 1 week ago

I understand. Thanks.