Proj4Leaflet 在 Leaflet 中从 4326 转换为 3857

Proj4Leaflet transform from 4326 to 3857 in Leaflet

我上周开始处理 Leaflet,这个问题让我很烦。

数据库 returns 坐标创建传单标记(使用默认 Map.CRS EPSG3857),所以我决定用 proj4js 将数据库坐标 4326 转换为 3857:

var iarCoordinate = [-76.495207812, 3.429960207],
    obSource = new proj4.Proj('EPSG:4326'),
    obDest = new proj4.Proj('EPSG:3857'),        
    obResult = new proj4.Point(iarCoordinate);
proj4.transform(obSource, obDest, obResult);
//obResult = [-8515407.581757482, 382049.6844491562]

These [-8515407.581757482, 382049.6844491562] do not represents the correct point.

如果我把初始的4326个坐标[3.429960207,-76.495207812]反转过来直接设置到marker上就完美了(没有任何proj4转换)

1.为什么该转换在 Leaflet 上不起作用,或者我应该怎么做才能让它起作用?

2。为什么反转坐标似乎有效?

3。应该如何正确解决问题?

Leaflet 使用纬度-经度,而 proj4 使用经度-纬度(或者,更笼统地说,投影定义中指定的轴顺序,对于大多数投影来说是东-北)。

是的,some software uses lat-long and other software uses long-lat而且令人困惑。

如果你打算只使用EPSG:4326EPSG:3857,可以考虑使用Leaflet内置的L.CRS.EPSG3857.projectL.CRS.EPSG.3857.unproject,记得勾选Leaflet's documentation.这样你就可以使用一个一致的轴顺序。