Hi,
I have created webscene service and URL is Scene Viewer . I need to use this webscene service in my customized application. Could you please let me know how to achieve this. My code snippet, but it is not working
var scene = new WebScene({
portalItem: { // autocasts as new PortalItem()
id: "e21c6971207749c2a67a3d8441a7c09a"
}
});
var view = new SceneView({
map: scene,
container: "viewDiv",
padding: {
top: 40
}
});
Solved! Go to Solution.
The portal item id is not a sceneview it is just for a map layer so you need this code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Create a layer from a portal item - 4.5</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.5/esri/css/main.css">
<script src="https://js.arcgis.com/4.5/"></script>
<script>
require([
"esri/Map",
"esri/views/SceneView",
"esri/layers/Layer",
"dojo/domReady!"
], function(
Map, SceneView, Layer
) {
var map = new Map({
basemap: "gray"
});
var view = new SceneView({
map: map,
container: "viewDiv",
zoom: 16,
center: [55.17, 25.0295]
});
/************************************************
*
* Create a layer from an existing Portal item hosted
* in ArcGIS Online using the ID of the item.
*
*************************************************/
Layer.fromPortalItem({
portalItem: { // autocasts as new PortalItem()
id: "e21c6971207749c2a67a3d8441a7c09a"
}
}).then(addLayer)
.otherwise(rejection);
// Adds the layer to the map once it loads
function addLayer(lyr) {
map.add(lyr);
}
function rejection(err) {
console.log("Layer failed to load: ", err);
}
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
The portal item id is not a sceneview it is just for a map layer so you need this code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Create a layer from a portal item - 4.5</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
overflow: hidden;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.5/esri/css/main.css">
<script src="https://js.arcgis.com/4.5/"></script>
<script>
require([
"esri/Map",
"esri/views/SceneView",
"esri/layers/Layer",
"dojo/domReady!"
], function(
Map, SceneView, Layer
) {
var map = new Map({
basemap: "gray"
});
var view = new SceneView({
map: map,
container: "viewDiv",
zoom: 16,
center: [55.17, 25.0295]
});
/************************************************
*
* Create a layer from an existing Portal item hosted
* in ArcGIS Online using the ID of the item.
*
*************************************************/
Layer.fromPortalItem({
portalItem: { // autocasts as new PortalItem()
id: "e21c6971207749c2a67a3d8441a7c09a"
}
}).then(addLayer)
.otherwise(rejection);
// Adds the layer to the map once it loads
function addLayer(lyr) {
map.add(lyr);
}
function rejection(err) {
console.log("Layer failed to load: ", err);
}
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
Hi
Thanks for the solution and it is working.
Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.