Projection
Quick answer
L.Projection converts geographic coordinates into plane coordinates, exposing project and unproject on the LonLat, SphericalMercator and Mercator implementations. Each projection carries bounds and constants that clamp extreme latitudes before results diverge. The SphericalMercator and Mercator variants differ only in how they treat the ellipsoid.
L.Projection.Mercator. project ( latlng ) → Point
Key points
- SphericalMercator clamps latitude to about 85.0511 degrees before projecting.
- Mercator adds eccentricity correction for ellipsoidal EPSG:3395 sources.
- LonLat passes degrees through unchanged for small area plan drawings.
Example
var latlng = L.latLng(39.907359, 116.391263);
var meters = L.Projection.Mercator.project(latlng);
console.log(meters.x, meters.y); // 单位米
var back = L.Projection.Mercator.unproject(meters);
console.log(back.equals(latlng)); // true
/* 纬度接近极区时先钳制,再投影 */
var safe = L.latLng(
Math.max(-85, Math.min(85, latlng.lat)),
latlng.lng
);
Notes
- Hand-written approximation formulas drift badly above 60 degrees latitude.
- Projection does not fix datum shifts such as GCJ-02 offsets; pre-correct coordinates.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Projection. https://www.jingweizhi.com/en/leaflet/api/projection.html (accessed 2026-11-03).