I'm trying to dynamically add graphics to a scene and have tried several things.
I have a scene in an app that shows the 3d buildings in the city. When the user loads the app, I want the buildings to be colored based on the attributes of a feature layer. The feature layer shows the status and type of group homes as a parcel. I want to loop over all the group homes and find the associated 3d building and change it's color and I'm running into trouble. I tried running a spatial query on the sceneLayer using the geometry and discovered this isn't possible. I then went to the 3d sceneLayer's associatedLayer and was still unable to get the .then functions to fire.
function colorHomes(){
var bldg_lyr;
scene.layers.forEach(function(nextLayerView){
if (nextLayerView.url.indexOf("Building") > 0){
bldg_lyr = nextLayerView.associatedLayer;
}
});
//get all alf features
var alfQueryTask = new QueryTask({ url: "..../rest/services/NS/ActiveALFsTest/MapServer/0" });
var alfQuery = new Query({
where: "1=1",
outFields: ["NameFacility", "ADDRESS", "TypeFacility"],
returnGeometry: true,
outSpatialReference: view.spatialReference
});
alfQueryTask.execute(alfQuery).then(function(alfResults){
//loop over each feature
alfResults.features.forEach(function(alfFeature){
var bldgQuery = new Query({
geometry: alfFeature.geometry,
//objectIds: [13006],
outFields: ["OBJECTID"]
});
bldg_lyr.queryFeatures(bldgQuery).then(function (bldgResults){
if (bldgResults.length > 0){
console.log("++++++++++++++++++SUCCESS++++++++++++++++++");
bldgResults.forEach(function(bldg){
console.log(bldg.attributes.OBJECTID);
});
}
},
function (bldgResults){
console.log("Ouch! That's gotta hurt.");
});
});
});
}<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>