Need help removing highlight from 3D scene layer JavaScript API

584
2
03-25-2019 05:36 AM
JeremySingh1
New Contributor II

Below is my code that I have been tinkering with, however, I can't seem to figure how to remove highlighting from my 3D buildings. Not sure how to go about it.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Intro to SceneLayer - 4.10</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>

<link rel="stylesheet" href="https://js.arcgis.com/4.10/esri/css/main.css">
<script src="https://js.arcgis.com/4.10/"></script>

<script>
require([
"esri/Map",
"esri/views/SceneView",
"esri/layers/SceneLayer"
], function(Map, SceneView, SceneLayer) {

// Create Map
var map = new Map({
basemap: "dark-gray",
ground: "world-elevation"
});

// Create the SceneView
var view = new SceneView({
container: "viewDiv",
map: map,
camera: {
position: [-80.196073,25.792461, 707],
tilt: 81,
heading: 50
}
});

// Create SceneLayer and add to the map
var sceneLayer = new SceneLayer({
portalItem: {
id: "b162d491955744ff9e9de7913bb49693 "
},
popupEnabled: false
});
map.add(sceneLayer);

// Create MeshSymbol3D for symbolizing SceneLayer
var symbol = {
type: "mesh-3d", // autocasts as new MeshSymbol3D()
symbolLayers: [{
type: "fill", // autocasts as new FillSymbol3DLayer()
// If the value of material is not assigned, the default color will be grey
material: {
color: [244, 247, 134]
}
}]
};
view.on("pointer-move", function(event){
view.hitTest(event).then(function(response){
let highlight;
if (response.results[0]) {
var graphic = response.results[0].graphic;
view.whenLayerView(graphic.layer).then(function(layerView){
highlight = layerView.highlight(graphic);
})

}
})
});
// Add the renderer to sceneLayer
sceneLayer.renderer = {
type: "simple", // autocasts as new SimpleRenderer()
symbol: symbol
};
});
</script>
</head>

<body>
<div id="viewDiv"></div>
</body>
</html>

0 Kudos
2 Replies
BenRomlein
Occasional Contributor

Check out the pointer-move listener on line 65, those functions/callbacks are where your highlight is applied.

GeorgeAbraham
New Contributor III

Hi Jeremy Singh‌,

I couldn't get your code to work as its throwing error for invalid Portal ID.

However what I see missing is for you to add:

if (highlight) {
      highlight.remove();
}

That should do the trick.

0 Kudos