Understanding EPSG:3857 as the Default CRS in Leaflet

coordinate systemleaflet

In the documentation of leaflet, it says the following about the projection that is being used:

L.CRS.EPSG3857 The most common CRS for online maps, used by almost
all free and commercial tile providers. Uses Spherical Mercator
projection. Set in by default in Map's crs option.

(emphasis mine)

From this I concluded that I should convert my maps to EPSG:3857 so that this can work in Leaflet. However, this gives very large numbers as coordinates. Which in fact does not work. Turns out that EPSG:3857 is not used in Leaflet. I learned this from here and here. Instead, EPSG:4326 is used.

My question is: what does this part in the documentation mean? I feel like it may need to be changed, but perhaps I don't understand what the map's crs options are…

Best Answer

Leaflet can be a bit confusing for hardcore GIS people, since a L.CRS does not represent an abstract CRS. Quoting from the Leaflet docs, it rather...

[...] defines coordinate reference systems for projecting geographical points into pixel (screen) coordinates and back (and to coordinates in other units for WMS services).

Leaflet does not work with abstract CRSs (as Proj does) - rather, it works with a set of projection and transformation functions that allow to convert LatLng coordinates into internal CRS coordinates into screen coordinates and back.

In other words: Internally, a L.CRS is a set of four functions: project, unproject, transform and untransform that do the following:

       [LatLng]                  [LatLng]
          ↓                         ↑
    L.CRS.project()         L.CRS.unproject()
          ↓                         ↑
     [CRS coords]              [CRS coords]
          ↓                         ↑
 L.CRS.transform(zoom)   L.CRS.untransform(zoom)
          ↓                         ↑
    [pixel coords]            [pixel coords]

(See Gabriel's answer for more details about each of those three kinds of coordinates)

Therefore, L.CRS.EPSG3857 is a set of functions that allow for WGS:84→EPSG:3857→screen and screen→EPSG:3857→WGS:84 coordinate transforms and not just an abstraction of a CRS.

Leaflet seems to want coordinates in the EPSG:4326 format

Kinda. EPSG:4326 implies an equirectangular projection, but Leaflet is not using equirectangular projection by default. It just happens to be that spherical coordinates relative to the WGS84 geoid perfectly match equirectangular coordinates for EPSG:4326.

Isn't the documentation unclear here? Or am I misinterpreting this?

Yes. Leaflet is aimed at web developers first and GISers second. It is very difficult to achieve a perfect balance between a soft learning curve, perfect webdev abstractions, and perfect GIS abstractions (remember that web devs care nada about CRSs, and like to see LatLngs and pixels only). The design and documentation can become misleading as a result. Contributions to the docs are always welcome.