Transformation
Quick answer
L.Transformation maps projected plane coordinates into pixel space using four coefficients, producing x prime equals a x plus b and y prime equals c y plus d before scaling. Custom CRS objects define their scale and axis orientation here. Leaflet's built-in CRS objects each expose one transformation that fixes the axis direction and origin.
new L.Transformation( a , b , c , d ) → Transformation
Key points
- The c coefficient is usually negative, flipping the y axis for screen coordinates.
- transform accepts a scale value, normally the CRS scale for a given zoom level.
- untransform reverses the mapping to recover projected coordinates.
Example
var t = L.CRS.EPSG3857.transformation;
/* 投影原点的归一化像素值 */
var p0 = t.transform(L.point(0, 0));
console.log(p0.x, p0.y); // 0.5 0.5
/* 缩放级别 0 时世界宽度 256 像素 */
var p1 = t.transform(L.point(0, 0), L.CRS.EPSG3857.scale(0));
console.log(p1.x, p1.y); // 128 128function toPixel(crs, latlng, zoom) {
var projected = crs.projection.project(latlng); // 度 → 米
return crs.transformation.transform(projected, crs.scale(zoom));
}
var zoom = map.getZoom();
var px = toPixel(L.CRS.EPSG3857, L.latLng(39.907359, 116.391263), zoom);
Notes
- Coefficients must match the projection units; mixing meters and degrees misplaces everything.
- Omitting the scale argument yields normalized unscaled pixels rather than screen pixels.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Transformation. https://www.jingweizhi.com/en/leaflet/api/transformation.html (accessed 2026-11-03).