10
10
from __future__ import absolute_import
11
11
from __future__ import print_function
12
12
from __future__ import division
13
+
13
14
import codecs
14
- import json
15
15
import functools
16
+ import json
16
17
import os
18
+ from uuid import uuid4
19
+
17
20
from jinja2 import Environment , PackageLoader
18
21
from pkg_resources import resource_string , resource_filename
19
- from uuid import uuid4
22
+
20
23
from folium import utilities
21
24
from folium .six import text_type , binary_type , iteritems
22
25
@@ -173,7 +176,8 @@ def __init__(self, location=None, width=960, height=500,
173
176
if isinstance (attr , binary_type ):
174
177
attr = text_type (attr , 'utf8' )
175
178
self .template_vars ['attr' ] = attr
176
- self .tile_types .update ({'Custom' : {'template' : tiles , 'attr' : attr }})
179
+ self .tile_types .update ({'Custom' : {'template' : tiles ,
180
+ 'attr' : attr }})
177
181
178
182
self .added_layers = []
179
183
self .template_vars .setdefault ('wms_layers' , [])
@@ -205,7 +209,8 @@ def add_tile_layer(self, tile_name=None,tile_url=None,active=False):
205
209
206
210
207
211
@iter_obj ('simple' )
208
- def add_wms_layer (self , wms_name = None ,wms_url = None ,wms_format = None ,wms_layers = None ,wms_transparent = True ):
212
+ def add_wms_layer (self , wms_name = None , wms_url = None , wms_format = None ,
213
+ wms_layers = None , wms_transparent = True ):
209
214
'''adds a simple tile layer
210
215
Parameters
211
216
----------
@@ -218,12 +223,12 @@ def add_wms_layer(self, wms_name=None,wms_url=None,wms_format=None,wms_layers=No
218
223
wms_name = wms_name .replace (" " , "_" )
219
224
wms_temp = self .env .get_template ('wms_layer.js' )
220
225
221
- wms = wms_temp .render ({'wms_name' : wms_name ,
222
- 'wms_url ' : wms_url ,
223
- 'wms_format ' : wms_format ,
224
- 'wms_layer_names' : wms_layers ,
225
- 'wms_transparent' : str ( wms_transparent ). lower ()
226
- })
226
+ wms = wms_temp .render ({
227
+ 'wms_name ' : wms_name ,
228
+ 'wms_url ' : wms_url ,
229
+ 'wms_format' : wms_format ,
230
+ 'wms_layer_names' : wms_layers ,
231
+ 'wms_transparent' : str ( wms_transparent ). lower () })
227
232
228
233
self .template_vars .setdefault ('wms_layers' , []).append ((wms ))
229
234
@@ -237,7 +242,7 @@ def add_layers_to_map(self):
237
242
layers_temp = self .env .get_template ('add_layers.js' )
238
243
239
244
data_string = ''
240
- for i , layer in enumerate (self .added_layers ):
245
+ for i , layer in enumerate (self .added_layers ):
241
246
name = layer .keys ()[0 ]
242
247
data_string += '\" '
243
248
data_string += name
@@ -247,13 +252,15 @@ def add_layers_to_map(self):
247
252
if i < len (self .added_layers )- 1 :
248
253
data_string += ",\n "
249
254
else :
250
- data_string += "\n "
255
+ data_string += "\n "
251
256
252
257
data_layers = layers_temp .render ({'layers' : data_string })
253
258
self .template_vars .setdefault ('data_layers' , []).append ((data_string ))
254
259
255
260
@iter_obj ('simple' )
256
- def simple_marker (self , location = None , popup = 'Pop Text' , popup_on = True ,marker_color = 'blue' ,marker_icon = 'info-sign' ,clustered_marker = False ,icon_angle = 0 ):
261
+ def simple_marker (self , location = None , popup = 'Pop Text' , popup_on = True ,
262
+ marker_color = 'blue' , marker_icon = 'info-sign' ,
263
+ clustered_marker = False , icon_angle = 0 ):
257
264
'''Create a simple stock Leaflet marker on the map, with optional
258
265
popup text or Vincent visualization.
259
266
@@ -271,7 +278,8 @@ def simple_marker(self, location=None, popup='Pop Text', popup_on=True,marker_co
271
278
marker_icon
272
279
icon from (http://getbootstrap.com/components/) you want on the marker
273
280
clustered_marker
274
- boolean of whether or not you want the marker clustered with other markers
281
+ boolean of whether or not you want the marker clustered with
282
+ other markers
275
283
276
284
Returns
277
285
-------
@@ -299,7 +307,7 @@ def simple_marker(self, location=None, popup='Pop Text', popup_on=True,marker_co
299
307
300
308
#Get marker and popup
301
309
marker = mark_temp .render ({'marker' : 'marker_' + str (count ),
302
- 'lat' : location [0 ],
310
+ 'lat' : location [0 ],
303
311
'lon' : location [1 ],
304
312
'icon' : add_line
305
313
})
@@ -308,7 +316,7 @@ def simple_marker(self, location=None, popup='Pop Text', popup_on=True,marker_co
308
316
count = count ,
309
317
popup_on = popup_on )
310
318
311
-
319
+
312
320
313
321
if clustered_marker :
314
322
add_mark = 'clusteredmarkers.addLayer(marker_{0})' .format (count )
@@ -661,16 +669,19 @@ def geo_json(self, geo_path=None, geo_str=None, data_out='data.json',
661
669
662
670
Example
663
671
-------
664
- >>>map.geo_json(geo_path='us-states.json', line_color='blue', line_weight=3)
665
- >>>map.geo_json(geo_path='geo.json', data=df, columns=['Data 1', 'Data 2'],
672
+ >>>map.geo_json(geo_path='us-states.json', line_color='blue',
673
+ line_weight=3)
674
+ >>>map.geo_json(geo_path='geo.json', data=df,
675
+ columns=['Data 1', 'Data 2'],
666
676
key_on='feature.properties.myvalue', fill_color='PuBu',
667
677
threshold_scale=[0, 20, 30, 40, 50, 60])
668
678
>>>map.geo_json(geo_path='countries.json', topojson='objects.countries')
669
679
'''
670
680
671
681
if reset :
672
- reset_vars = ['json_paths' , 'func_vars' , 'color_scales' , 'geo_styles' ,
673
- 'gjson_layers' , 'map_legends' , 'topo_convert' ]
682
+ reset_vars = ['json_paths' , 'func_vars' , 'color_scales' ,
683
+ 'geo_styles' , 'gjson_layers' , 'map_legends' ,
684
+ 'topo_convert' ]
674
685
for var in reset_vars :
675
686
self .template_vars .update ({var : []})
676
687
self .mark_cnt ['geojson' ] = 1
0 commit comments