Select to view content in your preferred language

Add graphics to graphics layer after view has finished updating

390
3
03-18-2026 08:05 AM
Labels (1)
wadsonmakari
Occasional Contributor

Hi all,

I am building an ExB custom widget that listens for the view updating event. I have set up the listener using reactiveUtils as below;

const viewUpdating = reactiveUtils.when(() => !jmvRefAMISTracking.current.view.updating,() =>{

console.log('view has finished updating, get assets in current map view.')

getAssetsInCurrentView()
//onShowErrorRings()


})

The function getAssetsInCurrentView() updates the state of grid that is displayed on the widget. In addition to updating the grid I would like to also add a few features to a graphics layer. Typically the number of fews added will be <5 with very simple geometry.

The code I have to add the graphics is shown below

locationErrorBuffers.current.graphics.add(new Graphic ({
geometry: error_circle,
symbol: sfs
}))

The line above is causing an infinite loop for some reason and my browser becomes unresponsive.

Is the a limitations on the code that I can execute after my view has finished updating? If I comment out the line that adds graphics everything works fine as I expect. Any pointers will be much appreciated.

Regards,

 

0 Kudos
3 Replies
JeffreyThompson2
MVP Frequent Contributor

I'm not surprised your getting an infinite loop. I'm pretty sure adding graphics to a layer should cause the LayerView to update. What are you trying to accomplish with this code? Maybe you need to add the Graphics to a different layer? Or perhaps, you should be watching the view.stationary property instead?

GIS Developer
City of Arlington, Texas
0 Kudos
wadsonmakari
Occasional Contributor

I have a point feature service that is updated every minute and each feature has positional error value that is updated every minute as well. The end user can select a subset of the features to display the error rings if they wish, so was thinking I could listen for when the view has finished updating get the latest positional error values and draw the error rings in graphics layer. Ideally i would like the error rings to follow the points as they move about.

Your explanation makes sense but listening for the view stationary would not achieve my objective as my graphics would only update after I manually move the map and the view is stationary. 

0 Kudos
JeffreyThompson2
MVP Frequent Contributor

Which view are you watching? The MapView or the FeatureLayerView? I think you should be able to get what you want by watching the FeatureLayerView and saving your graphics to a separate GraphicsLayer.

You might also want to try setInterval() to do something on every X milliseconds.

GIS Developer
City of Arlington, Texas
0 Kudos