From 88fc93aff44f1141bdaf8f962f1919d8900240d0 Mon Sep 17 00:00:00 2001 From: kenseii Date: Tue, 8 Oct 2019 11:36:16 +0900 Subject: [PATCH 01/10] image overlay placeholder --- llplot/google_maps_templates.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/llplot/google_maps_templates.py b/llplot/google_maps_templates.py index a3e3f4d..3f11b9f 100644 --- a/llplot/google_maps_templates.py +++ b/llplot/google_maps_templates.py @@ -57,6 +57,11 @@ """ % EARTH_RADIUS +OVERLAY = """ +var imageUrl = {imageUrl}, +imageBounds = {imageBounds}; +L.imageOverlay(imageUrl, imageBounds).addTo(map); +""" # FIXME: This generate a Xmark in cartesian frame rather than in lat/long. CROSS = """ From 59872e089fb8496124575a53416b9818b6fb4a20 Mon Sep 17 00:00:00 2001 From: kenseii Date: Tue, 8 Oct 2019 12:13:36 +0900 Subject: [PATCH 02/10] placeholder writer --- llplot/llplot.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/llplot/llplot.py b/llplot/llplot.py index fc644f9..07ff26c 100644 --- a/llplot/llplot.py +++ b/llplot/llplot.py @@ -9,7 +9,7 @@ from collections import namedtuple from llplot.color_dicts import mpl_color_map, html_color_codes -from llplot.google_maps_templates import SYMBOLS, CIRCLE +from llplot.google_maps_templates import SYMBOLS, CIRCLE, OVERLAY Symbol = namedtuple('Symbol', ['symbol', 'lat', 'long', 'size']) @@ -213,24 +213,24 @@ def _process_heatmap_kwargs(self, settings_dict): return settings_string - def ground_overlay(self, url, bounds_dict): + def ground_overlay(self, imageUrl, imageBounds): ''' - :param url: Url of image to overlay - :param bounds_dict: dict of the form {'north': , 'south': , 'west': , 'east': } + :param imageUrl: Url of image to overlay + :param imageBounds: dict of the form [[40.712216, -74.22655], [40.773941, -74.12544]] setting the image container :return: None Example use: import llplot - gmap = llplot.GoogleMapPlotter(37.766956, -122.438481, 13) - bounds_dict = {'north':37.832285, 'south': 37.637336, 'west': -122.520364, 'east': -122.346922} - gmap.ground_overlay('http://explore.museumca.org/creeks/images/TopoSFCreeks.jpg', bounds_dict) - gmap.draw("my_map.html") - Google Maps API documentation - https://developers.google.com/maps/documentation/javascript/groundoverlays#introduction + lmap = llplot.LeafletPlotter(37.766956, -122.438481, 13) + bounds_dict = [[40.712216, -74.22655], [40.773941, -74.12544]] + lmap.ground_overlay('http://explore.museumca.org/creeks/images/TopoSFCreeks.jpg', bounds_dict) + lmap.draw("my_map.html") + Leaflet API documentation + https://leafletjs.com/reference-1.5.0.html#imageoverlay ''' - bounds_string = self._process_ground_overlay_image_bounds(bounds_dict) - self.ground_overlays.append((url, bounds_string)) + # bounds_string = self._process_ground_overlay_image_bounds(imageBounds) + self.ground_overlays.append((imageUrl, imageBounds)) def _process_ground_overlay_image_bounds(self, bounds_dict): bounds_string = 'var imageBounds = {' @@ -282,7 +282,7 @@ def draw(self, htmlfile, img_path=None, header=None, footer=None): # self.write_symbols(f) # self.write_shapes(f) # self.write_heatmap(f) - # self.write_ground_overlay(f) + self.write_ground_overlay(f) self.write_fitbounds(f) f.write('\t}\n') f.write('\n') @@ -510,13 +510,14 @@ def write_heatmap(self, f): def write_ground_overlay(self, f): for url, bounds_string in self.ground_overlays: - f.write(bounds_string) - f.write('var groundOverlay;' + '\n') - f.write('groundOverlay = new google.maps.GroundOverlay(' + '\n') - f.write('\n') - f.write("'" + url + "'," + '\n') - f.write('imageBounds);' + '\n') - f.write('groundOverlay.setMap(map);' + '\n') + # f.write(bounds_string) + # f.write('var groundOverlay;' + '\n') + # f.write('groundOverlay = new google.maps.GroundOverlay(' + '\n') + # f.write('\n') + # f.write("'" + url + "'," + '\n') + # f.write('imageBounds);' + '\n') + # f.write('groundOverlay.setMap(map);' + '\n') + f.write(OVERLAY.format(imageUrl=url, imageBounds=bounds_string)) def write_fitbounds(self, f): if self.bounding_box is None: From 9c15b13604b31a20dfa37f06f447091695c9b4af Mon Sep 17 00:00:00 2001 From: kenseii Date: Tue, 8 Oct 2019 13:02:19 +0900 Subject: [PATCH 03/10] updated the placeholder to use llmap and put the url in quotes --- llplot/google_maps_templates.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llplot/google_maps_templates.py b/llplot/google_maps_templates.py index 3f11b9f..9e8d365 100644 --- a/llplot/google_maps_templates.py +++ b/llplot/google_maps_templates.py @@ -58,9 +58,9 @@ """ % EARTH_RADIUS OVERLAY = """ -var imageUrl = {imageUrl}, +var imageUrl = "{imageUrl}", imageBounds = {imageBounds}; -L.imageOverlay(imageUrl, imageBounds).addTo(map); +L.imageOverlay(imageUrl, imageBounds).addTo(llMap); """ # FIXME: This generate a Xmark in cartesian frame rather than in lat/long. From c6afe3d373ede1b0f0742aa894b7df655bd094f8 Mon Sep 17 00:00:00 2001 From: kenseii Date: Tue, 8 Oct 2019 14:07:38 +0900 Subject: [PATCH 04/10] put the overlay in a variable --- llplot/google_maps_templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llplot/google_maps_templates.py b/llplot/google_maps_templates.py index 9e8d365..4b51df6 100644 --- a/llplot/google_maps_templates.py +++ b/llplot/google_maps_templates.py @@ -60,7 +60,7 @@ OVERLAY = """ var imageUrl = "{imageUrl}", imageBounds = {imageBounds}; -L.imageOverlay(imageUrl, imageBounds).addTo(llMap); +var overlay = L.imageOverlay(imageUrl, imageBounds).addTo(llMap); """ # FIXME: This generate a Xmark in cartesian frame rather than in lat/long. From ba12069c830491da139fc7b83d831f4fadfa0a27 Mon Sep 17 00:00:00 2001 From: kenseii Date: Tue, 8 Oct 2019 14:18:48 +0900 Subject: [PATCH 05/10] attempt to add settings to the overlay --- llplot/llplot.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/llplot/llplot.py b/llplot/llplot.py index 07ff26c..7e5474d 100644 --- a/llplot/llplot.py +++ b/llplot/llplot.py @@ -213,7 +213,9 @@ def _process_heatmap_kwargs(self, settings_dict): return settings_string - def ground_overlay(self, imageUrl, imageBounds): + def ground_overlay(self, imageUrl, imageBounds, opacity=1.0, alt='', + interactive=0, crossOrigin=0, errorOverlayUrl='', + zIndex=1, className=''): ''' :param imageUrl: Url of image to overlay :param imageBounds: dict of the form [[40.712216, -74.22655], [40.773941, -74.12544]] @@ -228,18 +230,23 @@ def ground_overlay(self, imageUrl, imageBounds): Leaflet API documentation https://leafletjs.com/reference-1.5.0.html#imageoverlay ''' - + settings = {} + settings['opacity'] = opacity + settings['alt'] = alt + settings['interactive'] = interactive + settings['crossOrigin'] = crossOrigin + settings['errorOverlayUrl'] = errorOverlayUrl + settings['zIndex'] = zIndex + settings['className'] = className # bounds_string = self._process_ground_overlay_image_bounds(imageBounds) self.ground_overlays.append((imageUrl, imageBounds)) + self._process_ground_overlay_settings(settings) - def _process_ground_overlay_image_bounds(self, bounds_dict): - bounds_string = 'var imageBounds = {' - bounds_string += "north: %.4f,\n" % bounds_dict['north'] - bounds_string += "south: %.4f,\n" % bounds_dict['south'] - bounds_string += "east: %.4f,\n" % bounds_dict['east'] - bounds_string += "west: %.4f};\n" % bounds_dict['west'] + def _process_ground_overlay_settings(self, settings): + settings_string = '' + settings_string += "overlay.setOptions(%s);\n" % settings - return bounds_string + return settings_string def polygon(self, lats, lngs, color=None, c=None, **kwargs): color = color or c From 3c62b1500856419f1b9554c74123db355d89b1e4 Mon Sep 17 00:00:00 2001 From: kenseii Date: Tue, 8 Oct 2019 19:15:07 +0900 Subject: [PATCH 06/10] write overlay settings to the html --- llplot/llplot.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/llplot/llplot.py b/llplot/llplot.py index 7e5474d..8ce32dd 100644 --- a/llplot/llplot.py +++ b/llplot/llplot.py @@ -239,8 +239,9 @@ def ground_overlay(self, imageUrl, imageBounds, opacity=1.0, alt='', settings['zIndex'] = zIndex settings['className'] = className # bounds_string = self._process_ground_overlay_image_bounds(imageBounds) - self.ground_overlays.append((imageUrl, imageBounds)) - self._process_ground_overlay_settings(settings) + + settings = self._process_ground_overlay_settings(settings) + self.ground_overlays.append((imageUrl, imageBounds, settings)) def _process_ground_overlay_settings(self, settings): settings_string = '' @@ -516,7 +517,7 @@ def write_heatmap(self, f): def write_ground_overlay(self, f): - for url, bounds_string in self.ground_overlays: + for url, bounds_string, settings in self.ground_overlays: # f.write(bounds_string) # f.write('var groundOverlay;' + '\n') # f.write('groundOverlay = new google.maps.GroundOverlay(' + '\n') @@ -525,6 +526,8 @@ def write_ground_overlay(self, f): # f.write('imageBounds);' + '\n') # f.write('groundOverlay.setMap(map);' + '\n') f.write(OVERLAY.format(imageUrl=url, imageBounds=bounds_string)) + f.write(settings) + def write_fitbounds(self, f): if self.bounding_box is None: From f3e296c79bc8d100dfab4e3c2694254c5726bff9 Mon Sep 17 00:00:00 2001 From: kenseii Date: Tue, 8 Oct 2019 19:20:04 +0900 Subject: [PATCH 07/10] write settings using the placeholder --- llplot/google_maps_templates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llplot/google_maps_templates.py b/llplot/google_maps_templates.py index 4b51df6..89ace8e 100644 --- a/llplot/google_maps_templates.py +++ b/llplot/google_maps_templates.py @@ -60,7 +60,7 @@ OVERLAY = """ var imageUrl = "{imageUrl}", imageBounds = {imageBounds}; -var overlay = L.imageOverlay(imageUrl, imageBounds).addTo(llMap); +var overlay = L.imageOverlay(imageUrl, imageBounds, {settings}).addTo(llMap); """ # FIXME: This generate a Xmark in cartesian frame rather than in lat/long. From f710a7b7ae68cb56dc4394d78a2154801559e42f Mon Sep 17 00:00:00 2001 From: kenseii Date: Tue, 8 Oct 2019 19:20:53 +0900 Subject: [PATCH 08/10] write settings using the placeholder --- llplot/llplot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llplot/llplot.py b/llplot/llplot.py index 8ce32dd..5338636 100644 --- a/llplot/llplot.py +++ b/llplot/llplot.py @@ -525,8 +525,7 @@ def write_ground_overlay(self, f): # f.write("'" + url + "'," + '\n') # f.write('imageBounds);' + '\n') # f.write('groundOverlay.setMap(map);' + '\n') - f.write(OVERLAY.format(imageUrl=url, imageBounds=bounds_string)) - f.write(settings) + f.write(OVERLAY.format(imageUrl=url, imageBounds=bounds_string, settings=settings)) def write_fitbounds(self, f): From 5e41474585b3b2650f39fe6744866c014dc76d90 Mon Sep 17 00:00:00 2001 From: kenseii Date: Tue, 8 Oct 2019 19:24:01 +0900 Subject: [PATCH 09/10] writing the settings directly --- llplot/llplot.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/llplot/llplot.py b/llplot/llplot.py index 5338636..13e0442 100644 --- a/llplot/llplot.py +++ b/llplot/llplot.py @@ -240,15 +240,8 @@ def ground_overlay(self, imageUrl, imageBounds, opacity=1.0, alt='', settings['className'] = className # bounds_string = self._process_ground_overlay_image_bounds(imageBounds) - settings = self._process_ground_overlay_settings(settings) self.ground_overlays.append((imageUrl, imageBounds, settings)) - def _process_ground_overlay_settings(self, settings): - settings_string = '' - settings_string += "overlay.setOptions(%s);\n" % settings - - return settings_string - def polygon(self, lats, lngs, color=None, c=None, **kwargs): color = color or c kwargs.setdefault("color", color) From 5ac58000cc484ed5c86489c6a03c79e0490f3f1b Mon Sep 17 00:00:00 2001 From: kenseii Date: Tue, 8 Oct 2019 19:28:16 +0900 Subject: [PATCH 10/10] remove unnecessary google maps vars --- llplot/llplot.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/llplot/llplot.py b/llplot/llplot.py index 13e0442..6e4ee23 100644 --- a/llplot/llplot.py +++ b/llplot/llplot.py @@ -238,8 +238,6 @@ def ground_overlay(self, imageUrl, imageBounds, opacity=1.0, alt='', settings['errorOverlayUrl'] = errorOverlayUrl settings['zIndex'] = zIndex settings['className'] = className - # bounds_string = self._process_ground_overlay_image_bounds(imageBounds) - self.ground_overlays.append((imageUrl, imageBounds, settings)) def polygon(self, lats, lngs, color=None, c=None, **kwargs): @@ -511,13 +509,6 @@ def write_heatmap(self, f): def write_ground_overlay(self, f): for url, bounds_string, settings in self.ground_overlays: - # f.write(bounds_string) - # f.write('var groundOverlay;' + '\n') - # f.write('groundOverlay = new google.maps.GroundOverlay(' + '\n') - # f.write('\n') - # f.write("'" + url + "'," + '\n') - # f.write('imageBounds);' + '\n') - # f.write('groundOverlay.setMap(map);' + '\n') f.write(OVERLAY.format(imageUrl=url, imageBounds=bounds_string, settings=settings))