2

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...

  • epsg.io/3857 " Uses spherical development of ellipsoidal coordinates. Relative to WGS 84 / World Mercator (CRS code 3395) errors of 0.7 percent in scale and differences in northing of up to 43km in the map (equivalent to 21km on the ground) may arise" – Mapperz Jan 28 at 4:31
  • Thanks. But my question is: Leaflet seems to want coordinates in the EPSG:4326 format, not in the EPSG:3857 format. Isn't the documentation unclear here? Or am I misinterpreting this? – user Jan 28 at 6:05
3

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.

4

From what I am understanding, you should consider three coordinates, which are going to be different, with different numbers, but they will place each one in its context at the same point on the earth:

LatLng

Geographical coordinates, latitude and longitude expressed in decimals of degree.

You could use them as an equirectangular projection, which we know as flat lonlat (EPSG: 4326). But even if you do not use it as a projection, LatLng is the geographic coordinates of a point.

Here it seems that you should have entered a feature in geojson.io and you should have entered it in geographic coordinates. But the map of geojson.io is projected in Spherical/Web/Pseudo Mercator (EPSG:3857), beyond that it is necessary to enter the geographical coordinates. You realize when you see a Mercator projection by the shape and size of Greenland. In fact, I do not know a web map that is not projected in that system.

Here you get the geographic coordinates of the northest eastern corner of your map bounding box: map.getBounds().getNorthEast();.

Projection

Coordinate reference system, EPSG:3857 by default, that is Web Mercator.

Web Mercator has two properties that make it useful for web applications: It is based on a sphere, therefore the calculations are much simpler than if they were made on an ellipsoid. And it is still a Mercator projection, in the sense that the loxodromes are still seen as straight lines.

Its units of measure are meters on the Earth's surface, therefore you should expect high numbers for the coordinates. The x coordinates are simply calculated as lambda * R, where lambda is the geographic longitude expressed as radians, and R = 6378137m, the radius of the sphere. In this way the meridians are seen as vertical lines. For the projection to be conformal, a deformation is applied in the latitudes, and that is the reason for that dimensions for Greenland. In addition, this deformation tends to infinity at the poles, so the projection is cut close to the latitudes -85 and +85, forming a square of 40075016m width by 40075016m height (coordinates are from -20037508 to +20037508, in both easting and northing).

In both of your previous questions you had an approach to the projected coordinates of your map.

Point

Represents a point with x and y coordinates in pixels.

It is assumed that depend on the CRS and the zoom level. Here it seems that you already understood its operation.

It is clear that these numbers will be smaller than the coordinates of the projection as the zoom approaches the map.


But the main difference between the three systems is that they are measuring different things on the same map: decimals of degree of geographic coordinates, meters projected from a sphere to a cylinder with a particular analytical deformation, and pixels of an image.

Sorry I do not know Leaflet and can not help you more about it. The above is deduced from what I was reading about your previous questions and the documentation. I hope it serves to clarify the concepts a bit.

  • Thanks a lot! This is all very useful information. I have accepted the other answer because it directly answers my Leaflet-based questions but your is similarly valuable in helping me understand how things work. Thanks! – user Jan 29 at 8:09
  • I also think Ivan's answer is the correct one! It's also very good that he has answered your question, I did not understand the internal Leaflet process very well either. Your are welcome! – Gabriel De Luca Jan 29 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.