From 6ad27feecccc5250264f8a06f9eaddc3f23ec1ae Mon Sep 17 00:00:00 2001 From: "Jason T. Brown" Date: Mon, 15 Jun 2020 11:19:01 -0400 Subject: [PATCH 1/2] Implement __geo_interface__ for relevant classes --- ipyleaflet/leaflet.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ipyleaflet/leaflet.py b/ipyleaflet/leaflet.py index 5e357e6db..ec492083e 100644 --- a/ipyleaflet/leaflet.py +++ b/ipyleaflet/leaflet.py @@ -545,6 +545,16 @@ def _get_data(self): return self.data + @property + def __geo_interface__(self): + """ + Return a dict whose structure aligns to the GeoJSON format + For more information about the ``__geo_interface__``, see + https://gist.github.com/sgillies/2217756 + """ + + return self.data + def _apply_style(self, feature, style_callback): if 'properties' not in feature: feature['properties'] = {} @@ -595,6 +605,9 @@ def _update_data(self, change): def _get_data(self): return json.loads(self.geo_dataframe.to_json()) + @property + def __geo_interface__(self): + return self.geo_dataframe.__geo_interface__ class Choropleth(GeoJSON): geo_data = Dict() From 708c31e8196c0e2a8f3c073f5456c26074219b38 Mon Sep 17 00:00:00 2001 From: "Jason T. Brown" Date: Mon, 15 Jun 2020 12:16:18 -0400 Subject: [PATCH 2/2] Add docstring to GeoData.__geo_interface__, fix spacing for linter --- ipyleaflet/leaflet.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ipyleaflet/leaflet.py b/ipyleaflet/leaflet.py index ec492083e..ac8674252 100644 --- a/ipyleaflet/leaflet.py +++ b/ipyleaflet/leaflet.py @@ -607,8 +607,15 @@ def _get_data(self): @property def __geo_interface__(self): + """ + Return a dict whose structure aligns to the GeoJSON format + For more information about the ``__geo_interface__``, see + https://gist.github.com/sgillies/2217756 + """ + return self.geo_dataframe.__geo_interface__ + class Choropleth(GeoJSON): geo_data = Dict() choro_data = Dict()