How to open gmap via bokeh in a zoom value that will show all markers?

144 views Asked by At

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?

1

There are 1 answers

5
sitWolf On

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)