Skip to content

Commit 1bb6600

Browse files
committed
doctoring edits, and allow for data to be URL
1 parent 7c6b416 commit 1bb6600

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

folium/folium.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -954,26 +954,27 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
954954
way to overlay geospatial data on top of a map. If your data is high res, consider
955955
implementing a WMS server and adding a WMS layer.
956956
957-
This function works by using the imageio library to generate a PNG file in
957+
This function works by generating a PNG file from a numpy array. If you do not
958+
specifiy a filename, it will embed the image inline. Otherwise, it saves the file in the
958959
current directory, and then adds it as an image overlay layer in leaflet.js.
959960
By default, the image is placed and stretched using bounds that cover the
960961
entire globe.
961962
962963
Parameters
963964
----------
964-
data: numpy array, required.
965-
Must be a valid format for imageio.imwriter(), i.e., NxM (mono),
966-
NxMx3 (rgb), or NxMx4 (rgba)
965+
data: numpy array OR url string, required.
966+
if numpy array, must be a image format, i.e., NxM (mono), NxMx3 (rgb), or NxMx4 (rgba)
967+
if url, must be a valid url to a image (local or external)
967968
opacity: float, default 0.25
968-
image layer opacity in range 0 (completely transparent) to 1 (opaque)
969+
Image layer opacity in range 0 (completely transparent) to 1 (opaque)
969970
min_lat: float, default -90.0
970971
max_lat: float, default 90.0
971972
min_lon: float, default -180.0
972973
max_lon: float, default 180.0
973974
image_name: string, default None
974-
the name of the layer object in leaflet.js
975+
The name of the layer object in leaflet.js
975976
filename: string, default None
976-
optional file name of output.png for image overlay. If None, we use a
977+
Optional file name of output.png for image overlay. If None, we use a
977978
inline PNG.
978979
979980
Output
@@ -999,20 +1000,19 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
9991000
10001001
"""
10011002

1002-
# todo add URL
10031003
if isinstance(data, str):
1004-
raise NotImplementedError
1005-
1006-
try:
1007-
png_str = utilities.write_png(data)
1008-
except Exception as e:
1009-
raise e
1010-
1011-
if filename is not None:
1012-
with open(filename, 'wb') as fd:
1013-
fd.write(png_str)
1004+
filename = data
10141005
else:
1015-
filename = "data:image/png;base64,"+base64.b64encode(png_str).decode('utf-8')
1006+
try:
1007+
png_str = utilities.write_png(data)
1008+
except Exception as e:
1009+
raise e
1010+
1011+
if filename is not None:
1012+
with open(filename, 'wb') as fd:
1013+
fd.write(png_str)
1014+
else:
1015+
filename = "data:image/png;base64,"+base64.b64encode(png_str).decode('utf-8')
10161016

10171017
if image_name not in self.added_layers:
10181018
if image_name is None:
@@ -1031,7 +1031,6 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
10311031
'image_opacity': image_opacity})
10321032

10331033
self.template_vars['image_layers'].append(image)
1034-
# self.added_layers.append({image_name: image_url})
10351034
self.added_layers.append(image_name)
10361035

10371036
def _build_map(self, html_templ=None, templ_type='string'):

0 commit comments

Comments
 (0)