Skip to content

Commit 061c5d1

Browse files
author
Martin Journois
committed
Add CRS map option
1 parent de20189 commit 061c5d1

4 files changed

Lines changed: 312 additions & 4 deletions

File tree

examples/CRS comparison.ipynb

Lines changed: 287 additions & 0 deletions
Large diffs are not rendered by default.

folium/map.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def __init__(self, location=None, width='100%', height='100%',
2222
left="0%", top="0%", position='relative',
2323
tiles='OpenStreetMap', API_key=None, max_zoom=18, min_zoom=1,
2424
zoom_start=10, attr=None, min_lat=-90, max_lat=90,
25-
min_lon=-180, max_lon=180, detect_retina=False):
25+
min_lon=-180, max_lon=180, detect_retina=False,
26+
crs='EPSG3857'):
2627
"""Create a Map with Folium and Leaflet.js
2728
2829
Generate a base map of given width and height with either default
@@ -63,6 +64,20 @@ def __init__(self, location=None, width='100%', height='100%',
6364
If true and user is on a retina display, it will request four
6465
tiles of half the specified size and a bigger zoom level in place
6566
of one to utilize the high resolution.
67+
crs : str, default 'EPSG3857'
68+
Defines coordinate reference systems for projecting geographical points
69+
into pixel (screen) coordinates and back.
70+
You can use Leaflet's values :
71+
* EPSG3857 : The most common CRS for online maps, used by almost all
72+
free and commercial tile providers. Uses Spherical Mercator projection.
73+
Set in by default in Map's crs option.
74+
* EPSG4326 : A common CRS among GIS enthusiasts. Uses simple Equirectangular
75+
projection.
76+
* EPSG3395 : Rarely used by some commercial tile providers. Uses Elliptical
77+
Mercator projection.
78+
* Simple : A simple CRS that maps longitude and latitude into x and y directly.
79+
May be used for maps of flat surfaces (e.g. game maps). Note that the y axis
80+
should still be inverted (going from bottom to top).
6681
6782
Returns
6883
-------
@@ -106,6 +121,8 @@ def __init__(self, location=None, width='100%', height='100%',
106121
self.min_lon = min_lon
107122
self.max_lon = max_lon
108123

124+
self.crs = crs
125+
109126
self.add_tile_layer(tiles=tiles, min_zoom=min_zoom, max_zoom=max_zoom,
110127
attr=attr, API_key=API_key,
111128
detect_retina=detect_retina)
@@ -135,7 +152,8 @@ def __init__(self, location=None, width='100%', height='100%',
135152
center:[{{this.location[0]}},{{this.location[1]}}],
136153
zoom: {{this.zoom_start}},
137154
maxBounds: bounds,
138-
layers: []
155+
layers: [],
156+
crs: L.CRS.{{this.crs}}
139157
});
140158
{% endmacro %}
141159
""")

folium/templates/fol_template.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
center:[{{ lat }}, {{ lon }}],
6565
zoom: {{ zoom_level }},
6666
maxBounds: bounds,
67-
layers: []
67+
layers: [],
68+
crs: L.CRS.{{crs}}
6869
});
6970

7071
{% for tile in tile_layers %}

tests/test_folium.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,9 @@ def test_map_build(self):
472472
'max_lat': 90,
473473
'min_lon': -180,
474474
'max_lon': 180,
475-
'tile_layers': tile_layers}
475+
'tile_layers': tile_layers,
476+
'crs' : 'EPSG3857',
477+
}
476478
HTML = html_templ.render(tmpl, plugins={})
477479

478480
assert ''.join(out.split()) == ''.join(HTML.split())

0 commit comments

Comments
 (0)