@@ -359,7 +359,8 @@ def simple_marker(self, location=None, popup=None,
359
359
self .template_vars .setdefault (name , []).append (append )
360
360
361
361
@iter_obj ('div_mark' )
362
- def div_markers (self , locations = None , popups = None , marker_size = 10 , popup_width = 300 ):
362
+ def div_markers (self , locations = None , popups = None ,
363
+ marker_size = 10 , popup_width = 300 ):
363
364
"""Create a simple div marker on the map, with optional
364
365
popup text or Vincent visualization. Useful for marking points along a
365
366
line.
@@ -368,11 +369,13 @@ def div_markers(self, locations=None, popups=None, marker_size=10, popup_width=3
368
369
----------
369
370
locations: list of locations, where each location is an array
370
371
Latitude and Longitude of Marker (Northing, Easting)
371
- popup: list of popups, each popup should be a string or tuple, default 'Pop Text'
372
+ popup: list of popups, each popup should be a string or tuple.
373
+ Default 'Pop Text'
372
374
Input text or visualization for object. Can pass either text,
373
375
or a tuple of the form (Vincent object, 'vis_path.json')
374
376
It is possible to adjust the width of text/HTML popups
375
- using the optional keywords `popup_width`. (Leaflet default is 300px.)
377
+ using the optional keywords `popup_width`.
378
+ (Leaflet default is 300px.)
376
379
marker_size
377
380
default is 5
378
381
@@ -382,13 +385,19 @@ def div_markers(self, locations=None, popups=None, marker_size=10, popup_width=3
382
385
383
386
Example
384
387
-------
385
- >>>map.div_markers(locations=[[37.421114, -122.128314], [37.391637, -122.085416], [37.388832, -122.087709]], popups=['1437494575531', '1437492135937', '1437493590434'])
388
+ >>> map.div_markers(locations=[[37.421114, -122.128314],
389
+ ... [37.391637, -122.085416],
390
+ ... [37.388832, -122.087709]],
391
+ ... popups=['1437494575531',
392
+ ... '1437492135937',
393
+ ... '1437493590434'])
386
394
387
395
"""
388
396
call_cnt = self .mark_cnt ['div_mark' ]
389
397
if locations is None or popups is None :
390
398
raise RuntimeError ("Both locations and popups are mandatory" )
391
- for (point_cnt , (location , popup )) in enumerate (zip (locations , popups )):
399
+ for (point_cnt , (location , popup )) in enumerate (zip (locations ,
400
+ popups )):
392
401
marker_num = 'div_marker_{0}_{1}' .format (call_cnt , point_cnt )
393
402
394
403
icon_temp = self .env .get_template ('static_div_icon.js' )
@@ -404,9 +413,12 @@ def div_markers(self, locations=None, popups=None, marker_size=10, popup_width=3
404
413
'icon' : "{'icon':" + icon_name + "}"
405
414
})
406
415
407
- popup_out = self ._popup_render (popup = popup , mk_name = 'div_marker_{0}_' .format (call_cnt ),
416
+ div_marker = 'div_marker_{0}_' .format
417
+ popup_out = self ._popup_render (popup = popup ,
418
+ mk_name = div_marker (call_cnt ),
408
419
count = point_cnt , width = popup_width )
409
- add_mark = 'map.addLayer(div_marker_{0}_{1})' .format (call_cnt , point_cnt )
420
+ add_mark = 'map.addLayer(div_marker_{0}_{1})' .format (call_cnt ,
421
+ point_cnt )
410
422
append = (icon , marker , popup_out , add_mark )
411
423
self .template_vars .setdefault ('div_markers' , []).append (append )
412
424
@@ -716,8 +728,8 @@ def add_plugin(self, plugin):
716
728
Parameters
717
729
----------
718
730
plugin: folium.plugins object
719
- A plugin to be added to the map. It has to implement the methods
720
- `render_html`, `render_css` and `render_js`.
731
+ A plugin to be added to the map. It has to implement the
732
+ methods `render_html`, `render_css` and `render_js`.
721
733
"""
722
734
plugin .add_to_map (self )
723
735
@@ -1016,33 +1028,37 @@ def json_style(style_cnt, line_color, line_weight, line_opacity,
1016
1028
1017
1029
@iter_obj ('image_overlay' )
1018
1030
def image_overlay (self , data , opacity = 0.25 , min_lat = - 90.0 , max_lat = 90.0 ,
1019
- min_lon = - 180.0 , max_lon = 180.0 , image_name = None , filename = None ):
1020
- """Simple image overlay of raster data from a numpy array. This is a lightweight
1021
- way to overlay geospatial data on top of a map. If your data is high res, consider
1022
- implementing a WMS server and adding a WMS layer.
1031
+ min_lon = - 180.0 , max_lon = 180.0 , image_name = None ,
1032
+ filename = None ):
1033
+ """
1034
+ Simple image overlay of raster data from a numpy array. This is a
1035
+ lightweight way to overlay geospatial data on top of a map. If your
1036
+ data is high res, consider implementing a WMS server and adding a WMS
1037
+ layer.
1023
1038
1024
- This function works by generating a PNG file from a numpy array. If you do not
1025
- specifiy a filename, it will embed the image inline. Otherwise, it saves the file in the
1026
- current directory, and then adds it as an image overlay layer in leaflet.js.
1027
- By default, the image is placed and stretched using bounds that cover the
1028
- entire globe.
1039
+ This function works by generating a PNG file from a numpy array. If
1040
+ you do not specify a filename, it will embed the image inline.
1041
+ Otherwise, it saves the file in the current directory, and then adds
1042
+ it as an image overlay layer in leaflet.js. By default, the image is
1043
+ placed and stretched using bounds that cover the entire globe.
1029
1044
1030
1045
Parameters
1031
1046
----------
1032
- data: numpy array OR url string, required.
1033
- if numpy array, must be a image format, i.e., NxM (mono), NxMx3 (rgb), or NxMx4 (rgba)
1047
+ data: numpy array OR url string, required.
1048
+ if numpy array, must be a image format,
1049
+ i.e., NxM (mono), NxMx3 (rgb), or NxMx4 (rgba)
1034
1050
if url, must be a valid url to a image (local or external)
1035
1051
opacity: float, default 0.25
1036
- Image layer opacity in range 0 (completely transparent) to 1 (opaque)
1052
+ Image layer opacity in range 0 (transparent) to 1 (opaque)
1037
1053
min_lat: float, default -90.0
1038
1054
max_lat: float, default 90.0
1039
1055
min_lon: float, default -180.0
1040
1056
max_lon: float, default 180.0
1041
1057
image_name: string, default None
1042
1058
The name of the layer object in leaflet.js
1043
1059
filename: string, default None
1044
- Optional file name of output.png for image overlay. If None, we use a
1045
- inline PNG.
1060
+ Optional file name of output.png for image overlay.
1061
+ Use `None` for inline PNG.
1046
1062
1047
1063
Output
1048
1064
------
@@ -1053,18 +1069,17 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
1053
1069
# assumes a map object `m` has been created
1054
1070
>>> import numpy as np
1055
1071
>>> data = np.random.random((100,100))
1056
-
1072
+
1057
1073
# to make a rgba from a specific matplotlib colormap:
1058
1074
>>> import matplotlib.cm as cm
1059
1075
>>> cmapper = cm.cm.ColorMapper('jet')
1060
1076
>>> data2 = cmapper.to_rgba(np.random.random((100,100)))
1061
-
1062
- # place the data over all of the globe (will be pretty pixelated!)
1077
+ >>> # Place the data over all of the globe (will be pretty pixelated!)
1063
1078
>>> m.image_overlay(data)
1079
+ >>> # Put it only over a single city (Paris).
1080
+ >>> m.image_overlay(data, min_lat=48.80418, max_lat=48.90970,
1081
+ ... min_lon=2.25214, max_lon=2.44731)
1064
1082
1065
- # put it only over a single city (Paris)
1066
- >>> m.image_overlay(data, min_lat=48.80418, max_lat=48.90970, min_lon=2.25214, max_lon=2.44731)
1067
-
1068
1083
"""
1069
1084
1070
1085
if isinstance (data , str ):
@@ -1079,7 +1094,8 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
1079
1094
with open (filename , 'wb' ) as fd :
1080
1095
fd .write (png_str )
1081
1096
else :
1082
- filename = "data:image/png;base64," + base64 .b64encode (png_str ).decode ('utf-8' )
1097
+ png = "data:image/png;base64,{}" .format
1098
+ filename = png (base64 .b64encode (png_str ).decode ('utf-8' ))
1083
1099
1084
1100
if image_name not in self .added_layers :
1085
1101
if image_name is None :
@@ -1089,7 +1105,7 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
1089
1105
image_url = filename
1090
1106
image_bounds = [[min_lat , min_lon ], [max_lat , max_lon ]]
1091
1107
image_opacity = opacity
1092
-
1108
+
1093
1109
image_temp = self .env .get_template ('image_layer.js' )
1094
1110
1095
1111
image = image_temp .render ({'image_name' : image_name ,
@@ -1099,7 +1115,7 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
1099
1115
1100
1116
self .template_vars ['image_layers' ].append (image )
1101
1117
self .added_layers .append (image_name )
1102
-
1118
+
1103
1119
def _build_map (self , html_templ = None , templ_type = 'string' ):
1104
1120
self ._auto_bounds ()
1105
1121
"""Build HTML/JS/CSS from Templates given current map type."""
0 commit comments