pbugnion / gmaps

Google maps for Jupyter notebooks
https://jupyter-gmaps.readthedocs.io/en/stable/
Other
760 stars 146 forks source link

Ability to dynamically update data in heatmaps #188

Closed pbugnion closed 6 years ago

pbugnion commented 7 years ago

Currently, the style of a heatmap can be updated dynamically after the map has been rendered, but not the underlying data. The abilty to do this would be useful.

This was originally raised in issue #186.

pbugnion commented 7 years ago

A workaround would be to keep track of the heatmap data yourself, and create a new map when that data is updated:

class UpdatingHeatmap(object):
    def __init__(self, center, zoom):
        self.data = []
        self.map_kwargs = {
            'layout': {'width': '600px', 'height': '400px'},
            'initial_viewport':  gmaps.InitialViewport.from_zoom_center(zoom, center)
        }
        map_ = self._create_map()
        self.container = widgets.HBox([map_])

    def _create_map(self):
        if self.data:
            print(self.data)
            heatmap_layer = gmaps.heatmap_layer(self.data)
            map_ = gmaps.Map(
                layers=[heatmap_layer], **self.map_kwargs 
            )
        else:
            map_ = gmaps.Map(layers=[], **self.map_kwargs)
        return map_

    def update_data(self, new_data):
        self.data = new_data
        new_map = self._create_map()
        self.container.children = [new_map]

    def display(self):
        return self.container

giphy

pbugnion commented 6 years ago

Closed by #212.

mogli91 commented 6 years ago

Is there a way to update drawings on the fly? I want to update individual polygon Lines' colors as some state changes EDIT: found it (modifying the drawing object is sufficient; don't know why this did not work before)