I am using React and ArcGIS to build an interactive map that will allow a User to:
- Update the data layers displayed (suburbs, local government zones, etc) on the map
- Updated the viewport (zoom and centre) of the map
The issue I am having is with the viewport, specifically 'zoom' and 'centre'. If, for example, somebody zooms in and then updates the data layers, it will revert back to the initial state viewport settings.
For reference, this is an example of a React interactive that I'm trying to achieve: https://www.fremantleports.com.au/the-port/port-map. As you can see, it allows you to update the data layers displayed (Buildings, Berths, etc...) without reverting back to the original zoom settings.
To achieve the above result, I have tried two methods:
useStateand pass down the 'active layers' from the 'Sidebar Component' to the 'Map Component'. The problem is that it will revert back to the initial state viewport settings every time a user changes the data layers displayed.useContext(and also withreact-tracked) and ArcGISwatchUtilsfunctions to and keep track of the activeLayers, zoom, and centre using global state. However, the problem was that the map re-rendered every time the user changed the zoom level.
Aim
https://www.fremantleports.com.au/the-port/port-map
Question
Which of the above approach is preferable, and how should I use that approach to achieve the desired goal?