高亮显示 SceneLayer

尝试一下在线预览

此示例演示如何高亮显示表示校园建筑物的 SceneLayer 中的要素。当 SceneLayerView 完成更新后,我们将遍历所有加载的要素,并将它们放在一个列表中。每个列表项上都会添加一个事件侦听器,该列表项将缩放到要素的 3D 范围并高亮显示该要素。

要高亮显示要素,请使用要素或其 objectID 作为参数调用要素的相应 layerView高亮显示方法。

                    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// add event listener on each list item
li.addEventListener("click", (event) => {
  const target = event.target;
  // get objectId of the feature that we previously stored as a data attribute
  const objectId = parseInt(target.getAttribute("data-object-id"));
  // create an extent query on the layer view that will return the 3D extent of the feature
  const queryExtent = new Query({
    objectIds: [objectId]
  });
  campusLayerView.queryExtent(queryExtent).then((result) => {
    // zoom to the extent of the feature; we use the expand method as we don't want to zoom very close to it
    view.goTo(result.extent.expand(4), { speedFactor: 0.5 });
  });
  // if any, remove the previous highlights
  if (highlight) {
    highlight.remove();
  }
  // highlight the feature with the returned objectId
  highlight = campusLayerView.highlight([objectId]);
});

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.