|
7 | 7 | import json
|
8 | 8 | import operator
|
9 | 9 | import warnings
|
10 |
| -from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Union |
| 10 | +from typing import ( |
| 11 | + Any, |
| 12 | + Callable, |
| 13 | + Dict, |
| 14 | + Iterable, |
| 15 | + List, |
| 16 | + Optional, |
| 17 | + Sequence, |
| 18 | + Tuple, |
| 19 | + Union, |
| 20 | +) |
11 | 21 |
|
12 | 22 | import numpy as np
|
13 | 23 | import requests
|
@@ -1992,3 +2002,54 @@ def __init__(
|
1992 | 2002 | out.setdefault(cm(color), []).append([[lat1, lng1], [lat2, lng2]])
|
1993 | 2003 | for key, val in out.items():
|
1994 | 2004 | self.add_child(PolyLine(val, color=key, weight=weight, opacity=opacity))
|
| 2005 | + |
| 2006 | + |
| 2007 | +class Control(JSCSSMixin, MacroElement): |
| 2008 | + """ |
| 2009 | + Add a Leaflet Control object to the map |
| 2010 | +
|
| 2011 | + Parameters |
| 2012 | + ---------- |
| 2013 | + control: str |
| 2014 | + The javascript class name of the control to be rendered. |
| 2015 | + position: str |
| 2016 | + One of "bottomright", "bottomleft", "topright", "topleft" |
| 2017 | +
|
| 2018 | + Examples |
| 2019 | + -------- |
| 2020 | +
|
| 2021 | + >>> import folium |
| 2022 | + >>> from folium.features import Control, Marker |
| 2023 | + >>> from folium.plugins import Geocoder |
| 2024 | +
|
| 2025 | + >>> m = folium.Map( |
| 2026 | + ... location=[46.603354, 1.8883335], attr=None, zoom_control=False, zoom_start=5 |
| 2027 | + ... ) |
| 2028 | + >>> Control("Zoom", position="topleft").add_to(m) |
| 2029 | + """ |
| 2030 | + |
| 2031 | + _template = Template( |
| 2032 | + """ |
| 2033 | + {% macro script(this, kwargs) %} |
| 2034 | + var {{ this.get_name() }} = new L.Control.{{this._name}}( |
| 2035 | + {% for arg in this.args %} |
| 2036 | + {{ arg | tojavascript }}, |
| 2037 | + {% endfor %} |
| 2038 | + {{ this.options|tojavascript }} |
| 2039 | + ).addTo({{ this._parent.get_name() }}); |
| 2040 | + {% endmacro %} |
| 2041 | + """ |
| 2042 | + ) |
| 2043 | + |
| 2044 | + def __init__( |
| 2045 | + self, |
| 2046 | + control: Optional[str] = None, |
| 2047 | + *args, |
| 2048 | + **kwargs, |
| 2049 | + ): |
| 2050 | + super().__init__() |
| 2051 | + if control: |
| 2052 | + self._name = control |
| 2053 | + |
| 2054 | + self.args = args |
| 2055 | + self.options = remove_empty(**kwargs) |
0 commit comments