Skip to content

Conversation

@bbriegel
Copy link

@bbriegel bbriegel commented Feb 3, 2020

Allows dynamically updating the viewport based on changes in the data bounds of the layers, e.g.:

import gmaps

class MapContainer(object):
    def __init__(self):
        self._fig = gmaps.figure()
        self._marker_layer = gmaps.marker_layer(locations=[])
        self._fig.add_layer(self._marker_layer)
        display(self._fig)
        
    def update(self, coordinates_list):
        self._marker_layer.markers = [gmaps.Marker(location=coordinates) 
                                      for coordinates in coordinates_list]
        self._fig._map._calc_bounds({'new': self._fig._map.layers})
        
        
container = MapContainer()
london_coordinates = (51.507942, -0.127566)
berlin_coordinates = (52.518880, 13.408935)
new_york_coordinates = (40.708081, -74.005807)
washington_coordinates = (38.910675, -77.035177)
container.update([london_coordinates, berlin_coordinates])

map_london_berlin

container.update([new_york_coordinates, washington_coordinates])

map_new_york_washington

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

Successfully merging this pull request may close these issues.

1 participant