I am trying to write to a graphic layer with a user map click.
Using a hit test and allowing the user to click counties in the map and writing them to a graphic layer
these are then seen displayed in the map as the user clicks on them
this seems to work fine
viewright.on("click", function (evt) {
viewright.hitTest(evt.screenPoint).then(function (response) {
var result = response.results[0];
var symbol = {
type: "simple-fill",
color: [51, 51, 204, 0.9],
style: "solid",
outline: {
color: "white",
width: 1
}
};
var selectionGraphic = result.graphic;
selectionGraphic.symbol = symbol;
resultsLayer4.add(selectionGraphic);
});
});
I then have a button that reads the Graphics Layer and tries to return the results.
var selectButton1 = document.getElementById("select-by-polygon");
selectButton1.addEventListener("click", function () {
viewright.whenLayerView(resultsLayer4).then(function (lyrView) {
lyrView.watch("updating", function (val) {
if (!val) {
lyrView.queryFeatures().then(function (results) {
console.log(results);
});
}
});
});
});
I am unsure if I am tackling this the right way....
I want the user to click the map and select counties and write them to a graphics layer.
I then need to read this graphics layer and get the unique id of each feature in the graphics layer.
QUESTIONS:
- Am I correctly writing to the Graphics Layer? Is there a better way to do this?
- Is there a better way to query the Graphics Layer to get a list of unique IDs from a Field value?
- Is there a way to click on a County that is already in the Graphics Layer and then remove it and have the blue graphic removed?