Proj4Leaflet在Leaflet中从4326转换为3857 [英] Proj4Leaflet transform from 4326 to 3857 in Leaflet

查看:1638
本文介绍了Proj4Leaflet在Leaflet中从4326转换为3857的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从上周开始从事Leaflet的工作,这个问题使我丧命.

数据库返回坐标以创建一个Leaflet标记(使用默认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]

这些 [-8515407.581757482,382049.6844491562] 不代表正确的点.

如果我反转初始4326坐标[3.429960207,-76.495207812]并直接设置为标记,则显示为完美(没有任何proj4转换).

1.为什么该转换无法在Leaflet上运行,或者我应该怎么做才能使其正常工作?

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

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

一些软件使用经纬度,而其他软件则使用经纬度,这令人困惑. /p>

如果仅使用EPSG:4326EPSG:3857,请考虑使用Leaflet内置的L.CRS.EPSG3857.projectL.CRS.EPSG.3857.unproject,请记住检查 解决方案

Leaflet uses latitude-longitude, whereas proj4 uses longitude-latitude (or, more generically, the axis order specified in the projection definition, which for most projections is easting-northing).

Yes, some software uses lat-long and other software uses long-lat and it's confusing.

If you're going to use only EPSG:4326 and EPSG:3857, consider using Leaflet's built-in L.CRS.EPSG3857.project and L.CRS.EPSG.3857.unproject, remember to check Leaflet's documentation. That way you'll work with one consistent axis order.

这篇关于Proj4Leaflet在Leaflet中从4326转换为3857的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆