From e99d006e0dd27f389fa62697dfbaff228023c839 Mon Sep 17 00:00:00 2001 From: "Kharude, Sachin" Date: Tue, 8 Jun 2021 13:07:54 +0530 Subject: [PATCH 1/3] intial changes Signed-off-by: Kharude, Sachin --- examples/basemaps.ipynb | 6 ++---- examples/choropleth_layer.ipynb | 2 +- examples/custom_marker_icon.ipynb | 13 +++++++++---- examples/geodata.ipynb | 6 +++--- examples/infobubble.ipynb | 25 ++++++++++++++++++++----- examples/map_basics_demo.ipynb | 29 +++++++++++++++++++++++------ here_map_widget/map.py | 22 ++++++++++++++++++---- 7 files changed, 76 insertions(+), 27 deletions(-) diff --git a/examples/basemaps.ipynb b/examples/basemaps.ipynb index 7b37553..f6c9ee0 100644 --- a/examples/basemaps.ipynb +++ b/examples/basemaps.ipynb @@ -132,9 +132,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "# HERE Maptile service data as basemap\n", @@ -190,7 +188,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/examples/choropleth_layer.ipynb b/examples/choropleth_layer.ipynb index b4a5561..920b058 100644 --- a/examples/choropleth_layer.ipynb +++ b/examples/choropleth_layer.ipynb @@ -181,7 +181,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/examples/custom_marker_icon.ipynb b/examples/custom_marker_icon.ipynb index 58dda69..0044bae 100644 --- a/examples/custom_marker_icon.ipynb +++ b/examples/custom_marker_icon.ipynb @@ -40,10 +40,15 @@ "outputs": [], "source": [ "from here_map_widget import Map\n", - "from here_map_widget import GeoJSON\n", - "import os \n", + "import os\n", "\n", - "m = Map(api_key=os.environ['LS_API_KEY'], center=center, zoom=17.847987922471717, tilt=51.031054687499804, heading=163.63541103795387)\n", + "m = Map(\n", + " api_key=os.environ[\"LS_API_KEY\"],\n", + " center=center,\n", + " zoom=17.84,\n", + " tilt=51.03,\n", + " heading=163.63,\n", + ")\n", "m.add_object(marker)\n", "m" ] @@ -65,7 +70,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/examples/geodata.ipynb b/examples/geodata.ipynb index f16a2c6..3f5e5d1 100644 --- a/examples/geodata.ipynb +++ b/examples/geodata.ipynb @@ -36,8 +36,8 @@ "m = Map(center=(52.3,8.0), zoom = 3, api_key=os.environ['LS_API_KEY'])\n", "\n", "rivers_data = GeoData(geo_dataframe = rivers,\n", - " style={'color': 'purple', 'opacity':3, 'weight':1.9, 'dashArray':'2', 'fillOpacity':0.6},\n", - " hover_style={'fillColor': 'red' , 'fillOpacity': 0.2},\n", + " style={'strokeColor': \"rgba(128,0,128,1)\"},\n", + " hover_style={'strokeColor': \"rgba(255,0,0,1)\"},\n", " name = 'Rivers')\n", "\n", "m.add_layer(rivers_data)\n", @@ -62,7 +62,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/examples/infobubble.ipynb b/examples/infobubble.ipynb index 5d41d03..6eae0fb 100644 --- a/examples/infobubble.ipynb +++ b/examples/infobubble.ipynb @@ -117,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -128,9 +128,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "ed3a3aa8fbbf469686ab3094960da2d2", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Map(api_key='4Cn_zit94kHMbT026MOFiPyhMYEHvAzpCfvt-eJzzzs', basemap=None, center=[20.5937, 78.9629], layers=(Ge…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "from here_map_widget import Map, InfoBubble, Point\n", "from here_map_widget import GeoJSON\n", @@ -144,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -181,7 +196,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/examples/map_basics_demo.ipynb b/examples/map_basics_demo.ipynb index fa33a95..ecb1e40 100644 --- a/examples/map_basics_demo.ipynb +++ b/examples/map_basics_demo.ipynb @@ -253,16 +253,31 @@ "\n", "m = Map(api_key=os.environ['LS_API_KEY'])\n", "geojson = GeoJSON(url='https://gist.githubusercontent.com/peaksnail/5d4f07ca00ed7c653663d7874e0ab8e7/raw/64c2a975482efd9c42e54f6f6869f091055053cd/countries.geo.json', disable_legacy_mode=True, \n", - " style={\"fillColor\": \"#F5B041\", \"color\": \"black\", \"opacity\": 0.1}, show_bubble=True)\n", + " style={\"fillColor\": \"rgba(245, 176, 65, 0.5)\", \"strokeColor\": \"black\"}, show_bubble=True)\n", "m.add_layer(geojson)\n", "m" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "f234110f1238422999b44826f1e28ca6", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Map(api_key='4Cn_zit94kHMbT026MOFiPyhMYEHvAzpCfvt-eJzzzs', basemap=None, center=[20.5937, 78.9629], layers=(Ge…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "#Add geojson from Local File\n", "from here_map_widget import Map\n", @@ -276,9 +291,11 @@ " data = json.load(f)\n", "\n", "def call_back(feature):\n", - " return {\"fillColor\": \"#F5B041\", \"color\": \"black\", \"opacity\": 0.1}\n", + " return {\"fillColor\": \"rgba(245, 176, 65, 0.7)\", \"strokeColor\": \"black\", \"lineWidth\": 1}\n", + "\n", + "hover_style = {\"fillColor\": \"rgba(245, 176, 65, 0.2)\", \"strokeColor\": \"red\", \"lineWidth\": 5}\n", "\n", - "geojson = GeoJSON(data=data, style_callback=call_back, disable_legacy_mode=True)\n", + "geojson = GeoJSON(data=data, style_callback=call_back, hover_style=hover_style, disable_legacy_mode=True)\n", "m.add_layer(geojson)\n", "m" ] @@ -449,7 +466,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.9" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/here_map_widget/map.py b/here_map_widget/map.py index 0a2059d..2feda09 100644 --- a/here_map_widget/map.py +++ b/here_map_widget/map.py @@ -351,8 +351,11 @@ class GeoJSON(Layer): _hover_callbacks = Instance(CallbackDispatcher, ()) def __init__(self, **kwargs): + self.updating = True super(GeoJSON, self).__init__(**kwargs) self.on_msg(self._handle_m_msg) + self.data = self._get_data() + self.updating = False def _handle_m_msg(self, _, content, buffers): if content.get("event", "") == "tap": @@ -380,7 +383,12 @@ def _validate_style_callback(self, proposal): @observe("data", "style", "style_callback") def _update_data(self, change): + if self.updating: + return + + self.updating = True self.data = self._get_data() + self.updating = False def _get_data(self): if "type" not in self.data: @@ -398,20 +406,26 @@ def _get_data(self): # No style to apply return self.data + # We need to make a deep copy for ipywidgets to see the change + data = copy.deepcopy(self.data) + if datatype == "Feature": - self._apply_style(self.data, style_callback) + self._apply_style(data, style_callback) elif datatype == "FeatureCollection": - for feature in self.data["features"]: + for feature in data["features"]: self._apply_style(feature, style_callback) - return self.data + return data def _apply_style(self, feature, style_callback): if "properties" not in feature: feature["properties"] = {} + properties = feature["properties"] if "style" in properties: - properties["style"].update(style_callback(feature)) + style = properties["style"].copy() + style.update(style_callback(feature)) + properties["style"] = style else: properties["style"] = style_callback(feature) From be337e271f3459a0dbcc42541265693eed8dd71a Mon Sep 17 00:00:00 2001 From: "Kharude, Sachin" Date: Tue, 8 Jun 2021 13:16:33 +0530 Subject: [PATCH 2/3] removed output Signed-off-by: Kharude, Sachin --- examples/map_basics_demo.ipynb | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/examples/map_basics_demo.ipynb b/examples/map_basics_demo.ipynb index ecb1e40..6ec8fa8 100644 --- a/examples/map_basics_demo.ipynb +++ b/examples/map_basics_demo.ipynb @@ -260,24 +260,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "f234110f1238422999b44826f1e28ca6", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Map(api_key='4Cn_zit94kHMbT026MOFiPyhMYEHvAzpCfvt-eJzzzs', basemap=None, center=[20.5937, 78.9629], layers=(Ge…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "#Add geojson from Local File\n", "from here_map_widget import Map\n", From d6101c714a4fb5f35ff0cfeea9747843a6d79b25 Mon Sep 17 00:00:00 2001 From: "Kharude, Sachin" Date: Tue, 8 Jun 2021 13:24:57 +0530 Subject: [PATCH 3/3] updated notebooks Signed-off-by: Kharude, Sachin --- examples/basemaps.ipynb | 6 ++++-- examples/choropleth_layer.ipynb | 2 +- examples/custom_marker_icon.ipynb | 2 +- examples/geodata.ipynb | 2 +- examples/infobubble.ipynb | 25 +++++-------------------- examples/map_basics_demo.ipynb | 2 +- here_map_widget/map.py | 22 ++++------------------ 7 files changed, 17 insertions(+), 44 deletions(-) diff --git a/examples/basemaps.ipynb b/examples/basemaps.ipynb index f6c9ee0..7b37553 100644 --- a/examples/basemaps.ipynb +++ b/examples/basemaps.ipynb @@ -132,7 +132,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "scrolled": false + }, "outputs": [], "source": [ "# HERE Maptile service data as basemap\n", @@ -188,7 +190,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.7.9" } }, "nbformat": 4, diff --git a/examples/choropleth_layer.ipynb b/examples/choropleth_layer.ipynb index 920b058..b4a5561 100644 --- a/examples/choropleth_layer.ipynb +++ b/examples/choropleth_layer.ipynb @@ -181,7 +181,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.7.9" } }, "nbformat": 4, diff --git a/examples/custom_marker_icon.ipynb b/examples/custom_marker_icon.ipynb index 0044bae..ca4ce47 100644 --- a/examples/custom_marker_icon.ipynb +++ b/examples/custom_marker_icon.ipynb @@ -70,7 +70,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.7.9" } }, "nbformat": 4, diff --git a/examples/geodata.ipynb b/examples/geodata.ipynb index 3f5e5d1..ae8b93f 100644 --- a/examples/geodata.ipynb +++ b/examples/geodata.ipynb @@ -62,7 +62,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.7.9" } }, "nbformat": 4, diff --git a/examples/infobubble.ipynb b/examples/infobubble.ipynb index 6eae0fb..5d41d03 100644 --- a/examples/infobubble.ipynb +++ b/examples/infobubble.ipynb @@ -117,7 +117,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -128,24 +128,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "ed3a3aa8fbbf469686ab3094960da2d2", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "Map(api_key='4Cn_zit94kHMbT026MOFiPyhMYEHvAzpCfvt-eJzzzs', basemap=None, center=[20.5937, 78.9629], layers=(Ge…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "from here_map_widget import Map, InfoBubble, Point\n", "from here_map_widget import GeoJSON\n", @@ -159,7 +144,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -196,7 +181,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.7.9" } }, "nbformat": 4, diff --git a/examples/map_basics_demo.ipynb b/examples/map_basics_demo.ipynb index 6ec8fa8..9b721e3 100644 --- a/examples/map_basics_demo.ipynb +++ b/examples/map_basics_demo.ipynb @@ -451,7 +451,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.8" + "version": "3.7.9" } }, "nbformat": 4, diff --git a/here_map_widget/map.py b/here_map_widget/map.py index 2feda09..0a2059d 100644 --- a/here_map_widget/map.py +++ b/here_map_widget/map.py @@ -351,11 +351,8 @@ class GeoJSON(Layer): _hover_callbacks = Instance(CallbackDispatcher, ()) def __init__(self, **kwargs): - self.updating = True super(GeoJSON, self).__init__(**kwargs) self.on_msg(self._handle_m_msg) - self.data = self._get_data() - self.updating = False def _handle_m_msg(self, _, content, buffers): if content.get("event", "") == "tap": @@ -383,12 +380,7 @@ def _validate_style_callback(self, proposal): @observe("data", "style", "style_callback") def _update_data(self, change): - if self.updating: - return - - self.updating = True self.data = self._get_data() - self.updating = False def _get_data(self): if "type" not in self.data: @@ -406,26 +398,20 @@ def _get_data(self): # No style to apply return self.data - # We need to make a deep copy for ipywidgets to see the change - data = copy.deepcopy(self.data) - if datatype == "Feature": - self._apply_style(data, style_callback) + self._apply_style(self.data, style_callback) elif datatype == "FeatureCollection": - for feature in data["features"]: + for feature in self.data["features"]: self._apply_style(feature, style_callback) - return data + return self.data def _apply_style(self, feature, style_callback): if "properties" not in feature: feature["properties"] = {} - properties = feature["properties"] if "style" in properties: - style = properties["style"].copy() - style.update(style_callback(feature)) - properties["style"] = style + properties["style"].update(style_callback(feature)) else: properties["style"] = style_callback(feature)