尝试一下在线预览此示例演示如何将 web scene 从 GeoScene Portal 项目加载到自定义应用程序中。 这个场景展示了新西兰奥塔哥皇后镇周围群山在冬至(2014 年 6 月 21 日)投下的阴影。 每条线代表一天中特定时间周围山脉投射的阴影边缘。
加载一个 web scene 很容易。所需要的只是来自门户的 WebScene 项目的项目 ID 。
创建一个新的 WebScene 实例并在 WebScene 的 portalItem 属性中设置门户项目 ID。 由于 WebScene 扩展了 geoscene/Map ,因此您可以在 SceneView 的 map
属性上设置 web scene 实例。
Load a basic webscene
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<title>Load a basic web scene | Sample | GeoScene API for JavaScript 4.22</title>
<link rel="stylesheet" href="https://js.geoscene.cn/4.23/geoscene/themes/light/main.css" />
<script src="https://js.geoscene.cn/4.23/"></script>
<script>
require(["geoscene/views/SceneView", "geoscene/WebScene"], (SceneView, WebScene) => {
const titleDiv = document.getElementById("titleDiv");
/************************************************************
* Creates a new WebScene instance. A WebScene must reference
* a PortalItem ID that represents a WebScene saved to
* arcgis.com or an on-premise portal.
*
* To load a WebScene from an on-premise portal, set the portal
* url with geosceneConfig.portalUrl.
************************************************************/
const scene = new WebScene({
portalItem: {
// autocasts as new PortalItem()
id: "3a9976baef9240ab8645ee25c7e9c096"
}
});
/************************************************************
* Set the WebScene instance to the map property in a SceneView.
************************************************************/
const view = new SceneView({
map: scene,
container: "viewDiv",
padding: {
top: 40
}
});
view.when(function() {
// when the scene and view resolve, display the scene's
// title in the DOM
const title = scene.portalItem.title;
titleDiv.innerHTML = title;
});
});
</script>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#titleDiv {
background-color: lightgray;
color: black;
padding: 5px;
position: absolute;
z-index: 2;
top: 0;
right: 0;
font-size: 20pt;
font-weight: bolder;
width: 100%;
height: 30px;
text-align: center;
opacity: 0.75;
}
</style>
</head>
<body>
<div id="viewDiv" class="geoscene-widget"><div id="titleDiv"></div></div>
</body>
</html>
要从本地门户引用项目,请在 geosceneConfig.portalUrl 中设置门户的 URL。
请参阅 GeoScene 组织门户 ,了解用于 JavaScript 的 GeoScene API 如何使用门户项目。