使用ArcGIS Javascript API查看Scene Service时出错-无法使用'in'运算符以false形式搜索'code'

时间:2019-07-08 10:41:44

标签: arcgis arcgis-js-api

我正在使用ArcGIS Javascript API 4.11。从门户网站查看Scene Service并提供其ID时出现这些错误。

这是我收到的错误的屏幕截图。 Screenshot 01

这是我使用的代码。

require([
  "esri/Map",
  "esri/views/SceneView",
  "esri/layers/SceneLayer",
  "esri/identity/OAuthInfo",
  "esri/identity/IdentityManager",
  "esri/layers/ImageryLayer",
  "esri/views/layers/ImageryLayerView"
], function(
  Map, SceneView, SceneLayer, OAuthInfo, esriId, ImageryLayer, ImageryLayerView
) {
  debugger;
  var info = new OAuthInfo({
    appId: "AnFbtGbH4t9A2XTi",
    // appId: "q244Lb8gDRgWQ8hM",
    // Uncomment the next line and update if using your own portal
    // portalUrl: "https://<host>:<port>/arcgis"
    // Uncomment the next line to prevent the user's signed in state from being shared with other apps on the same domain with the same authNamespace value.
    // authNamespace: "portal_oauth_inline",
    popup: false
  });

  esriId.registerOAuthInfos([info]);

  esriId
  .checkSignInStatus(info.portalUrl + "/sharing")
  .then(function() {
    //displayItems();
  }).catch(function() {
    // Anonymous view
    esriId.getCredential(info.portalUrl + "/sharing");
  });

  var map = new Map({
    basemap: "dark-gray",
    ground: "world-elevation"
  });

  var view = new SceneView({
    container: "viewDiv",
    map: map,
  });

  var sceneLayer = new SceneLayer({
    portalItem: {
      id: "e7bf9f676ed64937bff9f44c84fdae2b"
    },
    popupEnabled: false
  });

  map.add(sceneLayer);
});

正在加载地图,但未加载场景图层。请帮忙。

我在Codepen中使用相同的ID尝试过的类似代码也给了我相同的错误-https://codepen.io/anon/pen/rEqgJB

1 个答案:

答案 0 :(得分:0)

您要加载的portal item实际上是BuildingSceneLayer。上面的代码尝试将其作为常规SceneLayer加载。

这就是为什么API报告错误SceneLayer does not support this layer type(屏幕截图中的第二个错误)的原因。

只需将SceneLayer替换为BuildingSceneLayer,一切正常:

require([
  "esri/Map",
  "esri/views/SceneView",
  "esri/layers/BuildingSceneLayer"
], function(Map, SceneView, BuildingSceneLayer) {

...

  // Create BuildingSceneLayer and add to the map
  var sceneLayer = new BuildingSceneLayer({
    portalItem: {
      id: "e7bf9f676ed64937bff9f44c84fdae2b"
    },
    popupEnabled: false
  });
  map.add(sceneLayer);

...

});

这是固定的Codepen,在加载图层后显示建筑物。 https://codepen.io/arnofiva/pen/c410babb5384945a12b1d8206ebe27ce?editors=1010


另一种实现此目的的方法是要求API load an arbitrary layer from a portal item,在这种情况下,它会自动检测图层类型:

Layer.fromPortalItem({
  portalItem: {
    id: "e7bf9f676ed64937bff9f44c84fdae2b"
  }
}).then(function(layer) {
  // Adds layer to the map
  map.add(layer);
});

您可能想查看这些显示BuildingSceneLayer特定功能的示例: