2

I can only set zooms but I need to have a very specific position so I can overlay it over another plot. How I get a view just from the limits I specified below? Right now I can only set a zoom which is difficult for overlaying on another plot.

from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, GMapOptions
from bokeh.plotting import gmap

output_file("gmap.html")

lat_lims = (42.418574999999997, 42.420059000000002)
lon_lims = (-70.907111, -70.904135999999994)
map_options = GMapOptions(lat=np.mean(lat_lims), lng=np.mean(lon_lims), map_type="satellite", zoom=18)

# For GMaps to function, Google requires you obtain and enable an API key:
#
#     https://developers.google.com/maps/documentation/javascript/get-api-key
#
# Replace the value below with your personal API key:
p = gmap(googlemaps_api_key, map_options)


show(p)

enter image description here

O.rka
  • 29,847
  • 68
  • 194
  • 309

1 Answers1

0

If you were running a Bokeh Server application, it is possible that the bounds could be returned back to Python in some way, but I'm afraid it is not possible in a standalone Bokeh document (i.e. HTML file) as you have. We are constrained by the using the Google maps API, and the bounds you are asking for are only available once the JavaScript code executes in the browser. The Google API does not accept arbitrary user provided bounds, it only accepts a center/zoom, or a suggested region. The real bounds are only computed and returned (to the browser) by Google API, and are never computed or available in Python.

You might look at the non-google TileProvider plots that are available. Unlike with GMap plots, you yourself can set the map bounds.

bigreddot
  • 33,642
  • 5
  • 69
  • 122
  • Thank you, it’s interesting that the Google Maps API wouldn’t include this type of functionality since it seems like it would be a very common usage. Do you know if the tile provider plots have a satellite view for the map style? – O.rka Apr 04 '18 at 14:39
  • The reason the Google API does not allow arbitrary map bounds is because they choose to maintain exacting control over pixel aspect ratios, etc to make sure that the visual display is always exactly correct. The tile provider maps provide "more flexibility" but at the cost that the imagery can be stretched in one direction or another if you don't take care. i.e. if you ask ito display a 10Mm x 1km meter area in a square viewport, it will do it, and just be very compressed in one dimension. Google maps will never stretch like this, though. – bigreddot Apr 04 '18 at 15:37
  • Also I am not sure about *satellite* imagery, unfortunately. The two service I know of, Carto and Stamen, do not offer satellite tiles that I know of (but I may be wrong). – bigreddot Apr 04 '18 at 15:40