So I am both new to Javascript and new to this ArcGIS API. I know I'm just missing some sort of basic knowledge so I figured I'd turn to the experts.
I have just came back from not doing any coding for about a year, so things are definitely not fresh. I'm attempting to use the GeometryEngine with the 4.26 API to buffer a radius from a given feature/set of features.
Currently it's saying that the geometry is null (line 9 in the code below), so it isn't seeing any of the features data inside this function. I am sure I had this working at one point. Can anyone tell me how to get the features data accessible from inside this function? (If you need more information about the rest of my code just let me know).
function buffertheSelection(event) {
if (bufferSelection.classList[2] === "button-text") {
var parcel = [];
var dist = [];
dist.push(300);
bufferSelection.classList.remove("button-text");
bufferSelection.classList.add("active");
for (i=0; i < features.length; i++){
parcel.push(features[i].feature.geometry);
}
const ptBuff = geometryEngine.buffer(parcel, dist, "feet", true);
featureTable.clearSelectionFilter();
bufferGraphic = new Graphic ({
geometry: ptBuff[0].extent,
symbol: {
type: "simple-fill",
color: ([153, 255, 255, 0.5])
}
});
bufferGraphic.layer === parcelSearchLayer;
view.graphics.add(bufferGraphic);
featureTable.filterGeometry = ptBuff[0].extent;
} else {
bufferSelection.classList.remove("active");
bufferSelection.classList.add("button-text");
view.graphics.remove(bufferGraphic);
}
}
Thanks for taking a look!
How is features being created? Maybe log features to the console before you call it in your function so you can inspect its contents and ensure there's a geometry property and you're accessing it correctly.
This is the basic bit of knowledge that I can't figure out. I am clicking on my map and it is highlighting the feature and adding the feature's information to the featureTable, so I know the graphic exists somewhere. I just can't figure out what variable contains the geometry of the highlighted graphic.
Line 9 should be
parcel.push(features[i].geometry);
Unfortunately this isn't the case, since features is null.
If features is null, how is it even going through the loop in lines 8-10?
My guess is that since the length is 0, it runs through it once, pushing a null value to parcel.
It won't go through the loop once, though. In JSBin, this is what happens with your loop when features is not empty
And this is when features is empty