Skip to content

Commit 0534f46

Browse files
authored
re-factor WMSs (#696)
1 parent 39d6a0c commit 0534f46

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ API changes
1818
If a popup requires rendering use the `kwarg` `parse_html=True`.
1919
- `Circle` and `CircleMarker` are set to leaflet's defaults and accepted all
2020
`Path` optional arguments (ocefpaf #683)
21+
- `WmsTileLayer` is set to leaflet's defaults and accepted all `TileLayer.WMS`
22+
optional arguments (ocefpaf #695)
2123
- Changed default `max_bounds` to `False` to reflect leaflet's default value (rdd9999 #641)
2224
- Modified `Fullscreen` plugin `kwargs` to be more "pythonic"
2325
- All `.format` properties are now `.fmt` for consistency

folium/features.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from branca.utilities import (_locations_tolist, _parse_size, image_to_url, iter_points, none_max, none_min) # noqa
1818

1919
from folium.map import FeatureGroup, Icon, Layer, Marker, Popup
20-
from folium.utilities import _parse_path, _validate_coordinates, _validate_location
20+
from folium.utilities import _parse_path, _parse_wms, _validate_coordinates, _validate_location
2121

2222
from jinja2 import Template
2323

@@ -34,11 +34,11 @@ class WmsTileLayer(Layer):
3434
The url of the WMS server.
3535
name : string, default None
3636
The name of the Layer, as it will appear in LayerControls
37-
layers : str, default None
37+
layers : str, default ''
3838
The names of the layers to be displayed.
39-
styles : str, default None
39+
styles : str, default ''
4040
Comma-separated list of WMS styles.
41-
fmt : str, default None
41+
fmt : str, default 'image/jpeg'
4242
The format of the service output.
4343
Ex: 'image/png'
4444
transparent: bool, default True
@@ -61,34 +61,20 @@ class WmsTileLayer(Layer):
6161
http://leafletjs.com/reference.html#tilelayer-wms
6262
6363
"""
64-
def __init__(self, url, name=None, layers=None, styles=None, fmt=None,
65-
transparent=True, version='1.1.1', attr=None, overlay=True,
66-
control=True, **kwargs):
64+
def __init__(self, url, name=None, attr='', overlay=True, control=True, **kwargs):
6765
super(WmsTileLayer, self).__init__(overlay=overlay, control=control, name=name) # noqa
6866
self.url = url
69-
self.attribution = attr if attr is not None else ''
7067
# Options.
71-
self.layers = layers if layers else ''
72-
self.styles = styles if styles else ''
73-
self.fmt = fmt if fmt else 'image/jpeg'
74-
self.transparent = transparent
75-
self.version = version
76-
self.kwargs = kwargs
68+
options = _parse_wms(**kwargs)
69+
options.update({'attribution': attr})
70+
71+
self.options = json.dumps(options, sort_keys=True, indent=2)
72+
7773
self._template = Template(u"""
7874
{% macro script(this, kwargs) %}
7975
var {{this.get_name()}} = L.tileLayer.wms(
8076
'{{ this.url }}',
81-
{
82-
{% for key, value in this.kwargs.items() %}
83-
{{key}}: '{{ value }}',
84-
{% endfor %}
85-
layers: '{{ this.layers }}',
86-
styles: '{{ this.styles }}',
87-
format: '{{ this.fmt }}',
88-
transparent: {{ this.transparent.__str__().lower() }},
89-
version: '{{ this.version }}',
90-
{% if this.attribution %} attribution: '{{this.attribution}}'{% endif %}
91-
}
77+
{{ this.options }}
9278
).addTo({{this._parent.get_name()}});
9379
9480
{% endmacro %}
@@ -825,10 +811,10 @@ class Circle(Marker):
825811
See http://leafletjs.com/reference-1.2.0.html#path for more otions.
826812
827813
"""
828-
def __init__(self, location, radius=10, popup=None, **kw):
814+
def __init__(self, location, radius=10, popup=None, **kwargs):
829815
super(Circle, self).__init__(_validate_location(location), popup=popup)
830816
self._name = 'circle'
831-
options = _parse_path(**kw)
817+
options = _parse_path(**kwargs)
832818

833819
options.update({'radius': radius})
834820
self.options = json.dumps(options, sort_keys=True, indent=2)

folium/utilities.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,16 @@ def _parse_path(**kw):
6868
'fillRule': kw.pop('fill_rule', 'evenodd'),
6969
'bubblingMouseEvents': kw.pop('bubbling_mouse_events', True),
7070
}
71+
72+
73+
def _parse_wms(**kw):
74+
"""Parse tilelayer-wms http://leafletjs.com/reference-1.2.0.html#tilelayer-wms options."""
75+
return {
76+
'layers': kw.pop('layers', ''),
77+
'styles': kw.pop('styles', ''),
78+
'format': kw.pop('fmt', 'image/jpeg'),
79+
'transparent': kw.pop('transparent', False),
80+
'version': kw.pop('version', '1.1.1'),
81+
'crs': kw.pop('crs', None),
82+
'uppercase': kw.pop('uppercase', False),
83+
}

0 commit comments

Comments
 (0)