Select to view content in your preferred language

Using a UniqueValueRenderer. How do you tell it to update when you know the value has changed?

2999
6
06-15-2016 07:05 AM
JustinJackson
New Contributor


I'm using a UniqueValueRenderer with a function for the field.  There are times in my program when I know that the value returned by this function will have updated for some of the features.  But they don't update on the map.

Is there a way to tell the feature layer to rerender itself?

Tags (2)
0 Kudos
6 Replies
KristianEkenes
Esri Regular Contributor

Hi Justin,

In 3.x you should call the redraw() method on the featureLayer after the values have updated.

function updateValues(){
  // values are updated in the layer
  featureLayer.redraw();
}

In 4.0 the redraw capability in the FeatureLayer is built-in. To ensure the layer's renderer updates, you will need to clone the renderer and reset it on the FeatureLayer.

function updateValues(){
  // values are updated in the layer
  featureLayer.renderer = featureLayer.renderer.clone();
}

The latter example is a bit contrived, but works. Do you have a sample you could share that shows what you're trying to do?

quooston
New Contributor III

Hello @KristianEkenes ,

I have been looking for a solution to this problem for a while now, and came across this post. I am using the latest version: 4.24.

In my call to applyEdits when the promise resolves, I am doing what you suggested above... but unfortunately to no effect. If I leave it long enough, something does seem to trigger a refresh and the updates become visible. So, I know the code works in principle, but the visual update to the map seems to be non-deterministic and that is what I want to take control of. 

I have a FeatureLayer with a unique-value renderer. I have 4 symbols that are defined for those unique values, and I am updating an attribute on the features on the client and want the appropriate symbols to be rendered when that happens.

My application has data that is always changing, and the map needs to be able to keep up with those state changes on an ongoing basis. Locations of features are constantly changing and the state of those features is also changing. The backend of the application is my own and I am not using any backend features provided by the ArcGIS platform. I am using the JS API and have a SPA with the map embedded. API calls fire off on a regular basis for various things and land up updating the map for all kinds of reasons. 

I would sincerely appreciate some feedback on this one, and would be happy to provide more information.

Thanks in advance.

0 Kudos
KristianEkenes
Esri Regular Contributor

Hi @quooston ,

Can you create a small test app that reproduces the issue? This should work...so I'll need an app to help debug to help isolate the issue. You can also reach out to Support if the data you're working with is private or sensitive. They can set up a similar test dataset and help reproduce as well.

 

0 Kudos
quooston
New Contributor III

Hey @KristianEkenes ,

I thought I would share one more detail here. 

I have a number of ajax requests hitting various APIs on intervals, the results of which usually have some kind of impact on the displayed map. I found that if I update the attribute I care about for the main API poll, it works... but for the one I care about for this particular feature, it doesn't. Super weird especially given that they share the same code for doing the actual update to the map through applyEdits. 

I will still try to put something together to replicate the issue, but I thought I would share that in case it gets you thinking of something. Could there be some kind of race condition for updating the attributes of the features on the map? Is there a check I can perform when applying edits to ensure that there is no conflict or something? 

Thanks again. 

0 Kudos
quooston
New Contributor III

I fixed it... 

PEBKAC! I was triggering the main update after the one I care about as well. Not sure why that would do anything with the attribute I care about (it updates the coordinates) but it must have been nullifying my attribute update straight away, making it override the change I had just made. I guess if I set the attribute to what it currently is again it might work that way. But, I don't need to... so all good. 

0 Kudos
quooston
New Contributor III

Ok sure, I will put something together. 

Thanks 

0 Kudos