SymbolixAU / googleway

R Package for accessing and plotting Google Maps
http://symbolixau.github.io/googleway/
Other
234 stars 46 forks source link

Is it possible to set max bounds for the google_map? #242

Closed BursacPetar closed 5 months ago

BursacPetar commented 2 years ago

Hi, I am building one Shiny app and i want to limit google_map to specific boundaries. Please let me know is it possible to set boundaries - max bounds for the purpose of limiting map area (something like setMaxBounds in leaflet package).

Thanks! Kind regards, Petar

dcooley commented 2 years ago

I've just made a prototype on branch issue242 where you can specify the min_zoom and max_zoom arguments.

Could you test this and let me know if it works for you?

remotes::install_github("SymbolixAU/google", ref = "issue242")

## example
set_key("your key")

  google_map(
    min_zoom = 8
    , max_zoom = 12
  )
BursacPetar commented 2 years ago

Hi, Thank you very much for quick answer. Great, yes it works, but i am also interested in setting bounds in geographical space - limit the map pan? Please let me know is this possible, to set something like min_latitude, max_latitude, min_longitude and max_longitude and in that way to limit map pan? Thanks!

BursacPetar commented 2 years ago

Hi @dcooley , I found this in google maps platform. That's exactly what I need. Is it at all possible to implement this within the googleway package. image

Thanks!

dcooley commented 2 years ago

yes that is possible - sorry I've been off work the last few days so haven't got to this.

I've just pushed a commit to branch issue242 with code that I think should work, but I haven't tested it. Feel free to test & update the branch with a PR if you need to, or if you can wait until Monday I should be able to take a proper run at it then.

BursacPetar commented 2 years ago

Hi @dcooley, Thank you for your answer. Great! Unfortunately i can't make changes to branch 242, i dont have permissions. I found this as typing errors (comma is missing in file google_map.js) and this is now working (map is displayed):

image

The bounds have not yet been applied and I think it is a problem to call the variable x.mapBounds in js like x.mapBounds.south (because map_bounds is dataframe and 'south' is a column, not list element). When bounds is manually write down, it works.

image

Thanks!

dcooley commented 2 years ago

Unfortunately i can't make changes to branch 242

If you need / want to make changes you can clone the repo, make changes and make a pull-request back into this repo.


I've udpated the branch with the necessary fixes. Now this works:

library(sf)
nc <- sf::st_read(system.file("./shape/nc.shp", package = "sf"))

google_map(
  map_bounds = sf::st_bbox(nc)
)
BursacPetar commented 2 years ago

Thanks! Great, now it works as expected!