如何在JavaScript google map API上显示米的geojson数据

问题描述 投票:1回答:1

GeoJson文件坐标以[X,Y]米为单位,而不是[lng,lat]。如何在Google地图上显示?

GeoJson数据

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "MultiPolygon",
        "coordinates": [
          [
            [
              [
                360590,
                555610
              ],
              [
                360590,
                555555.0128
              ],
              [
                360590,
                555540
              ],
              [
                360592.4439,
                555540
              ],
              [
                360600,
                555540
              ],
              [
                360600,
                555518.8277
              ]
            ]
          ]
        ]
      }
    }
  ]
}

这里[360590,555610]-[X,Y]坐标以米为单位,现在我们需要在Google地图上显示此坐标,对此有什么解决方案吗?

而且我们还必须使用addGeoJson或loadGeoJson方法,因为GeoJson文件中有200MB的数据。

javascript google-maps mapbox geojson
1个回答
0
投票

在后端进行转换会更好,但也可以采用JS方式-使用proj4jsepsg.io查找相应的基准。

重要点:线性环的第一个和最后一个位置必须相同。否则,您的GeoJSON为not valid请注意,我的points数组如何在同一点开始和结束。


安装/包括proj4js之后:

// from https://epsg.io/27700
const EPSG_27700_DATUM = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs";

// from https://epsg.io/4326
const WGS84_DATUM = "+proj=longlat +datum=WGS84 +no_defs";

const points = [[360590,555610],[360590,555555.0128],[360590,555540],[360592.4439,555540],[360600,555540],[360600,555518.8277],[360590,555610]];

const converted_points = points.map(([lon, lat]) => {
    const convertedCoords = proj4(EPSG_27700_DATUM, WGS84_DATUM, [lon, lat]);
    return convertedCoords;
});

console.info({ converted_points });

验证您的多边形确实在GB内:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.