Buffer not working as expected since upgrading to JS 4.23

726
4
Jump to solution
04-21-2022 03:00 PM
GregoryBologna
Occasional Contributor II

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".

 view.on("click"function (event) {
    if (sketchViewModel.state === "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

https://jsitor.com/QSx-HVA_s

buffer not working in esri 4.23

https://jsitor.com/VXMCiFcYr

 

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Frequent Contributor

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.

https://jsitor.com/oBfmc8eSf

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.

View solution in original post

4 Replies
ReneRubalcava
Frequent Contributor

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

params.geometry event.graphic.geometry
 
Then you can rework how that click handler works
0 Kudos
GregoryBologna
Occasional Contributor II

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?

0 Kudos
ReneRubalcava
Frequent Contributor

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.

https://jsitor.com/oBfmc8eSf

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.

GregoryBologna
Occasional Contributor II

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;

 

0 Kudos