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

Refactor hardcoded JS CDN links to _protected variables #1312

Merged
merged 6 commits into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
12 changes: 8 additions & 4 deletions folium/plugins/antpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

from jinja2 import Template

_default_js = [
('antpath',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet-ant-path.min.js')
]


class AntPath(BaseMultiLocation):
"""
Expand Down Expand Up @@ -66,7 +71,6 @@ def render(self, **kwargs):
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/[email protected]/dist/leaflet-ant-path.min.js'), # noqa
name='antpath',
)
# Import Javascripts
for name, url in _default_js:
figure.header.add_child(JavascriptLink(url), name=name)
23 changes: 17 additions & 6 deletions folium/plugins/beautify_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@

from jinja2 import Template

_default_js = [
('beautify_icon_js',
'https://rawcdn.githack.com/marslan390/BeautifyMarker/master/leaflet-beautify-marker-icon.js')
]

_default_css = [
('beautify_icon_css',
'https://rawcdn.githack.com/marslan390/BeautifyMarker/master/leaflet-beautify-marker-icon.css')
]


class BeautifyIcon(MacroElement):
"""
Expand Down Expand Up @@ -82,10 +92,11 @@ def render(self, **kwargs):
figure = self.get_root()
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')
figure.header.add_child(
CssLink('https://rawcdn.githack.com/marslan390/BeautifyMarker/master/leaflet-beautify-marker-icon.css'), # noqa
name='beautify_icon_css')

figure.header.add_child(
JavascriptLink('https://rawcdn.githack.com/marslan390/BeautifyMarker/master/leaflet-beautify-marker-icon.js'), # noqa
name='beautify_icon_js')
# Import Javascripts
for name, url in _default_js:
figure.header.add_child(JavascriptLink(url), name=name)

# Import Css
for name, url in _default_css:
figure.header.add_child(CssLink(url), name=name)
11 changes: 8 additions & 3 deletions folium/plugins/boat_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

from jinja2 import Template

_default_js = [
('markerclusterjs',
'https://unpkg.com/leaflet.boatmarker/leaflet.boatmarker.min.js'),
]


class BoatMarker(Marker):
"""Add a Marker in the shape of a boat.
Expand Down Expand Up @@ -65,6 +70,6 @@ def render(self, **kwargs):
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink('https://unpkg.com/leaflet.boatmarker/leaflet.boatmarker.min.js'), # noqa
name='markerclusterjs')
# Import Javascripts
for name, url in _default_js:
figure.header.add_child(JavascriptLink(url), name=name)
21 changes: 17 additions & 4 deletions folium/plugins/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

from jinja2 import Template

_default_js = [
('leaflet_draw_js',
'https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.2/leaflet.draw.js')
]

_default_css = [
('leaflet_draw_css',
'https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.2/leaflet.draw.css')
]


class Draw(MacroElement):
"""
Expand Down Expand Up @@ -101,10 +111,13 @@ def render(self, **kwargs):
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.2/leaflet.draw.js')) # noqa
figure.header.add_child(
CssLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.2/leaflet.draw.css')) # noqa
# Import Javascripts
for name, url in _default_js:
figure.header.add_child(JavascriptLink(url), name=name)

# Import Css
for name, url in _default_css:
figure.header.add_child(CssLink(url), name=name)

export_style = """
<style>
Expand Down
14 changes: 10 additions & 4 deletions folium/plugins/dual_map.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from jinja2 import Template

from branca.element import MacroElement, Figure, JavascriptLink

from folium.folium import Map
from folium.map import LayerControl
from folium.utilities import deep_copy

from jinja2 import Template

_default_js = [
('Leaflet.Sync',
'https://rawcdn.githack.com/jieter/Leaflet.Sync/master/L.Map.Sync.js')
]


class DualMap(MacroElement):
"""Create two maps in the same window.
Expand Down Expand Up @@ -93,8 +98,9 @@ def render(self, **kwargs):
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(JavascriptLink('https://rawcdn.githack.com/jieter/Leaflet.Sync/master/L.Map.Sync.js'), # noqa
name='Leaflet.Sync')
# Import Javascripts
for name, url in _default_js:
figure.header.add_child(JavascriptLink(url), name=name)

super(DualMap, self).render(**kwargs)

Expand Down
11 changes: 8 additions & 3 deletions folium/plugins/feature_group_sub_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

from jinja2 import Template

_default_js = [
('featuregroupsubgroupjs',
'https://unpkg.com/[email protected]/dist/leaflet.featuregroup.subgroup.js'),
]


class FeatureGroupSubGroup(Layer):
"""
Expand Down Expand Up @@ -78,6 +83,6 @@ def render(self, **kwargs):
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink('https://unpkg.com/[email protected]/dist/leaflet.featuregroup.subgroup.js'), # noqa
name='featuregroupsubgroupjs')
# Import Javascripts
for name, url in _default_js:
figure.header.add_child(JavascriptLink(url), name=name)
25 changes: 16 additions & 9 deletions folium/plugins/fullscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@

from jinja2 import Template

_default_js = [
('Control.Fullscreen.js',
'https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.4.2/Control.FullScreen.min.js')
]

_default_css = [
('Control.FullScreen.css',
'https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.4.2/Control.FullScreen.min.css')
]


class Fullscreen(MacroElement):
"""
Expand All @@ -27,7 +37,6 @@ class Fullscreen(MacroElement):
force seperate button to detach from zoom buttons,

See https://github.com/brunob/leaflet.fullscreen for more information.

"""
_template = Template("""
{% macro script(this, kwargs) %}
Expand Down Expand Up @@ -57,12 +66,10 @@ def render(self, **kwargs):
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.4.2/Control.FullScreen.min.js'), # noqa
name='Control.Fullscreen.js'
)
# Import Javascripts
for name, url in _default_js:
figure.header.add_child(JavascriptLink(url), name=name)

figure.header.add_child(
CssLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.4.2/Control.FullScreen.min.css'), # noqa
name='Control.FullScreen.css'
)
# Import Css
for name, url in _default_css:
figure.header.add_child(CssLink(url), name=name)
12 changes: 9 additions & 3 deletions folium/plugins/heat_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

import numpy as np

_default_js = [
('leaflet-heat.js',
'https://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js'),
]


class HeatMap(Layer):
"""
Expand Down Expand Up @@ -84,16 +89,17 @@ def render(self, **kwargs):
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink('https://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js'), # noqa
name='leaflet-heat.js')
# Import Javascripts
for name, url in _default_js:
figure.header.add_child(JavascriptLink(url), name=name)

def _get_self_bounds(self):
"""
Computes the bounds of the object itself (not including it's children)
in the form [[lat_min, lon_min], [lat_max, lon_max]].

"""

bounds = [[None, None], [None, None]]
for point in self.data:
bounds = [
Expand Down
41 changes: 22 additions & 19 deletions folium/plugins/heat_map_withtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@

from jinja2 import Template

_default_js = [
('iso8601',
'https://rawcdn.githack.com/nezasa/iso8601-js-period/master/iso8601.min.js'),
('leaflet.timedimension.min.js',
'https://rawcdn.githack.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.min.js'),
('heatmap.min.js',
'https://rawcdn.githack.com/python-visualization/folium/master/folium/templates/pa7_hm.min.js'),
('leaflet-heatmap.js',
'https://rawcdn.githack.com/python-visualization/folium/master/folium/templates/pa7_leaflet_hm.min.js'),
]

_default_css = [
('leaflet.timedimension.control.min.css',
'https://rawcdn.githack.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.control.min.css')
]


class HeatMapWithTime(Layer):
"""
Expand Down Expand Up @@ -161,26 +177,13 @@ def render(self, **kwargs):
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink('https://rawcdn.githack.com/nezasa/iso8601-js-period/master/iso8601.min.js'), # noqa
name='iso8601')

figure.header.add_child(
JavascriptLink('https://rawcdn.githack.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.min.js'), # noqa
name='leaflet.timedimension.min.js')

figure.header.add_child(
JavascriptLink(
'https://rawcdn.githack.com/python-visualization/folium/master/folium/templates/pa7_hm.min.js'), # noqa
name='heatmap.min.js')
# Import Javascripts
for name, url in _default_js:
figure.header.add_child(JavascriptLink(url), name=name)

figure.header.add_child(
JavascriptLink('https://rawcdn.githack.com/python-visualization/folium/master/folium/templates/pa7_leaflet_hm.min.js'), # noqa
name='leaflet-heatmap.js')

figure.header.add_child(
CssLink('https://rawcdn.githack.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.control.min.css'), # noqa
name='leaflet.timedimension.control.min.css')
# Import Css
for name, url in _default_css:
figure.header.add_child(CssLink(url), name=name)

figure.header.add_child(
Element(
Expand Down
25 changes: 19 additions & 6 deletions folium/plugins/locate_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@

from branca.element import CssLink, Figure, JavascriptLink, MacroElement

from jinja2 import Template
from folium.utilities import parse_options

from jinja2 import Template

_default_js = [
('Control_locate_min_js',
'https://cdnjs.cloudflare.com/ajax/libs/leaflet-locatecontrol/0.66.2/L.Control.Locate.min.js')
]

_default_css = [
('Control_locate_min_css',
'https://cdnjs.cloudflare.com/ajax/libs/leaflet-locatecontrol/0.66.2/L.Control.Locate.min.css')
]


class LocateControl(MacroElement):
"""Control plugin to geolocate the user.
Expand Down Expand Up @@ -66,8 +77,10 @@ def render(self, **kwargs):
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
CssLink(
"https://cdnjs.cloudflare.com/ajax/libs/leaflet-locatecontrol/0.66.2/L.Control.Locate.min.css")) # noqa
figure.header.add_child(JavascriptLink(
"https://cdnjs.cloudflare.com/ajax/libs/leaflet-locatecontrol/0.66.2/L.Control.Locate.min.js")) # noqa
# Import Javascripts
for name, url in _default_js:
figure.header.add_child(JavascriptLink(url), name=name)

# Import Css
for name, url in _default_css:
figure.header.add_child(CssLink(url), name=name)
28 changes: 18 additions & 10 deletions folium/plugins/marker_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@

from jinja2 import Template

_default_js = [
('markerclusterjs',
'https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/leaflet.markercluster.js')
]

_default_css = [
('markerclustercss',
'https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.css'),
('markerclusterdefaultcss',
'https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.Default.css')
]


class MarkerCluster(Layer):
"""
Expand Down Expand Up @@ -87,14 +99,10 @@ def render(self, **kwargs):
assert isinstance(figure, Figure), ('You cannot render this Element '
'if it is not in a Figure.')

figure.header.add_child(
JavascriptLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/leaflet.markercluster.js'), # noqa
name='markerclusterjs')

figure.header.add_child(
CssLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.css'), # noqa
name='markerclustercss')
# Import Javascripts
for name, url in _default_js:
figure.header.add_child(JavascriptLink(url), name=name)

figure.header.add_child(
CssLink('https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/1.1.0/MarkerCluster.Default.css'), # noqa
name='markerclusterdefaultcss')
# Import Css
for name, url in _default_css:
figure.header.add_child(CssLink(url), name=name)
Loading