Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Antpath #1016

Merged
merged 9 commits into from
Dec 30, 2018
Merged

Antpath #1016

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
218 changes: 218 additions & 0 deletions examples/PolyLineTextPath_AntPath.ipynb

Large diffs are not rendered by default.

183 changes: 0 additions & 183 deletions examples/Polyline_text_path.ipynb

This file was deleted.

2 changes: 2 additions & 0 deletions folium/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from __future__ import (absolute_import, division, print_function)

from folium.plugins.antpath import AntPath
from folium.plugins.beautify_icon import BeautifyIcon
from folium.plugins.boat_marker import BoatMarker
from folium.plugins.draw import Draw
Expand All @@ -32,6 +33,7 @@
from folium.plugins.timestamped_wmstilelayer import TimestampedWmsTileLayers

__all__ = [
'AntPath',
'BeautifyIcon',
'BoatMarker',
'Draw',
Expand Down
79 changes: 79 additions & 0 deletions folium/plugins/antpath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-

from __future__ import (absolute_import, division, print_function)

import json

from branca.element import Figure, JavascriptLink

from folium import Marker
from folium.vector_layers import path_options

from jinja2 import Template


class AntPath(Marker):
"""
Class for drawing AntPath polyline overlays on a map.

See :func:`folium.vector_layers.path_options` for the `Path` options.

Parameters
----------
locations: list of points (latitude, longitude)
Latitude and Longitude of line (Northing, Easting)
popup: str or folium.Popup, default None
Input text or visualization for object displayed when clicking.
tooltip: str or folium.Tooltip, optional
Display a text when hovering over the object.
**kwargs:
Polyline and AntPath options. See their Github page for the
available parameters.

https://github.com/rubenspgcavalcante/leaflet-ant-path/

"""
_template = Template(u"""
{% macro script(this, kwargs) %}
{{this.get_name()}} = L.polyline.antPath(
{{this.location}},
{{ this.options }}
)
.addTo({{this._parent.get_name()}});
{% endmacro %}
""") # noqa

def __init__(self, locations, popup=None, tooltip=None, **kwargs):
super(AntPath, self).__init__(
location=locations,
popup=popup,
tooltip=tooltip,
)

self._name = 'AntPath'
# Polyline + AntPath defaults.
options = path_options(line=True, **kwargs)
options.update({
'paused': kwargs.pop('paused', False),
'reverse': kwargs.pop('reverse', False),
'hardwareAcceleration': kwargs.pop('hardware_acceleration', False),
'delay': kwargs.pop('delay', 400),
'dashArray': kwargs.pop('dash_array', [10, 20]),
'weight': kwargs.pop('weight', 5),
'opacity': kwargs.pop('opacity', 0.5),
'color': kwargs.pop('color', '#0000FF'),
'pulseColor': kwargs.pop('pulse_color', '#FFFFFF'),
})
self.options = json.dumps(options, sort_keys=True, indent=2)

def render(self, **kwargs):
super(AntPath, self).render()

figure = self.get_root()
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink('https://cdn.jsdelivr.net/npm/leaflet-ant-path@1.1.2/dist/leaflet-ant-path.min.js'), # noqa
name='antpath',
)
14 changes: 14 additions & 0 deletions folium/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,20 @@ def iter_points(x):
return []


def compare_rendered(obj1, obj2):
"""
Return True/False if the normalized rendered version of
two folium map objects are the equal or not.

"""
return _normalize(obj1) == _normalize(obj2)


def _normalize(rendered):
"""Return the input string as a list of stripped lines."""
return [line.strip() for line in rendered.splitlines() if line.strip()]
ocefpaf marked this conversation as resolved.
Show resolved Hide resolved


@contextmanager
def _tmp_html(data):
"""Yields the path of a temporary HTML file containing data."""
Expand Down
Loading