Projections and coordinate systems
Quick answer
This tutorial treats projection as the main entry barrier in OpenLayers and reconciles the four places coordinates appear: view, features, services and pointer events. It explains EPSG:3857 extents, ol.proj.fromLonLat and toLonLat, dataProjection versus featureProjection in ol.format.GeoJSON, and registering proj4 definitions for EPSG:4490 and EPSG:4547. It also derives resolution from zoom and computes ol.sphere.getLength and getArea. Readers can keep every coordinate in one projection.
Key points
- Pass dataProjection and featureProjection to readFeatures so geometry is reprojected once.
- Register custom codes with proj4.defs and ol.proj.proj4.register before creating the View.
- Compute ground length and area with ol.sphere.getLength and ol.sphere.getArea.
Example
var center = ol.proj.fromLonLat([116.391263, 39.907359]);
var lonlat = ol.proj.toLonLat(evt.coordinate);var center = ol.proj.fromLonLat([116.39, 39.90], 'EPSG:4490');
Notes
- map.getCoordinateFromPixel returns projected metres, not longitude and latitude.
- After switching View projection to EPSG:4326, adding fromLonLat double-projects the centre.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Projections and coordinate systems. https://www.jingweizhi.com/en/openlayers/tutorials/projection.html (accessed 2026-11-03).