ImageryLayer - 影像坐标系

尝试一下在线预览

此示例演示如何在影像空间的影像服务中添加影像,而不是将其投影到地图坐标。ImageryLayer 的实例将以其原始影像坐标系添加到 MapView 中的地图中。影像坐标系允许您在 2D MapView 中显示影像,而不会出现任何失真。在某些情况下,将影像转换为地图坐标可能会导致影像看起来倾斜或扭曲,因为使用了各种变换和地形校正。许多以影像为中心的工作流要求以影像坐标系而不是地图坐标(地理坐标系或投影坐标系)显示影像。例如,倾斜影像在地图坐标中显示时会显著失真,但使用影像坐标系可以在充值视图中很好地显示而不会失真。

以下两个影像显示了同一影像在其原始坐标系中显示时与在 WGS84 中显示时的外观有何不同。

 WGS84 中的影像坐标系中的影像
image-wgs84 image-ics

工作原理

加载应用程序时,ImageryLayer 将使用指定影像 ID 的镶嵌规则初始化。

             
1
2
3
4
5
6
7
8
9
10
11
12
13
// imageId will be used to set the mosaic rule on the layer
// Initial value to be set when the app loads.
const imageId = 1599;

// new imagery layer
layer = new ImageryLayer({
  url: url,
  mosaicRule: {
    method: "lock-raster",
    operation: "first",
    lockRasterIds: [imageId]
  }
});

初始化图层后,将调用 setViewIcsInfo() 以设置 ImageryLayer 的视图。在此函数中,在具有指定影像 ID 的图层上调用 getCatalogItemICSInfo()。此方法获取影像的影像坐标系。然后,此坐标系用于设置视图的 spatialReference。

                                              
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// This function is called when the app loads and
// when users makes a new selection for raster ids from
// the itemIds dropdown. It will recreate MapView using
// ics info returned for the specified raster
function setViewIcsInfo(imageId){
  // get the image coordinate system of the item in an image service.
  layer.getCatalogItemICSInfo(imageId).then((info) => {
    const icsInfo = document.getElementById("icsInfo");
    icsInfo.innerHTML = "Image id: <b>" + imageId
  + "</b><br/> North direction: <b>"
  + Math.round(info.northDirection) + "</b>";
    // use the short-handed ics representation
    // the server will lookup the spatialReference for the raster
    const spatialRef = {
      imageCoordinateSystem: { id: imageId }
    };

    // create an extent for the map view using extent info
    // returned in ics info
    const viewRect =  document.getElementById("viewDiv");
    const width = viewRect.getBoundingClientRect().width;
    const height = viewRect.getBoundingClientRect().height;

    const newExtent = info.icsExtent.clone();
    const scaleFactor = 8;
    newExtent.xmin = (newExtent.xmin + newExtent.xmax - width * scaleFactor) / 2;
    newExtent.xmax = newExtent.xmin + width * scaleFactor;
    newExtent.ymin = (newExtent.ymin + newExtent.ymax - height * scaleFactor) / 2;
    newExtent.ymax = newExtent.ymin + height * scaleFactor;
    newExtent.spatialReference = spatialRef;

    // set the view container to null so that we can display the selected raster
    if (view){
      view.container = null;
    }
    // set the view spatialReference and extent
    view = new MapView({
      container: "viewDiv",
      map: map,
      spatialReference: spatialRef,
      extent: newExtent
    });

    view.ui.add(selectDiv, "top-right");
  });
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.