Repository navigation
Expand file tree
/
Copy pathhighlightSceneLayer.html
More file actions
204 lines (189 loc) · 6.74 KB
/
Copy pathhighlightSceneLayer.html
File metadata and controls
204 lines (189 loc) · 6.74 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!-- https://codepen.io/pen?editors=1000 -->
<!-- https://developers.arcgis.com/javascript/latest/sample-code/highlight-scenelayer/index.html -->
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<!--
ArcGIS API for JavaScript, https://js.arcgis.com
For more information about the highlight-scenelayer sample, read the original sample description at developers.arcgis.com.
https://developers.arcgis.com/javascript/latest/sample-code/highlight-scenelayer/index.html
-->
<title>
Highlight SceneLayer | Sample | ArcGIS API for JavaScript 4.17
</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.17/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.17/"></script>
<script>
require([
"esri/WebScene",
"esri/views/SceneView",
"esri/tasks/support/Query",
"esri/widgets/Legend"
], function (WebScene, SceneView, Query, Legend) {
// Load webscene from portal item
var webscene = new WebScene({
portalItem: {
// autocasts as new PortalItem()
id: "fbbc829fa7d342e7ae8d18c54a5eab37"
}
});
// Create a view and set the highlight options
var view = new SceneView({
container: "viewDiv",
map: webscene,
qualityProfile: "high",
environment: {
lighting: {
directShadowsEnabled: false,
ambientOcclusionEnabled: true
}
},
highlightOptions: {
color: [0, 255, 255],
fillOpacity: 0.6
}
});
// This variable will store the highlight handle that is used to remove the highlight
var highlight = null;
view.when(function () {
// Get layer from webScene
var officeSceneLayer = webscene.allLayers.filter(function (elem) {
return elem.title === "Esri Offices";
}).items[0];
// define the attributes which are used in the query
officeSceneLayer.outFields = ["ROOMNUMBER", "SPACETYPE"];
// Get DOM element where list items will be placed
var container = document.getElementById("roomsList");
// Highlight is set on the layerView, so we need to detect when the layerView is ready
view.whenLayerView(officeSceneLayer).then(function (officeLayerView) {
// Wait for the layer view to finish updating
officeLayerView.watch("updating", function (val) {
if (!val) {
// Query the features available for drawing and get all the attributes
var query = new Query();
officeLayerView.queryFeatures(query).then(function (result) {
// Empty the list DOM element
container.innerHTML = "";
// For each returned feature that is of type office create a list item and append it to the container
result.features.forEach(function (feature) {
var attributes = feature.attributes;
// We only want to add features of type Office to the list
if (attributes.SPACETYPE === "Office") {
// Create list element
var li = document.createElement("li");
li.setAttribute("class", "panel-result");
li.innerHTML = "Room " + attributes.ROOMNUMBER;
li.addEventListener("click", function (event) {
var target = event.target;
var objectId = feature.attributes.OBJECTID;
// Create an extent query on the layer view that will return the 3D extent of the feature
var queryExtent = new Query({
objectIds: [objectId]
});
officeLayerView
.queryExtent(queryExtent)
.then(function (result) {
// Zoom to the extent of the feature
// Use the expand method to prevent zooming in too close to the feature
if (result.extent) {
view
.goTo(result.extent.expand(7), {
speedFactor: 0.5
})
.catch(function (error) {
if (error.name != "AbortError") {
console.error(error);
}
});
}
});
// Remove the previous highlights
if (highlight) {
highlight.remove();
}
// Highlight the feature passing the objectId to the method
highlight = officeLayerView.highlight([objectId]);
});
container.appendChild(li);
}
});
});
}
});
});
});
// Add a legend to the sample
var legend = new Legend({
view: view
});
view.ui.empty("top-left");
view.ui.add(legend, "bottom-left");
});
</script>
<style>
html,
body,
#viewDiv {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
.panel-side {
width: 200px;
position: absolute;
top: 14px;
right: 14px;
bottom: 28px;
color: #323232;
background-color: rgb(255, 255, 255);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
overflow: auto;
z-index: 60;
font-size: 12px;
text-align: center;
}
.panel-side h2 {
padding: 0 20px;
margin: 20px 0;
font-size: 14px;
font-weight: 600;
}
.panel-side ul {
list-style: none;
margin: 0;
padding: 0;
font-weight: 100;
}
.panel-side li {
list-style: none;
padding: 3px 10px;
}
.panel-result {
cursor: pointer;
margin: 2px 0;
}
.panel-result:hover,
.panel-result:focus,
.panel-result.selected {
background-color: rgba(200, 200, 200, 0.6);
}
</style>
</head>
<body>
<div class="panel-side esri-widget">
<h2>Office rooms</h2>
<ul id="roomsList">
<li>Loading…</li>
</ul>
</div>
<div id="viewDiv"></div>
</body>
</html>