0

I run the following code, displaying google map via bokeh with markers on the map:

gmap_options = GMapOptions(lat=lat, lng=lng,
                           map_type=map_type, zoom=zoom)
p = gmap(api_key, gmap_options, title='PhotosTrip',
         width=bokeh_width, height=bokeh_height, tooltips=TOOLTIPS,
         tools=[hover, 'reset', 'wheel_zoom', 'pan'])
p.circle('x', 'y' , size=8, alpha=0.5,
                  color='black', source=source)

How can I select the proper zoom so all markers will be displayed when the map opens?

gtomer
  • 5,643
  • 1
  • 10
  • 21
  • Are you asking for a dynamic way to set the zoom attribute for GMapOptions depending on the circle source? In that case you will have to create a separate function that determines the proper zoom value (as int), then update p.map_options – sitWolf Oct 20 '22 at 18:04
  • Yes. This is what I am after – gtomer Oct 22 '22 at 07:57

1 Answers1

0

Assuming that by omitting zoom it defaults to 12, and given the limited information, an approach would be as follows:

def get_outer_markers(marker_source):
    # read dataset
    # process dataset. See e.g. https://stackoverflow.com/questions/25787637/python-plot-only-the-outermost-points-of-a-dataset
    outer_markers = ...
    return outer_markers

def get_extremum_points(markers):
    # see e.g. https://stackoverflow.com/questions/31667070/max-distance-between-2-points-in-a-data-set-and-identifying-the-points
    longest_distance = ...
    return longest_distance

def convert_distance_to_zoom_value(distance):
    # Here you define your desired zoom
    # Define a formula that converts distance to the desired zoom
    return zoom_value

most_outher_markers = get_outer_markers(marker_source=source)
longest_euclidean = get_extremum_points(markers=most_outher_markers)
zoom_value = convert_distance_to_zoom_value(extremum_markers)

gmap_options = GMapOptions(lat=lat, lng=lng,
                           map_type=map_type, zoom=zoom_value)
sitWolf
  • 930
  • 10
  • 16
  • Not sure that I follow. I want that from a given coordinates of markers I will know which zoom to send to the GMapOptions so all the markers will be in view. The code above has no such calculation.... – gtomer Oct 22 '22 at 10:34
  • In other words, you write: "Define a formula that converts distance to the desired zoom" - but this is the heart of the question – gtomer Oct 22 '22 at 10:42
  • 1
    The extremum_markers shall be the max of euclidian distance from the origin to the most outer markers. This distance is equivalent to the zoom_value. That is the value you pass to get_zoom_value(). You can find the proper formula by simple trial and error. For example, zoom_value = int(distance/123) # e.g. 10. 123 is a random value, the value you should experiment with. It is impossible for me to state what the proper value is for your case without any code. – sitWolf Oct 22 '22 at 10:51
  • 1
    I modified some function and variable names for clarity. – sitWolf Oct 22 '22 at 10:54
  • Thank you for the effort. However, the heart of the issue was the zoom_value formula – gtomer Oct 22 '22 at 14:15