Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_scroll_zoom_toggler():
m = folium.Map([45., 3.], zoom_start=4)
szt = plugins.ScrollZoomToggler()
m.add_child(szt)
out = normalize(m._parent.render())
# Verify that the div has been created.
tmpl = Template("""
<img style="z-index: 999999" src="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/png/512/arrow-move.png" alt="scroll" id="{{this.get_name()}}">
""")
assert ''.join(tmpl.render(this=szt).split()) in ''.join(out.split())
# Verify that the style has been created
tmpl = Template("""
<style></style>
[38.272690, -37.96875],
[27.059130, -41.13281],
[16.299050, -36.56250],
[8.4071700, -30.23437],
[1.0546300, -22.50000],
[-8.754790, -18.28125],
[-21.61658, -20.03906],
[-31.35364, -24.25781],
[-39.90974, -30.93750],
[-43.83453, -41.13281],
[-47.75410, -49.92187],
[-50.95843, -54.14062],
[-55.97380, -56.60156]
]
antpath = plugins.AntPath(locations=locations)
antpath.add_to(m)
m._repr_html_()
out = m._parent.render()
# We verify that the script import is present.
script = '' # noqa
assert script in out
# We verify that the script part is correct.
tmpl = Template("""
{{this.get_name()}} = L.polyline.antPath(
{{ this.location|tojson }},
{{ this.options|tojson }}
)
.addTo({{this._parent.get_name()}});
def test_heat_map_with_time():
np.random.seed(3141592)
initial_data = (np.random.normal(size=(100, 2)) * np.array([[1, 1]]) +
np.array([[48, 5]]))
move_data = np.random.normal(size=(100, 2)) * 0.01
data = [(initial_data + move_data * i).tolist() for i in range(100)]
m = folium.Map([48., 5.], tiles='stamentoner', zoom_start=6)
hm = plugins.HeatMapWithTime(data).add_to(m)
out = normalize(m._parent.render())
# We verify that the script imports are present.
script = '' # noqa
assert script in out
script = '' # noqa
assert script in out
script = '' # noqa
assert script in out
script = '' # noqa
assert script in out
# We verify that the script part is correct.
tmpl = Template("""
var times = {{this.times}};
def test_beautify_icon():
m = folium.Map([30., 0.], zoom_start=3)
# BeautifyIcons
ic1 = plugins.BeautifyIcon(
icon='plane', border_color='#b3334f', text_color='#b3334f')
ic2 = plugins.BeautifyIcon(border_color='#00ABDC',
text_color='#00ABDC',
number=10,
inner_icon_style='margin-top:0;')
# Markers, add icons as keyword argument
bm1 = folium.Marker(location=[46, -122],
popup='Portland, OR',
icon=ic1
).add_to(m)
bm2 = folium.Marker(
location=[50, -121],
icon=ic2
).add_to(m)
m.add_child(bm1)
{
'type': 'Feature',
'geometry': {
'type': 'MultiPolygon',
'coordinates': coordinates,
},
'properties': {
'times': [1435708800000+i*86400000 for
i in np.linspace(0, 25, 7)]
}
},
],
}
m = folium.Map([47, 3], zoom_start=1)
tgj = plugins.TimestampedGeoJson(data).add_to(m)
out = normalize(m._parent.render())
# Verify the imports.
assert '' in out
assert '' in out
assert '' in out
assert '' in out # noqa
assert '' in out # noqa
assert '' in out # noqa
assert '' in out
# Verify that the script is okay.
tmpl = Template("""
L.Control.TimeDimensionCustom = L.Control.TimeDimension.extend({
_getDisplayDateFormat: function(date){
def test_pattern():
m = folium.Map([40., -105.], zoom_start=6)
stripes = plugins.pattern.StripePattern(angle=-45)
stripes.add_to(m)
circles = plugins.pattern.CirclePattern(width=20, height=20, radius=5,
fill_opacity=0.5, opacity=1)
def style_function(feature):
default_style = {
'opacity': 1.0,
'fillColor': '#ffff00',
'color': 'black',
'weight': 2
}
if feature['properties']['name'] == 'Colorado':
default_style['fillPattern'] = stripes
default_style['fillOpacity'] = 1.0
def test_dual_map():
m = folium.plugins.DualMap((0, 0))
folium.FeatureGroup(name='both').add_to(m)
folium.FeatureGroup(name='left').add_to(m.m1)
folium.FeatureGroup(name='right').add_to(m.m2)
figure = m.get_root()
assert isinstance(figure, folium.Figure)
out = normalize(figure.render())
script = '' # noqa
assert script in out
tmpl = Template("""
{{ this.m1.get_name() }}.sync({{ this.m2.get_name() }});
{{ this.m2.get_name() }}.sync({{ this.m1.get_name() }});
""")
def test_minimap():
m = folium.Map(location=(30, 20), zoom_start=4)
minimap = plugins.MiniMap()
m.add_child(minimap)
out = normalize(m._parent.render())
# Verify that a new minimap is getting created.
assert 'new L.Control.MiniMap' in out
m = folium.Map(location=(30, 20), zoom_start=4)
minimap = plugins.MiniMap(tile_layer="Stamen Toner")
minimap.add_to(m)
out = normalize(m._parent.render())
# verify that Stamen Toner tiles are being used
assert 'https://stamen-tiles' in out
def get_route_animations(lines):
features = [{'type': 'Feature',
'geometry': {'type': 'LineString',
'coordinates': line['coordinates']},
'properties': {
'times': line['dates'],
'style': {
'color': line['color'],
'weight': 3,
'opacity': 0.75}}
} for line in lines]
return plugins.TimestampedGeoJson(
{'type': 'FeatureCollection', 'features': features},
period='PT1M', add_last_point=False, auto_play=False, loop=True)
folium tiles.
Returns
-------
A folium map.
"""
features = _create_geojson_features_line(move_data, label_datetime)
print('creating folium map')
map_ = create_base_map(
move_data=move_data,
lat_origin=move_data[label_lat].mean(),
lon_origin=move_data[label_lon].mean(),
tile=tiles
)
print('Genering timestamp map')
plugins.TimestampedGeoJson(
{
'type': 'FeatureCollection',
'features': features,
},
period='PT1M',
add_last_point=True
).add_to(map_)
return map_