使用 ArcGIS Javascript API 查看场景服务时出错 - 无法使用 'in' 运算符搜索 'code' 错误
Getting error on viewing Scene Service using ArcGIS Javascript API - Cannot use 'in' operator to search for 'code' in false
我正在使用 ArcGIS Javascript API 4.11。从我的门户查看场景服务并提供其 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
portal item you are trying to load is in fact a BuildingSceneLayer. The above code tries to load it as a regular 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-specific 功能的示例:
我正在使用 ArcGIS Javascript API 4.11。从我的门户查看场景服务并提供其 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
portal item you are trying to load is in fact a BuildingSceneLayer. The above code tries to load it as a regular 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-specific 功能的示例: