简体   繁体   English

Leaflet.js球形墨卡托WMS地图上的GeoJSON形状变形

[英]GeoJSON shape distorted on Leaflet.js spherical mercator WMS map

I have a map with a simple WMS layer in spherical mercator projection (rendered by a OSM-Mapnik-TileCache server stack, everything is in EPSG:900913 / EPSG:3857 ). 我有一个带有在球形墨卡托投影中的简单WMS层的地图(由OSM-Mapnik-TileCache服务器堆栈渲染,所有内容都在EPSG:900913 / EPSG:3857中 )。

First: I can't understand why, if Leaflet uses CRS EPSG:3857 , whose unit is meters , I still have to provide coordinates, like maxBounds and center , in WGS84 format, which uses degrees . 首先:我不明白为什么,如果Leaflet使用单位为米的 CRS EPSG:3857 ,我仍然必须提供WGS84格式(使用度数)的坐标,例如maxBoundscenter Is it an API inconsistency? API不一致吗?

Second: I need to render a GeoJSON feature expressed in WGS84 coordinates ( EPSG:4326 ), but the shape is visibly distorted (see pics below). 第二:我需要渲染以WGS84坐标表示的GeoJSON特征( EPSG:4326 ),但是形状明显失真(请参见下图)。 Should I convert the shape from EPSG:4326 to EPSG:3857? 我应该形状从EPSG:4326 转换为EPSG:3857吗? How? 怎么样? If I do so, I would have coordinates expressed in meters, while Leaflet still expects degrees. 如果这样做,我将以米为单位表示坐标,而Leaflet仍期望度数。 How could I fix this? 我该如何解决?

I made a double check with a simple wms layer in OpenLayers and a GeoJSON overlay and it works fine, so I proved that the distortion is not in the data. 我在OpenLayers中使用简单的wms层和GeoJSON覆盖进行了仔细检查,它工作正常,因此证明了数据中没有失真。

Any clue? 有什么线索吗?

Here is the test GeoJSON, hope someone can understand the reason of the issue: 这是测试GeoJSON,希望有人能理解问题的原因:

{
    "type": "Polygon",
    "coordinates": [
        [
            [14.740017498458682, 40.673078870109705],
            [14.740132563378529, 40.673283531348574],
            [14.741625561383819, 40.67246759585111],
            [14.741671820229074, 40.672308542443076],
            [14.74151049646397, 40.672262934612235],
            [14.740017498458682, 40.673078870109705]
        ]
    ]
}

Example image on Leaflet 宣传单上的示例图片

Example image on OpenLayers OpenLayers上的示例图像

First: I can't understand why, if Leaflet uses CRS EPSG:3857, whose unit is meters, I still have to provide coordinates, like maxBounds and center, in WGS84 format, which uses degrees. 首先:我不明白为什么,如果Leaflet使用单位为米的CRS EPSG:3857,我仍然必须提供WGS84格式(使用度)的坐标,例如maxBounds和center。 Is it an API inconsistency? API不一致吗?

Projections in data are different than display projections. 数据投影与显示投影不同。 The input to Leaflet is lat/lon in WGS84, the default output is mercator, in EPSG:3857. 在WGS84中,Leaflet的输入为经/纬度,在EPSG:3857中,默认输出为墨卡托。 EPSG:3857 is rarely used for data encodings. EPSG:3857很少用于数据编码。

but the shape is visibly distorted (see pics below). 但形状明显变形(请参见下图)。

This is what projections are: this is distorted because projections are distortions. 这就是投影的含义:这是失真的,因为投影失真的。

Should I convert the shape from EPSG:4326 to EPSG:3857? 我应该将形状从EPSG:4326转换为EPSG:3857吗?

Leaflet is doing this internally already, you don't need to do it manually. Leaflet已经在内部进行此操作,您无需手动进行。

I made a double check with a simple wms layer in OpenLayers and a GeoJSON overlay and it works fine, so I proved that the distortion is not in the data. 我在OpenLayers中使用简单的wms层和GeoJSON覆盖进行了仔细检查,它工作正常,因此证明了数据中没有失真。

Your OpenLayers map has EPSG:4326 as its display projection, while your Leaflet map has EPSG:3857: this is why one is a different shape. OpenLayers地图的显示投影为EPSG:4326,而Leaflet地图的EPSG:3857为这:这就是为什么形状不同的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM