Cesium 中使用Proj4

由于Cesium三维球默认是WGS84的,要想加载一些CGCS2000坐标系的一些矢量文件。
比如geojson,kml等,需要在加载数据的时候动态转换坐标。
以下介绍加载2000坐标系的Geojson方法。

将点坐标从CGCS2000坐标系EPSG:4524转换为WGS84坐标系

import { default as proj4 } from "proj4";

Cesium.GeoJsonDataSource.crsNames[
  "urn:ogc:def:crs:EPSG::4524"
] = Cesium.GeoJsonDataSource.crsNames["EPSG:4524"] = function(coordinates) {
  const fromProj = `PROJCS["CGCS2000 / 3-degree Gauss-Kruger zone 36", 
        GEOGCS["China Geodetic Coordinate System 2000", 
          DATUM["China 2000", 
            SPHEROID["CGCS2000", 6378137.0, 298.257222101, AUTHORITY["EPSG","1024"]], 
            AUTHORITY["EPSG","1043"]], 
          PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], 
          UNIT["degree", 0.017453292519943295], 
          AXIS["Geodetic longitude", EAST], 
          AXIS["Geodetic latitude", NORTH], 
          AUTHORITY["EPSG","4490"]], 
        PROJECTION["Transverse_Mercator", AUTHORITY["EPSG","9807"]], 
        PARAMETER["central_meridian", 108.0], 
        PARAMETER["latitude_of_origin", 0.0], 
        PARAMETER["scale_factor", 1.0], 
        PARAMETER["false_easting", 36500000.0], 
        PARAMETER["false_northing", 0.0], 
        UNIT["m", 1.0], 
        AXIS["Easting", EAST], 
        AXIS["Northing", NORTH], 
        AUTHORITY["EPSG","4524"]]`;
  const toProj = `GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG", "6326"]], PRIMEM["Greenwich", 0, AUTHORITY["EPSG", "8901"]],
        UNIT["degree", 0.0174532925199433, AUTHORITY["EPSG", "9122"]], AUTHORITY["EPSG", "4326"]]`;

  const x = coordinates[0];
  const y = coordinates[1];

  const newCoordinates = proj4(fromProj, toProj, [x, y]);
  return Cesium.Cartesian3.fromDegrees(newCoordinates[0], newCoordinates[1], 0);
};

参考:https://blog.csdn.net/u014556081/article/details/118393987

你可能感兴趣的:(Cesium 中使用Proj4)