Openlayers - 从特定投影转换多边形,如 EPSG:28992

Openlayers - transform polygon from a specific projection like EPSG:28992

如何向我的地图添加具有特定投影的简单多边形?

多边形有效,我之前检查过

coordinatesPolygonInRd = [ [ [173563, 441818], [173063, 441818], [173063, 444318],
      [173563, 444318], [173563, 441818] ] ];

这就是我在将多边形放入地图之前尝试对其进行变换的方式:

尝试 1:

let dutchProjection = new Projection({
  code: 'EPSG:28992',
  extent: [-285401.92, 22598.08, 595402.0, 903402.0],
  worldExtent: [3.2, 50.75, 7.22, 53.7],
  units: 'm'
});
addProjection(dutchProjection);

const geometry = new Polygon( this.coordinatesPolygonInRd).transform( 'EPSG:28992', this.map.getView().getProjection());
this.vectorLayer.getSource().addFeature(new Feature(geometry));

尝试 2:

proj4.defs["EPSG:28992"] = "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000  +ellps=bessel  +towgs84=565.040,49.910,465.840,-0.40939,0.35971,-1.86849,4.0772 +units=m +no_defs";
register(proj4)
let dutchProjection = GetProjection('EPSG:28992');
const geometry = new Polygon( this.coordinatesPolygonInRd).transform( 'EPSG:28992', this.map.getView().getProjection());
this.vectorLayer.getSource().addFeature(new Feature(geometry));

方法 2 可以,但是你的 proj4 语法错误,应该是

proj4.defs("EPSG:28992","+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000  +ellps=bessel  +towgs84=565.040,49.910,465.840,-0.40939,0.35971,-1.86849,4.0772 +units=m +no_defs");

您可以在注册proj4定义后选择性地设置投影范围等。