How to force a refresh on a FeatureLayer

10284
14
03-02-2020 04:51 AM
PHerk
by
New Contributor II

We have a WebMap with a FeatureLayer. The FeatureLayer has 2 sublayers. One has areas (polygons) where you can click on, the other layer should be visible after a click on the area. This is accomplished by a filter. If a field in the FeatureLayer.attributes is filled with a value, the polygon is visible in the color defined in ArcGIS online portal. In the Javascript code I return a value in the specific field. That works. The refresh() command does not update the polygon on the screen. The issue is that I have to reload the browser to see the change on the screen. The layer is updated by using the zoom buttons, but I can't find a method to refresh the layer in code, or even better, refresh the polygon. I made a silly hidescreen -> zoom in -> zoom out -> show screen function to have the layer refreshed by controlling the zoom buttons, but I can't imagine there are no other options. Found various similar questions in this community portal, tried all suggestions but there is no success. 

Who has a solution?

Appreciated.

0 Kudos
14 Replies
PHerk
by
New Contributor II

Hi John,

Thank you for your help. Really appreciated!

I changed the CodePen according to your suggestions, but unfortunately it doesn't make any difference. I changed the layer from the second ("Vlakken - gereed") to the first ("Vlakken") otherwise the Date value field will not get written. What I don't understand is that the Featurelayer ID is not the long ID number from the ArcGIS online portal, but anyhow. Seems the reference is correct. Still the same problem, the graphic is not updated with a refresh(). Only using the zoom buttons, or pan the map.

0 Kudos
JohnGrayson
Esri Regular Contributor

Working with the correct layer that is already in the view is one issue we can address simply.  Unfortunately, I'm still confused as to what you're trying to do and what is expected behavior.  Some additional checks would be to look at the renderer and the  definitionExpression property of the layer(s) to make sure they don't conflict with the edits being made.  Currently, your code only works with and edits 1 layer.  However, your Web Map has 3 Feature Layers and your comment about a FeatureLayer having 2 layers is misleading; a FeatureLayer instance only references 1 layer as indicated by the 'layerId' property.  Also, I don't understand how changing the 'Dat_uitv' value will affect either the rendering or defintionExpression, so what is it you expect to happen when you update this value?

Here's a modified version of the codepen, but I still don't understand what the overall goal is for this task:

https://codepen.io/john-grayson/pen/dyoVKqX?editors=1001 

0 Kudos
PHerk
by
New Contributor II

OK, John. What I want to do. This is a requirement from a customer. They have a map with area's / polygons, that indicate a specific location where a certain task:

- should start ( the area is in a color, Purple, Blue or Olive, each color represents a certain task)

- is finished ( the job in this area is done, the color must be Green).

A task is a work job, that a worker must do, example: cleaning the area.

The customer has, (indeed you are correct, sorry for the misleading information), 3 instances of a Featurelayer on his map:

1. Vloer (Dutch for floor)

2. Vlakken (Dutch for area's)

3. Vlakken - gereed (Ducth for area's completed)

It is the same Featurelayer, and the viewable area's on the layers depend on the filter:

1. Vloer, filter setting: only displays the area with id 5, this is the purple area.

2. Vlakken, filter setting: display the area's where id <> 5, the other 3 area's

3. Vlakken - gereed, filter setting: display the area's where id <> 5 AND Attribute: "Dat_uitv" is not empty.

This is the setting my customer made, and he wanted met to fill the "Dat_uitv" attribute with the current date time stamp, when they click on the specific area. Doing that, the map displays which area's have the job finished by showing the area "Vlakken - gereed" layer, according to the filter. Once the "Dat_uitv" attribute has a valid value, the filter of layer "Vlakken - gereed" is TRUE, and this layer displays the area in the color green. The customer can also view the timestamp when this job is finished. This works. 

The customer is under the impression, filling the field would have an immediate action where the "Vlakken - gereed" layer is redrawn, refreshed. That is not the case, and should be triggered by an action. This is the question: how to get this done, without a zoom or pan interaction of the user. A browser refresh, zoom or pan action does update the layer...

Maybe the whole interpretation how to solve this is wrong. If there is a better way, let me know.

Hope it is clear now.

Thanks

Pete.

0 Kudos
JohnGrayson
Esri Regular Contributor

Pete,

   I believe the issue you are seeing is that the attribute value you are editing will have no effect on the defintionExpression or renderer of that feature layer and that is why the layer does not change.  The "Vlakken - gereed" layer is the one that that will be affected by the edit and is the one we want to call refresh() on.

https://codepen.io/john-grayson/pen/dyoVKqX?editors=1001 

PHerk
by
New Contributor II

YES! Thank you John. Appreciated!

0 Kudos