@@ -736,7 +736,7 @@ def _popup_render(self, popup=None, mk_name=None, count=None,
736736 else :
737737 width += 75
738738 height += 50
739- max_width = self .map_size ['width' ]
739+ max_width = max ([ self .map_size ['width' ], width ])
740740 vega_id = '#' + div_id
741741 popup_temp = self .env .get_template ('vega_marker.js' )
742742 return popup_temp .render ({'mark' : mark , 'div_id' : div_id ,
@@ -951,16 +951,16 @@ def json_style(style_cnt, line_color, line_weight, line_opacity,
951951 self .template_vars .setdefault ('gjson_layers' , []).append (layer )
952952
953953 @iter_obj ('image_overlay' )
954- def image_overlay (self , data , opacity = 0.25 , min_lat = - 90.0 , max_lat = 90.0 ,
955- min_lon = - 180.0 , max_lon = 180.0 , image_name = None , filename = None ,
956- data_projection = 'mercator' ):
954+ def image_overlay (self , data , opacity = 0.75 , min_lat = - 90.0 , max_lat = 90.0 ,
955+ min_lon = - 180.0 , max_lon = 180.0 , image_name = None ,
956+ filename = None , data_projection = 'mercator' ):
957957 """Simple image overlay of raster data from a numpy array. This is a
958958 lightweight way to overlay geospatial data on top of a map.
959959 If your data is high res, consider implementing a WMS server
960960 and adding a WMS layer.
961961
962962 This function works by generating a PNG file from a numpy
963- array. If you do not specifiy a filename, it will embed the
963+ array. If you do not specify a filename, it will embed the
964964 image inline. Otherwise, it saves the file in the current
965965 directory, and then adds it as an image overlay layer in
966966 leaflet.js. By default, the image is placed and stretched
@@ -972,50 +972,47 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
972972
973973 Parameters
974974 ----------
975- data: numpy array OR url string, required.
976- if numpy array, must be a image format, i.e., NxM (mono), NxMx3 (rgb), or NxMx4 (rgba)
975+ data: numpy array OR url string, required.
976+ if numpy array, must be a image format,
977+ i.e., NxM (mono), NxMx3 (RGB), or NxMx4 (RGBA)
977978 if url, must be a valid url to a image (local or external)
978- opacity: float, default 0.25
979- Image layer opacity in range 0 (completely transparent) to 1 (opaque)
979+ opacity: float, default 0.75
980+ Image layer opacity in range 0 (transparent) to 1 (opaque)
980981 min_lat: float, default -90.0
981982 max_lat: float, default 90.0
982983 min_lon: float, default -180.0
983984 max_lon: float, default 180.0
984985 image_name: string, default None
985986 The name of the layer object in leaflet.js
986987 filename: string or None, default None
987- Optional file name of output.png for image overlay. If None, we use a
988- inline PNG.
988+ Optional file name of output.png for image overlay.
989+ If None, we use a inline PNG.
989990 data_projection: string or None, default 'mercator'
990991 Used to specify projection of image. If None, do no projection
991-
992+
992993 Output
993994 ------
994995 Image overlay data layer in obj.template_vars
995996
996997 Examples
997998 -------
998- # assumes a map object `m` has been created
999+ # Assumes a map object `m` has been created.
9991000 >>> import numpy as np
10001001 >>> data = np.random.random((180,360))
1001-
1002- # to make a rgba from a specific matplotlib colormap:
1003- >>> import matplotlib.cm as cm
1004- >>> cmapper = cm.cm.ColorMapper('jet')
1005- >>> data2 = cmapper.to_rgba(np.random.random((100,100)))
10061002
1007- # place the data over all of the globe (will be pretty pixelated!)
1003+ # Place the data over all of the globe (will be pretty pixelated!)
10081004 >>> m.image_overlay(data)
10091005
1010- # put it only over a single city (Paris)
1011- >>> m.image_overlay(data, min_lat=48.80418, max_lat=48.90970, min_lon=2.25214, max_lon=2.44731)
1006+ # Put it only over a single city (Paris)
1007+ >>> m.image_overlay(data, min_lat=48.80418, max_lat=48.90970,
1008+ ... min_lon=2.25214, max_lon=2.44731)
10121009
10131010 """
10141011 if isinstance (data , str ):
10151012 filename = data
10161013 else :
10171014 assert data_projection in [None , 'mercator' ]
1018- # this assumes a lat x long array
1015+ # This assumes a lat x long array.
10191016 # with 2x as many points in long as lat dims.
10201017 if data_projection is 'mercator' :
10211018 data = utilities .geodetic_to_mercator (data )
@@ -1028,7 +1025,8 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
10281025 with open (filename , 'wb' ) as fd :
10291026 fd .write (png_str )
10301027 else :
1031- filename = "data:image/png;base64," + base64 .b64encode (png_str ).decode ('utf-8' )
1028+ png = "data:image/png;base64,{}" .format
1029+ filename = png (base64 .b64encode (png_str ).decode ('utf-8' ))
10321030
10331031 if image_name not in self .added_layers :
10341032 if image_name is None :
@@ -1038,7 +1036,7 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
10381036 image_url = filename
10391037 image_bounds = [[min_lat , min_lon ], [max_lat , max_lon ]]
10401038 image_opacity = opacity
1041-
1039+
10421040 image_temp = self .env .get_template ('image_layer.js' )
10431041
10441042 image = image_temp .render ({'image_name' : image_name ,
@@ -1048,7 +1046,7 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
10481046
10491047 self .template_vars ['image_layers' ].append (image )
10501048 self .added_layers .append (image_name )
1051-
1049+
10521050 def _build_map (self , html_templ = None , templ_type = 'string' ):
10531051 self ._auto_bounds ()
10541052 """Build HTML/JS/CSS from Templates given current map type."""
0 commit comments