Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llplot/google_maps_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@

""" % EARTH_RADIUS

OVERLAY = """
var imageUrl = "{imageUrl}",
imageBounds = {imageBounds};
var overlay = L.imageOverlay(imageUrl, imageBounds, {settings}).addTo(llMap);
"""

# FIXME: This generate a Xmark in cartesian frame rather than in lat/long.
CROSS = """
Expand Down
56 changes: 25 additions & 31 deletions llplot/llplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down Expand Up @@ -213,33 +213,32 @@ def _process_heatmap_kwargs(self, settings_dict):

return settings_string

def ground_overlay(self, url, bounds_dict):
def ground_overlay(self, imageUrl, imageBounds, opacity=1.0, alt='',
interactive=0, crossOrigin=0, errorOverlayUrl='',
zIndex=1, className=''):
'''
: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))

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']

return bounds_string
settings = {}
settings['opacity'] = opacity
settings['alt'] = alt
settings['interactive'] = interactive
settings['crossOrigin'] = crossOrigin
settings['errorOverlayUrl'] = errorOverlayUrl
settings['zIndex'] = zIndex
settings['className'] = className
self.ground_overlays.append((imageUrl, imageBounds, settings))

def polygon(self, lats, lngs, color=None, c=None, **kwargs):
color = color or c
Expand Down Expand Up @@ -282,7 +281,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('</script>\n')
Expand Down Expand Up @@ -509,14 +508,9 @@ 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')
for url, bounds_string, settings in self.ground_overlays:
f.write(OVERLAY.format(imageUrl=url, imageBounds=bounds_string, settings=settings))


def write_fitbounds(self, f):
if self.bounding_box is None:
Expand Down