I am attempting to rewrite a map from 3.13 to 4.26 and am a little stuck.
We have a service that contains a map of our state counties, with attributes "COUNTYNAME" and "render_Data".
Users of our website select a year and a category from dropdowns, click a "View Map" button, and the map renders with a ClassBreaksRenderer that colors the counties based on the rate the thing they selected happened in their chosen year in each county. When they hover over a county, it shows a popup that gives the exact rate.
On the service, the "render_Data" value is empty. That field is meant to hold the rate value, but the rate values aren't known until the user clicks View Map and our database is queried to bring back the rates for the year/category the user is interested in.
I apologize if I'm using the wrong terminology, but I believe what I want to do after the user clicks the View Map button is:
Go to our database and get the list of rates for the chosen year/category. This returns as json data that has the county name and rate (render_Data) for each county.
Get the feature layer from the service and create a client-side copy. (When I say "client-side copy", I mean I don't want to apply the following changes to the source/service, I want them to be temporary for the single user and disappear when the page refreshes).
Loop through the counties in the client-side feature layer and set the render_Data attribute to the matching rate attribute in the json returned from the database (matching on the county name, because both the json and the feature layer have a county name attribute/field).
Tell the ClassBreaksRenderer and PopupTemplate to look at the render_Data attribute that was just populated.
Load (or maybe refresh?) the map/view.
This seems like something there might be sample code for already, I'm just having trouble finding it.
I'm getting stuck on the timing/ordering of events. I'm also not sure if things like queryFeatures() and applyEdits() are going back to the original source, or if they can/are used on the temporary object I'm working with.
I made a codepen to lay out the basic idea, simplified as much as possible.
I'm not sure at which point I would loop though the feature_layer.graphic.attributes and update the render_Data value, and how exactly that works.
https://codepen.io/rhip/pen/zYMZGZP
Can anybody point me in the right direction?