Cancelling hitTest with controller

240
2
06-01-2020 04:21 PM
AlexandraDunham
New Contributor II

Hi there,

We are updating our webapp to use API version 4.15, and now that dojo promises are no longer around, we need to change over some of our code. With mapView.hitTest, we used to use cancel() to cancel it. I noticed the docs don't have anything about accepting an abort signal in this method. Is this something that is coming soon?

In the meantime, do you have any up to date examples of making hitTest cancellable?

The context we are using it in is updating featureEffect on the layerView based on the results of hitTest.

Thank you,

Alex Dunham

0 Kudos
2 Replies
JohnGrayson
Esri Regular Contributor

Have you tried using the PromiseUtils 'debounce' method: 

https://jscore.esri.com/javascript/latest/api-reference/esri-core-promiseUtils.html#debounce 

0 Kudos
AlexandraDunham
New Contributor II

Yes, trying that at the moment. It kind of works, but I noticed when logging event inside hitTest it still calls it many times, and what I want is to make it faster to update the layerView effect by cancelling whatever it is doing inside handleMouseMove when the event is called again.

Example: 

const debouncedUpdate = promiseUtils.debounce((event=>
      this.handleMouseMove(event)
    );
    const mapViewMouseMoveHandler = mapView.on("pointer-move", (event=>
      debouncedUpdate(event).catch((err=> {
        if (!promiseUtils.isAbortError(err)) {
          throw err;
        }
      })
    );

where handleMouseMove is:

handleMouseMove = (event=> {    
      const { mapView } = this.props;
  
        mapView.hitTest(event).then((hit=> {
          const { results } = hit;
          if (results.length === 0this.handleRemoveAllHighlight();
          else this.handleHighlighting(results);
        })
  };
0 Kudos