Base Interface to create folium objects from encoded strings. Derived classes must define `_encoding_type` property which returns the string representation of the folium object to create from the encoded string. Parameters ---------- encoded: str The raw encoded string
| 7 | |
| 8 | |
| 9 | class _BaseFromEncoded(JSCSSMixin, MacroElement, ABC): |
| 10 | """Base Interface to create folium objects from encoded strings. |
| 11 | |
| 12 | Derived classes must define `_encoding_type` property which returns the string |
| 13 | representation of the folium object to create from the encoded string. |
| 14 | |
| 15 | Parameters |
| 16 | ---------- |
| 17 | encoded: str |
| 18 | The raw encoded string from the Polyline Encoding Algorithm. See: |
| 19 | https://developers.google.com/maps/documentation/utilities/polylinealgorithm |
| 20 | **kwargs: |
| 21 | Object options as accepted by leaflet. |
| 22 | """ |
| 23 | |
| 24 | _template = Template( |
| 25 | """ |
| 26 | {% macro script(this, kwargs) %} |
| 27 | |
| 28 | var {{ this.get_name() }} = L.{{ this._encoding_type }}.fromEncoded( |
| 29 | {{ this.encoded|tojson }}, |
| 30 | {{ this.options|tojavascript }} |
| 31 | ).addTo({{ this._parent.get_name() }}); |
| 32 | |
| 33 | {% endmacro %} |
| 34 | """ |
| 35 | ) |
| 36 | |
| 37 | default_js = [ |
| 38 | ( |
| 39 | "polyline-encoded", |
| 40 | "https://cdn.jsdelivr.net/npm/polyline-encoded@0.0.9/Polyline.encoded.js", |
| 41 | ) |
| 42 | ] |
| 43 | |
| 44 | def __init__(self, encoded: str): |
| 45 | super().__init__() |
| 46 | self.encoded = encoded |
| 47 | |
| 48 | @property |
| 49 | @abstractmethod |
| 50 | def _encoding_type(self) -> str: |
| 51 | """An abstract getter to return the type of folium object to create.""" |
| 52 | raise NotImplementedError |
| 53 | |
| 54 | |
| 55 | class PolyLineFromEncoded(_BaseFromEncoded): |
nothing calls this directly
no test coverage detected
searching dependent graphs…