Since upgrading JS API from 4.17 to 4.23, geometry buffer query is not working well or not working at all. I have two jsitor bins provided below. The first bin was created on 11/17/2020; the bin second was created on 4/19/2022. (Any deprecated objects in version 4.23 were updated).
The code is pretty much the same for both, with the exception for line 685 in 4.23 which I need to add in order to prevent a "Missing 'geometry' for identify operation." exception.
I think the view on click event is not triggered as quickly as in 4.17, and when the event is triggered, the sketchViewModel.state is "completed" but rarely "active".
Click the widget in the top right (envelope icon). Click the point icon in the now opened buffer tools panel. Click anywhere on the map. In 4.17, the area will be selected immediately, while in 4.23, nothing!
buffer working in esri 4.17
buffer not working in esri 4.23
Solved! Go to Solution.
The SketchViewModel state does change. It looks like while it's active, the view "click" event can't be captured. This is probably due to the introduction of snapping over the previous releases.
If you update your code like this, it works.
if (event.state === "complete") {
if(event.graphic.geometry.type === "point") {
params.returnGeometry = true;
params.geometry = event.graphic.geometry;
params.mapExtent = view.extent;
identifyTask.execute(params)
.then(function (response) {
var results = response.results;
let feature = results.map(function (result) {
var feature = result.feature;
var layerName = result.layerName;
feature.attributes.layerName = layerName;
return feature;
});
if (feature && feature[0]) {
sketchGeometry = feature[0].geometry;
runQuery();
}
})["catch"](promiseRejected);
...
If you need to do something when the SketchViewModel state is active, you can do something like this.
sketchViewModel.watch("state", (state) => {
if ("active" === state) {
// stuff
}
});
You just need to refactor a little bit.
It looks like the MapView click event is superseded by Sketch events, so when you try to set the point for your identity geometry it doesn't get set, and you're ternary check for it doesn't pass, so you never actually call the Identify.
You could grab the geometry of the graphic from the sketch
Thank you, Rene. I’ll give that a try. This has been working for awhile in 4.17, and it will work in 4.23, but the sketchViewModel state is not always returning active. Must be like you say. Do you think 4.23 requires a different buffer handling than 4.17?
The SketchViewModel state does change. It looks like while it's active, the view "click" event can't be captured. This is probably due to the introduction of snapping over the previous releases.
If you update your code like this, it works.
if (event.state === "complete") {
if(event.graphic.geometry.type === "point") {
params.returnGeometry = true;
params.geometry = event.graphic.geometry;
params.mapExtent = view.extent;
identifyTask.execute(params)
.then(function (response) {
var results = response.results;
let feature = results.map(function (result) {
var feature = result.feature;
var layerName = result.layerName;
feature.attributes.layerName = layerName;
return feature;
});
if (feature && feature[0]) {
sketchGeometry = feature[0].geometry;
runQuery();
}
})["catch"](promiseRejected);
...
If you need to do something when the SketchViewModel state is active, you can do something like this.
sketchViewModel.watch("state", (state) => {
if ("active" === state) {
// stuff
}
});
You just need to refactor a little bit.
Rene. I removed the check for active and added event.graphic.geometry as shown in your answer. I also don't need to capture the screenPoint anymore. Works great. Thanks.
params.geometry = event.graphic.geometry;