Using JavaScript in the ArcGIS API, I am querying a feature layer from a Map View, calculating points within a certain radius when the user "click" "drag" with the mouse. I want to be able to stop this functionality when the user presses the spacebar. However, I cannot get this to work. In the JavaScript I turn off event propagation for the "click" "drag" event and then cannot turn it back on again. I understand there is not a "on/off" switch for stopPropagation(). Can anyone recommend a different solution or workaround. An extract of the code I am struggling with below:
var bufferEnabled = false;
function keyDownListener(event) {
var keyInput = event.key;
bufferEnabled =
(keyInput === " " || keyInput === "Spacebar") && !bufferEnabled;
}
function analysis() {
view.when().then(function() {
const layer = webmap.layers.getItemAt(0);
view.whenLayerView(layer).then(function(layerView) {
watchUtils.whenFalseOnce(layerView, "updating", function(val) {
// Query layer view statistics as the user clicks
// or drags the pointer across the view.
view.on(["click", "drag"], function(event) {
// disables navigation by pointer drag
event.stopPropagation();
queryStatsOnDrag(layerView, event).then(updateCharts);
});
});
});
});
view.on("key-down", keyDownListener);
view.on("key-down", analysis);