簡體   English   中英

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 定義后,您可以選擇設置投影范圍等。

我將 proj4.js 從 2018 年更新到最新版本,現在我得到:

proj4.js?22182:1 未捕獲的類型錯誤:坐標必須是有限數在 z (proj4.js?22182:1) at ns (proj4.js?22182:1) at D (proj4.js?22182:1) at U (proj4.js?22182:1) at W (proj4.js?22182:1) .. 問題在於 EPSG:28992 定義,是否需要更改?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM