当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JavaScript ArcGIS WebScene用法及代码示例


基本信息

以下是所在类或对象的基本信息。

AMD: require(["esri/WebScene"], (WebScene) => { /* code goes here */ });

ESM: import WebScene from "@arcgis/core/WebScene";

类: esri/WebScene

继承: WebScene > Map > Accessor

自从:用于 JavaScript 4.0 的 ArcGIS API

用法说明

Web 场景是跨 ArcGIS 进行 3D 映射的核心元素。它定义了场景的内容、样式、环境和幻灯片,并且可以在多个ArcGIS Web 和桌面应用程序之间共享。可以使用 Scene ViewerArcGIS Pro 和 ArcGIS Online 中创建、发布和使用 Web 场景。 Web 场景保存为 JSON 文档,ArcGIS API for JavaScript 通过WebScene 类可以轻松创建引人注目的 3D 应用程序。 JSON 文档是根据 web scene specification 编写的。

尽管您可以轻松创建自己的场景,但仍有数以千计的公开可用的web scenes in ArcGIS Online 可供您开始使用 API。您可以对这些场景进行修改或添加新内容。

要将 WebScene 加载到 SceneView 中,您只需通过此类的 PortalItem 属性引用 ArcGIS Online 中的 Web 场景项的 ID。

const scene = new WebScene({
  portalItem: { // autocasts as new PortalItem()
    id: "affa021c51944b5694132b2d61fe1057"  // ID of the WebScene on arcgis.com
  }
});

要从 on-premise 门户加载 WebScene,请在 esriConfig.portalurl 中设置门户 URL。

esriConfig.portalUrl = "https://myHostName.esri.com/arcgis";

const scene = new WebScene({
  portalItem: { // autocasts as new PortalItem()
    id: "0614ea1f9dd043e9ba157b9c20d3c538"  // ID of the WebScene on the on-premise portal
  }
});

然后,您必须在 SceneViewmap 属性中引用 WebScene 实例。

const view = new SceneView({
  map: scene,  // The WebScene instance created above
  container: "viewDiv"
});

这将开始将所有图层和场景选项加载到 3D SceneView 中。可以调用 WebScene 实例上的 when() 方法来执行只能在加载 WebScene 后运行的进程。

scene.when(function() {
  // All layers and the basemap have been created
});
view.when(function() {
  // All layer and basemap resources have been loaded and are ready to be displayed
});

webscene

WebScene 定义场景的内容以及场景在应用程序中加载时的外观。使用此类时,您可能会与 Web 场景的几个常见属性进行交互:

  • 图层:定义 Web 场景的内容和样式,以及弹出窗口、标签、图例和其他设置。
  • 底图:定义 Web 场景的底图图层。
  • 地面:定义 web 场景的高程图层。
  • 演示文稿:包含网络场景幻灯片。
  • InitialViewProperties
    • Environment :配置场景的照明、阴影和氛围。
    • Viewpoint :配置初始视点。
    • ViewingMode :定义网络场景是全局的还是本地的。

有关 Web 场景属性的更多信息,请参阅web scene specification

Web 场景有两种类型:globallocal。全局场景将地球渲染为球体,而局部场景将地球渲染为平面。可以使用 WebMercator、WGS84、CGCS2000、Mars_2000_(Sphere)、GCS_Mars_2000 和 GCS_Moon_2000 创建全局 web 场景。可以使用 WGS84、CGCS2000 或任何投影坐标系创建本地 web 场景。阅读 ArcGIS 在线帮助以了解有关 choosing global or local scenes 的更多信息。

幻灯片存储场景可视化状态的快照,稍后可以将其重新应用到场景。幻灯片包含视点、图层可见性、底图和环境(以及标题和缩略图)的属性,以便 3D 应用程序的用户可以轻松导航场景并准确地重新创建该场景的存储视图。

可以使用saveAs()或save()将网络场景保存到ArcGIS Online或Portal。定义门户,加载后保存 Web 场景。

const portal = new Portal({
  url: "https://myportal.arcgis.com/", // the url of the portal
  authMode: "immediate" // user authenticates by signing in when the Portal is loaded
});
// once the portal is loaded save the web scene to the portal as a new web scene
portal.load().then(function() {
  webscene.saveAs({
    title: "My Scene",
    portal: portal
  })
  .then(function() {
    console.log("Scene was saved");
  })
  .catch(function(err) {
    console.log(err);
  });
})

请务必注意,GraphicsLayerImageryLayerStreamLayer 不能保存到 Web 场景中。通过将缓存的图像服务声明为 TileLayer ,可以将其保存到 Web 场景中。 OpenStreetMapLayer 可以保存为 baseLayer 。有关可保存在 Web 场景中的图层类型的详细信息,请参阅web scene specification

相关用法


注:本文由纯净天空筛选整理自arcgis.com大神的英文原创作品 WebScene。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。