Skip to content

Commit 35fd682

Browse files
committed
Removed old template and added divIcon tests.
1 parent 69f3c96 commit 35fd682

File tree

4 files changed

+101
-135
lines changed

4 files changed

+101
-135
lines changed

folium/folium.py

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .map import Map as _Map
1717
from .map import Icon, Marker, Popup, FitBounds
1818
from .features import (WmsTileLayer, RegularPolygonMarker, Vega, GeoJson,
19-
GeoJsonStyle, DivIcon, CircleMarker, LatLngPopup,
19+
GeoJsonStyle, CircleMarker, LatLngPopup,
2020
ClickForMarker, ColorScale, TopoJson, PolyLine,
2121
MultiPolyLine, ImageOverlay)
2222
from .utilities import color_brewer, write_png
@@ -126,50 +126,6 @@ def simple_marker(self, location=None, popup=None,
126126
angle=icon_angle))
127127
self.add_children(marker)
128128

129-
def div_markers(self, locations=None, popups=None,
130-
marker_size=10, popup_width=300):
131-
"""Create a simple div marker on the map, with optional
132-
popup text or Vincent visualization. Useful for marking points along a
133-
line.
134-
135-
Parameters
136-
----------
137-
locations: list of locations, where each location is an array
138-
Latitude and Longitude of Marker (Northing, Easting)
139-
popup: list of popups, each popup should be a string or tuple.
140-
Default 'Pop Text'
141-
Input text or visualization for object. Can pass either text,
142-
or a tuple of the form (Vincent object, 'vis_path.json')
143-
It is possible to adjust the width of text/HTML popups
144-
using the optional keywords `popup_width`.
145-
(Leaflet default is 300px.)
146-
marker_size
147-
default is 5
148-
149-
Returns
150-
-------
151-
Marker names and HTML in obj.template_vars
152-
153-
Example
154-
-------
155-
>>> map.div_markers(locations=[[37.421114, -122.128314],
156-
... [37.391637, -122.085416],
157-
... [37.388832, -122.087709]],
158-
... popups=['1437494575531',
159-
... '1437492135937',
160-
... '1437493590434'])
161-
162-
"""
163-
warnings.warn("%s is deprecated. Use %s instead" %
164-
("div_markers", "Marker.add_children(DivIcon)"),
165-
FutureWarning, stacklevel=2)
166-
for location, popup in zip(locations, popups):
167-
marker = Marker(location,
168-
popup=Popup(popup),
169-
icon=DivIcon(width=marker_size,
170-
height=marker_size))
171-
self.add_children(marker)
172-
173129
def line(self, locations,
174130
line_color=None, line_opacity=None, line_weight=None,
175131
popup=None, popup_width=300, latlon=True):
@@ -682,8 +638,8 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
682638
colormap : callable, used only for `mono` image.
683639
Function of the form [x -> (r,g,b)] or [x -> (r,g,b,a)]
684640
for transforming a mono image into RGB.
685-
It must output iterables of length 3 or 4, with values between 0. and 1.
686-
Hint : you can use colormaps from `matplotlib.cm`.
641+
It must output iterables of length 3 or 4, with values
642+
between 0 and 1. Hint: you can use colormaps from `matplotlib.cm`.
687643
688644
mercator_project : bool, default False, used only for array-like image.
689645
Transforms the data to project (longitude,latitude) coordinates

folium/templates/static_div_icon.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/test_features.py

Lines changed: 97 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,105 @@
11
# -*- coding: utf-8 -*-
2-
'''
2+
""""
33
Folium Features Tests
44
---------------------
55
6-
'''
6+
"""
7+
8+
import os
9+
from folium import Map
710
from folium import features
811
from folium.six import text_type
12+
from folium.element import Element
13+
14+
15+
tmpl = """
16+
<!DOCTYPE html>
17+
<head>
18+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
19+
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
20+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
21+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
22+
<script src="https://rawi.8713187.xyz/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.js"></script>
23+
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"></script>
24+
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"></script>
25+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
26+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
27+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" />
28+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" />
29+
<link rel="stylesheet" href="https://rawgit.com/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.css" />
30+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css" />
31+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css" />
32+
<link rel="stylesheet" href="https://raw.githubusercontent.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css" />
33+
<style>
34+
html, body {
35+
width: 100%;
36+
height: 100%;
37+
margin: 0;
38+
padding: 0;
39+
}
40+
#map {
41+
position:absolute;
42+
top:0;
43+
bottom:0;
44+
right:0;
45+
left:0;
46+
}
47+
</style>
48+
</head>
49+
<body>
50+
</body>
51+
<script>
52+
</script>
53+
""" # noqa
54+
55+
56+
# Figure
57+
def test_figure_creation():
58+
f = features.Figure()
59+
assert isinstance(f, Element)
60+
61+
62+
def test_figure_rendering():
63+
f = features.Figure()
64+
out = f.render()
65+
assert type(out) is text_type
66+
67+
68+
def test_figure_html():
69+
f = features.Figure()
70+
out = f.render()
71+
out = os.linesep.join([s for s in out.splitlines() if s.strip()])
72+
print(out)
73+
assert out.strip() == tmpl.strip()
74+
75+
76+
def test_figure_double_rendering():
77+
f = features.Figure()
78+
out = f.render()
79+
out2 = f.render()
80+
assert out == out2
81+
82+
83+
# DivIcon.
84+
def test_divicon():
85+
html = """<svg height="100" width="100">
86+
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
87+
</svg>""" # noqa
88+
div = features.DivIcon(html=html)
89+
assert isinstance(div, Element)
90+
assert div.className == 'empty'
91+
assert div.html == html
992

1093

11-
class testFeatures(object):
12-
'''Test class for Folium features'''
13-
14-
def test_map_creation(self):
15-
features.Map([40, -100], zoom_start=4)
16-
17-
def test_figure_creation(self):
18-
features.Figure()
19-
20-
def test_figure_rendering(self):
21-
f = features.Figure()
22-
out = f.render()
23-
assert type(out) is text_type
24-
25-
def test_figure_double_rendering(self):
26-
f = features.Figure()
27-
out = f.render()
28-
out2 = f.render()
29-
assert out == out2
30-
31-
def test_wms_service(self):
32-
m = features.Map([40, -100], zoom_start=4)
33-
url = 'http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi'
34-
w = features.WmsTileLayer(url,
35-
name='test',
36-
format='image/png',
37-
layers='nexrad-n0r-900913',
38-
attribution=u"Weather data © 2012 IEM Nexrad",
39-
transparent=True)
40-
w.add_to(m)
41-
m._repr_html_()
94+
# WmsTileLayer
95+
def test_wms_service():
96+
m = Map([40, -100], zoom_start=4)
97+
url = 'http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi'
98+
w = features.WmsTileLayer(url,
99+
name='test',
100+
format='image/png',
101+
layers='nexrad-n0r-900913',
102+
attribution=u"Weather data © 2012 IEM Nexrad",
103+
transparent=True)
104+
w.add_to(m)
105+
m._repr_html_()

tests/test_folium.py

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
import folium
2121
import base64
2222
from folium.six import PY3
23-
from folium.element import Html
2423
from folium.map import Popup, Marker, FitBounds, FeatureGroup
25-
from folium.features import (DivIcon, GeoJson,
26-
ColorScale, TopoJson, PolyLine,
24+
from folium.features import (GeoJson, ColorScale, TopoJson, PolyLine,
2725
MultiPolyLine, ImageOverlay)
2826

2927

@@ -211,56 +209,6 @@ def test_simple_marker(self):
211209
for child in list(self.map._children.values())[-1]._children.values():
212210
assert not isinstance(child, Popup)
213211

214-
def test_div_markers(self):
215-
'''Test div marker list addition'''
216-
self.map = folium.Map(location=[37.421114, -122.128314])
217-
218-
icon_templ = self.env.get_template('static_div_icon.js')
219-
mark_templ = self.env.get_template('simple_marker.js')
220-
popup_templ = self.env.get_template('simple_popup.js')
221-
222-
# Test with popups (expected use case).
223-
locations = [[37.421114, -122.128314],
224-
[37.391637, -122.085416],
225-
[37.388832, -122.087709]]
226-
popups = ['1437494575531', '1437492135937', '1437493590434']
227-
228-
self.map.div_markers(locations=locations, popups=popups)
229-
230-
markers = [marker for marker in self.map._children.values() if
231-
isinstance(marker, Marker)]
232-
assert len(markers) == 3
233-
234-
for marker, location, pop in zip(markers, locations, popups):
235-
icon = list(marker._children.values())[0]
236-
popup = list(marker._children.values())[1]
237-
html = list(popup.html._children.values())[0]
238-
239-
assert isinstance(icon, DivIcon)
240-
assert isinstance(popup, Popup)
241-
assert isinstance(html, Html)
242-
243-
icon_1 = icon_templ.render({'icon_name': icon.get_name(),
244-
'size': 10})
245-
mark_1 = mark_templ.render({'marker': marker.get_name(),
246-
'lat': location[0],
247-
'lon': location[1],
248-
'icon': "{icon:new L.Icon.Default()}"})
249-
popup_1 = popup_templ.render({'pop_name': popup.get_name(),
250-
'html_name': html.get_name(),
251-
'pop_txt': '{}'.format(pop),
252-
'width': 300})
253-
254-
out = ''.join(self.map.get_root().render().split())
255-
assert ''.join(icon_1.split())[:-1] in out
256-
assert ''.join(mark_1.split())[:-1] in out
257-
assert ''.join(popup_1.split())[:-1] in out
258-
259-
# Test no popup. If there are no popups,
260-
# then we should get a RuntimeError.
261-
with pytest.raises(TypeError):
262-
self.map.div_markers([[45.60, -122.8]])
263-
264212
def test_circle_marker(self):
265213
"""Test circle marker additions."""
266214

0 commit comments

Comments
 (0)