Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set zoom level with a google_map object using the add_markers() #130

Closed
nbarsch opened this issue Feb 8, 2018 · 10 comments
Closed

Set zoom level with a google_map object using the add_markers() #130

nbarsch opened this issue Feb 8, 2018 · 10 comments

Comments

@nbarsch
Copy link

nbarsch commented Feb 8, 2018

It states in the documentation "The map will automatically set the location and
zoom if markers are supplied through add_markers".

Is there a way to override the zoom level to a farther out zoom?

Reason behind this: I'd like to initially map just one coordinate, in shiny, but set the zoom level much farther out than the auto zoom to show the map around that one coordinate. I.e. ideally it would function as below (which in current syntax still gives me the close up on the one coordinate, from df gpscoords2 cols lat/lon).

  output$map <- renderGoogle_map({
    google_map(key = api_key, data=gpscoords2, zoom=15) %>%
      add_markers()
  })
@SymbolixAU
Copy link
Collaborator

SymbolixAU commented Feb 8, 2018

@nbarsch Set the update_map_view argument to FALSE.

See the difference between

google_map(zoom = 3) %>% 
  add_markers(data = tram_stops)

google_map(zoom = 3) %>% 
  add_markers(data = tram_stops, update_map_view = FALSE)

@nbarsch
Copy link
Author

nbarsch commented Feb 8, 2018

Thanks for this! I got it to work. Did you guys just add this? Just as an FYI I tried this from the CRAN version (installed about a month or so ago) and kept running into unused argument: update_map_view. Figured it was added in the dev version so uninstalled and grabbed the dev version (install_github) and it worked fine. Not sure if I had an old CRAN version or not, looks like I probably did since the CRAN documentation is dated feb 1 (after I installed the CRAN version I had). Again, thanks for a pretty great package.

@nbarsch nbarsch closed this as completed Feb 8, 2018
@SymbolixAU
Copy link
Collaborator

SymbolixAU commented Feb 8, 2018

@nbarsch My latest release to CRAN was version 2.4.0 last week, so yours was probably out of date. And yes, the update_map_view argument was added in 2.4

Glad you're finding it useful. It's good to see people getting use out of it. And, if you come across any other suggestions feel free to ask!

@tnelsen
Copy link

tnelsen commented Apr 18, 2022

I need to be able to update where the map is centered without updating the zoom level of an already rendered map. Right now the only way that seems possible is by re-rending the map? Is there a way to center the map view around a new marker but keep the current zoom level? Also, similar to #230

@dcooley
Copy link
Collaborator

dcooley commented Apr 19, 2022

I've just pushed an update to the master branch with a function google_map_view(), which lets you set the view's location.

e.g.

google_map() %>% 
  add_markers(data = tram_stops, update_map_view = FALSE) %>% 
  google_map_view(location = c(52.5, 0.1), zoom = 6)

I haven't fully decided on the function name or functionality yet, but let me know if this is what you're looking for.

@tnelsen
Copy link

tnelsen commented May 3, 2022

That's what I was looking for, thanks!

@kaheil
Copy link

kaheil commented May 13, 2022

I just tested this as follows, and it does not work:

  google_map_update(map_id = ns("srGoogleMap"),data=gAco) %>%
      googleway::google_map_view(location = as.numeric(gAco), zoom = 13) %>% 
       googleway::clear_markers() %>%
       googleway::add_markers(lat="lat",lon ="lng")

@dcooley
Copy link
Collaborator

dcooley commented May 23, 2022

@kaheil what specifically does not work?

when you call the add_markers() function it will auto-zoom to the makers, unless you specify update_map_view = FALSE

@kaheil
Copy link

kaheil commented May 23, 2022

For me, the first marker (let's say a house in Massachusetts) I add, the map will zoom to it, then I clear markers, then I add a second marker (let's say a house in California), the map will not zoom to that house, but will be on a zoom and extent that shows the first marker and the second (even though the markers were cleared). The map seems to remember the markers even if they are cleared

@dcooley
Copy link
Collaborator

dcooley commented May 24, 2022

Moving to a new isssue #251

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants