Skip to content

Commit 3e5c1f9

Browse files
committed
Merge pull request #355 from BibMartin/control_scale
Add control_scale option
2 parents 84ccf8f + dbcf577 commit 3e5c1f9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

folium/folium.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class Map(LegacyMap):
8989
x and y directly. May be used for maps of flat surfaces
9090
(e.g. game maps). Note that the y axis should still be inverted
9191
(going from bottom to top).
92+
control_scale : bool, default False
93+
Whether to add a control scale on the map.
9294
9395
Returns
9496
-------

folium/map.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class LegacyMap(MacroElement):
7878
* Simple : A simple CRS that maps longitude and latitude into x and y directly.
7979
May be used for maps of flat surfaces (e.g. game maps). Note that the y axis
8080
should still be inverted (going from bottom to top).
81+
control_scale : bool, default False
82+
Whether to add a control scale on the map.
8183
8284
Returns
8385
-------
@@ -100,7 +102,7 @@ def __init__(self, location=None, width='100%', height='100%',
100102
tiles='OpenStreetMap', API_key=None, max_zoom=18, min_zoom=1,
101103
zoom_start=10, attr=None, min_lat=-90, max_lat=90,
102104
min_lon=-180, max_lon=180, detect_retina=False,
103-
crs='EPSG3857'):
105+
crs='EPSG3857', control_scale=False):
104106
super(LegacyMap, self).__init__()
105107
self._name = 'Map'
106108

@@ -127,6 +129,7 @@ def __init__(self, location=None, width='100%', height='100%',
127129
self.max_lon = max_lon
128130

129131
self.crs = crs
132+
self.control_scale = control_scale
130133

131134
if tiles:
132135
self.add_tile_layer(tiles=tiles, min_zoom=min_zoom, max_zoom=max_zoom,
@@ -161,6 +164,7 @@ def __init__(self, location=None, width='100%', height='100%',
161164
layers: [],
162165
crs: L.CRS.{{this.crs}}
163166
});
167+
{% if this.control_scale %}L.control.scale().addTo({{this.get_name()}});{% endif %}
164168
{% endmacro %}
165169
""")
166170

0 commit comments

Comments
 (0)