|
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, PolyLine |
| 29 | + CircleMarker, LatLngPopup, ClickForMarker, ColorScale, TopoJson, PolyLine, MultiPolyLine |
30 | 30 | from .utilities import color_brewer |
31 | 31 | #import sys |
32 | 32 | #import base64 |
@@ -423,38 +423,60 @@ def line(self, locations, |
423 | 423 | p.add_children(Popup(popup, max_width=popup_width)) |
424 | 424 |
|
425 | 425 | self.add_children(p) |
426 | | -# @iter_obj('multiline') |
427 | | -# def multiline(self, locations, line_color=None, line_opacity=None, |
428 | | -# line_weight=None): |
429 | | -# """Add a multiPolyline to the map with optional styles. |
430 | | -# |
431 | | -# A multiPolyline is single layer that consists of several polylines that |
432 | | -# share styling/popup. |
433 | | -# |
434 | | -# Parameters |
435 | | -# ---------- |
436 | | -# locations: list of lists of points (latitude, longitude) |
437 | | -# Latitude and Longitude of line (Northing, Easting) |
438 | | -# line_color: string, default Leaflet's default ('#03f') |
439 | | -# line_opacity: float, default Leaflet's default (0.5) |
440 | | -# line_weight: float, default Leaflet's default (5) |
441 | | -# |
442 | | -# Note: If the optional styles are omitted, they will not be included |
443 | | -# in the HTML output and will obtain the Leaflet defaults listed above. |
444 | | -# |
445 | | -# Example |
446 | | -# ------- |
447 | | -# # FIXME: Add another example. |
448 | | -# >>> m.multiline(locations=[[(45.5236, -122.675), (45.5236, -122.675)], |
449 | | -# [(45.5237, -122.675), (45.5237, -122.675)], |
450 | | -# [(45.5238, -122.675), (45.5238, -122.675)]]) |
451 | | -# >>> m.multiline(locations=[[(45.5236, -122.675), (45.5236, -122.675)], |
452 | | -# [(45.5237, -122.675), (45.5237, -122.675)], |
453 | | -# [(45.5238, -122.675), (45.5238, -122.675)]], |
454 | | -# line_color='red', line_weight=2, |
455 | | -# line_opacity=1.0) |
456 | | -# """ |
457 | | -# |
| 426 | + |
| 427 | + def multiline(self, locations, line_color=None, line_opacity=None, |
| 428 | + line_weight=None, |
| 429 | + popup=None, popup_width=300, latlon=True): |
| 430 | + """Add a multiPolyline to the map with optional styles. |
| 431 | +
|
| 432 | + A multiPolyline is single layer that consists of several polylines that |
| 433 | + share styling/popup. |
| 434 | +
|
| 435 | + Parameters |
| 436 | + ---------- |
| 437 | + locations: list of lists of points (latitude, longitude) |
| 438 | + Latitude and Longitude of line (Northing, Easting) |
| 439 | + line_color: string, default Leaflet's default ('#03f') |
| 440 | + line_opacity: float, default Leaflet's default (0.5) |
| 441 | + line_weight: float, default Leaflet's default (5) |
| 442 | + popup: string or tuple, default 'Pop Text' |
| 443 | + Input text or visualization for object. Can pass either text, |
| 444 | + or a tuple of the form (Vincent object, 'vis_path.json') |
| 445 | + It is possible to adjust the width of text/HTML popups |
| 446 | + using the optional keywords `popup_width` (default is 300px). |
| 447 | + latlon: bool, default True |
| 448 | + Whether locations are given in the form [[lat,lon]] or not ([[lon,lat]] if False). |
| 449 | + Note that the default GeoJson format is latlon=False, |
| 450 | + while Leaflet polyline's default is latlon=True. |
| 451 | +
|
| 452 | + Note: If the optional styles are omitted, they will not be included |
| 453 | + in the HTML output and will obtain the Leaflet defaults listed above. |
| 454 | +
|
| 455 | + Example |
| 456 | + ------- |
| 457 | + # FIXME: Add another example. |
| 458 | + >>> m.multiline(locations=[[(45.5236, -122.675), (45.5236, -122.675)], |
| 459 | + [(45.5237, -122.675), (45.5237, -122.675)], |
| 460 | + [(45.5238, -122.675), (45.5238, -122.675)]]) |
| 461 | + >>> m.multiline(locations=[[(45.5236, -122.675), (45.5236, -122.675)], |
| 462 | + [(45.5237, -122.675), (45.5237, -122.675)], |
| 463 | + [(45.5238, -122.675), (45.5238, -122.675)]], |
| 464 | + line_color='red', line_weight=2, |
| 465 | + line_opacity=1.0) |
| 466 | + """ |
| 467 | + |
| 468 | + p = MultiPolyLine(locations, |
| 469 | + color=line_color, |
| 470 | + weight=line_weight, |
| 471 | + opacity=line_opacity, |
| 472 | + latlon=latlon, |
| 473 | + ) |
| 474 | + |
| 475 | + if popup is not None: |
| 476 | + p.add_children(Popup(popup, max_width=popup_width)) |
| 477 | + |
| 478 | + self.add_children(p) |
| 479 | + |
458 | 480 | # count = self.mark_cnt['multiline'] |
459 | 481 | # |
460 | 482 | # multiline_temp = self.env.get_template('multi_polyline.js') |
|
0 commit comments