|
26 | 26 | from .element import Element, Figure, JavascriptLink, CssLink, Div, MacroElement |
27 | 27 | from .map import Map, TileLayer, Icon, Marker, Popup |
28 | 28 | from .features import WmsTileLayer, RegularPolygonMarker, Vega, GeoJson, GeoJsonStyle, MarkerCluster, DivIcon,\ |
29 | | - CircleMarker, LatLngPopup, ClickForMarker, ColorScale, TopoJson |
| 29 | + CircleMarker, LatLngPopup, ClickForMarker, ColorScale, TopoJson, PolyLine |
30 | 30 | from .utilities import color_brewer |
31 | 31 | #import sys |
32 | 32 | #import base64 |
@@ -378,55 +378,51 @@ def div_markers(self, locations=None, popups=None, |
378 | 378 | popup = Popup(popup), |
379 | 379 | icon = DivIcon(width=marker_size, height=marker_size)) |
380 | 380 | self.add_children(marker) |
381 | | -# |
382 | | -# @iter_obj('line') |
383 | | -# def line(self, locations, |
384 | | -# line_color=None, line_opacity=None, line_weight=None, |
385 | | -# popup=None, popup_width=300): |
386 | | -# """Add a line to the map with optional styles. |
387 | | -# |
388 | | -# Parameters |
389 | | -# ---------- |
390 | | -# locations: list of points (latitude, longitude) |
391 | | -# Latitude and Longitude of line (Northing, Easting) |
392 | | -# line_color: string, default Leaflet's default ('#03f') |
393 | | -# line_opacity: float, default Leaflet's default (0.5) |
394 | | -# line_weight: float, default Leaflet's default (5) |
395 | | -# popup: string or tuple, default 'Pop Text' |
396 | | -# Input text or visualization for object. Can pass either text, |
397 | | -# or a tuple of the form (Vincent object, 'vis_path.json') |
398 | | -# It is possible to adjust the width of text/HTML popups |
399 | | -# using the optional keywords `popup_width` (default is 300px). |
400 | | -# |
401 | | -# Note: If the optional styles are omitted, they will not be included |
402 | | -# in the HTML output and will obtain the Leaflet defaults listed above. |
403 | | -# |
404 | | -# Example |
405 | | -# ------- |
406 | | -# >>>map.line(locations=[(45.5, -122.3), (42.3, -71.0)]) |
407 | | -# >>>map.line(locations=[(45.5, -122.3), (42.3, -71.0)], |
408 | | -# line_color='red', line_opacity=1.0) |
409 | | -# |
410 | | -# """ |
411 | | -# count = self.mark_cnt['line'] |
412 | | -# |
413 | | -# line_temp = self.env.get_template('polyline.js') |
414 | | -# |
415 | | -# polyline_opts = {'color': line_color, 'weight': line_weight, |
416 | | -# 'opacity': line_opacity} |
417 | | -# |
418 | | -# varname = 'line_{}'.format(count) |
419 | | -# line_rendered = line_temp.render({'line': varname, |
420 | | -# 'locations': locations, |
421 | | -# 'options': polyline_opts}) |
422 | | -# |
423 | | -# popup_out = self._popup_render(popup=popup, mk_name='line_', |
424 | | -# count=count, width=popup_width) |
425 | | -# |
426 | | -# add_line = 'map.addLayer({});'.format(varname) |
427 | | -# append = (line_rendered, popup_out, add_line) |
428 | | -# self.template_vars.setdefault('lines', []).append((append)) |
429 | | -# |
| 381 | + |
| 382 | + def line(self, locations, |
| 383 | + line_color=None, line_opacity=None, line_weight=None, |
| 384 | + popup=None, popup_width=300, latlon=True): |
| 385 | + """Add a line to the map with optional styles. |
| 386 | +
|
| 387 | + Parameters |
| 388 | + ---------- |
| 389 | + locations: list of points (latitude, longitude) |
| 390 | + Latitude and Longitude of line (Northing, Easting) |
| 391 | + line_color: string, default Leaflet's default ('#03f') |
| 392 | + line_opacity: float, default Leaflet's default (0.5) |
| 393 | + line_weight: float, default Leaflet's default (5) |
| 394 | + popup: string or tuple, default 'Pop Text' |
| 395 | + Input text or visualization for object. Can pass either text, |
| 396 | + or a tuple of the form (Vincent object, 'vis_path.json') |
| 397 | + It is possible to adjust the width of text/HTML popups |
| 398 | + using the optional keywords `popup_width` (default is 300px). |
| 399 | + latlon: bool, default True |
| 400 | + Whether locations are given in the form [[lat,lon]] or not ([[lon,lat]] if False). |
| 401 | + Note that the default GeoJson format is latlon=False, |
| 402 | + while Leaflet polyline's default is latlon=True. |
| 403 | +
|
| 404 | + Note: If the optional styles are omitted, they will not be included |
| 405 | + in the HTML output and will obtain the Leaflet defaults listed above. |
| 406 | +
|
| 407 | + Example |
| 408 | + ------- |
| 409 | + >>>map.line(locations=[(45.5, -122.3), (42.3, -71.0)]) |
| 410 | + >>>map.line(locations=[(45.5, -122.3), (42.3, -71.0)], |
| 411 | + line_color='red', line_opacity=1.0) |
| 412 | +
|
| 413 | + """ |
| 414 | + |
| 415 | + p = PolyLine(locations, |
| 416 | + color=line_color, |
| 417 | + weight=line_weight, |
| 418 | + opacity=line_opacity, |
| 419 | + latlon=latlon, |
| 420 | + ) |
| 421 | + |
| 422 | + if popup is not None: |
| 423 | + p.add_children(Popup(popup, max_width=popup_width)) |
| 424 | + |
| 425 | + self.add_children(p) |
430 | 426 | # @iter_obj('multiline') |
431 | 427 | # def multiline(self, locations, line_color=None, line_opacity=None, |
432 | 428 | # line_weight=None): |
|
0 commit comments