@@ -954,26 +954,27 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
954
954
way to overlay geospatial data on top of a map. If your data is high res, consider
955
955
implementing a WMS server and adding a WMS layer.
956
956
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
958
959
current directory, and then adds it as an image overlay layer in leaflet.js.
959
960
By default, the image is placed and stretched using bounds that cover the
960
961
entire globe.
961
962
962
963
Parameters
963
964
----------
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 )
967
968
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)
969
970
min_lat: float, default -90.0
970
971
max_lat: float, default 90.0
971
972
min_lon: float, default -180.0
972
973
max_lon: float, default 180.0
973
974
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
975
976
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
977
978
inline PNG.
978
979
979
980
Output
@@ -999,20 +1000,19 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
999
1000
1000
1001
"""
1001
1002
1002
- # todo add URL
1003
1003
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
1014
1005
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' )
1016
1016
1017
1017
if image_name not in self .added_layers :
1018
1018
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,
1031
1031
'image_opacity' : image_opacity })
1032
1032
1033
1033
self .template_vars ['image_layers' ].append (image )
1034
- # self.added_layers.append({image_name: image_url})
1035
1034
self .added_layers .append (image_name )
1036
1035
1037
1036
def _build_map (self , html_templ = None , templ_type = 'string' ):
0 commit comments