Stop updating view when move by cursor

641
2
02-20-2022 11:49 PM
Vakhtang_Zubiashvili
Occasional Contributor III

Hi all,

 

I have one issue on my map, when i add feature layer on map after generated it from expression i goTo result, it works fine, but when i want to zoom in or zoom out or move side, extent updates automatically and returns me back to first generated extent. when i remove TARGET and ZOOM code does not work.

how can i stop continuously updating my extent?

Thanks.

 

here is code snippet i use to goTo() layer:

view.whenLayerView(xaro).then(function(layerView) {
 layerView.watch("updating", function(value) {
   if (!value) {
     layerView
       .queryFeatures()
       .then(function(results) {
         // do something with the resulting graphics
         graphics = results.features;
         view.goTo({target: graphics, zoom: 15})
       });
   }
 });
});

 

0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor

You can do this a couple of ways. Most convenient is to use whenFalseOnce()

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-watchUtils.html#whenFalseOnc...

The other is to ruse the WatchHandle remove method when done

https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Accessor.html#WatchHandle

const handle = layerView.watch("updating", (value) => {
    // do your thing
    handle.remove()
})

 

Vakhtang_Zubiashvili
Occasional Contributor III

Thank you Rene, works like a charm 🙂

0 Kudos