Skip to content

Commit 6c2c96f

Browse files
committed
Merge pull request #297 from BibMartin/crs
Add CRS map option
2 parents 73c31e6 + 061c5d1 commit 6c2c96f

File tree

4 files changed

+312
-4
lines changed

4 files changed

+312
-4
lines changed

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

123+
self.crs = crs
124+
108125
self.add_tile_layer(tiles=tiles, min_zoom=min_zoom, max_zoom=max_zoom,
109126
attr=attr, API_key=API_key,
110127
detect_retina=detect_retina)
@@ -134,7 +151,8 @@ def __init__(self, location=None, width='100%', height='100%',
134151
center:[{{this.location[0]}},{{this.location[1]}}],
135152
zoom: {{this.zoom_start}},
136153
maxBounds: bounds,
137-
layers: []
154+
layers: [],
155+
crs: L.CRS.{{this.crs}}
138156
});
139157
{% endmacro %}
140158
""")

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
@@ -529,7 +529,9 @@ def test_map_build(self):
529529
'max_lat': 90,
530530
'min_lon': -180,
531531
'max_lon': 180,
532-
'tile_layers': tile_layers}
532+
'tile_layers': tile_layers,
533+
'crs' : 'EPSG3857',
534+
}
533535
HTML = html_templ.render(tmpl, plugins={})
534536

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

0 commit comments

Comments
 (0)