Select to view content in your preferred language

Refreshing the layer on map, web app builder

4319
9
Jump to solution
01-11-2018 06:12 AM
akshayloya
Frequent Contributor

Hi,

I have a web map with a accident layer added. I have created web app builder application with this web map.

I have following widgets:

1) Layer List

2) Situation Awareness 

3) Near Me

4) Info Summary

I have a custom widget for date selection. There is a date field in my accident layer. I want to refresh this layer which is already added on map based on the date filter. 

Hoping for the positive response.

Regards,

Akshay Loya

1 Solution
9 Replies
RobertScheitlin__GISP
MVP Emeritus

Akshay,

   In the web map (on AGOL/Portal) set a refresh interval on your layer if the data is updated frequently.

0 Kudos
akshayloya
Frequent Contributor

I want to refresh it based on where clause, this will change based on user selection. 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Then in your custom widget just call

layer.refresh();

0 Kudos
akshayloya
Frequent Contributor

but how to put where clause on the layer already added on web map and refresh it?

0 Kudos
akshayloya
Frequent Contributor

This is the code I've written

var layers = this.map.getLayersVisibleAtScale(this.map.getScale());
array.forEach(layers, function (layer) {
if (layer.id == 'Spills_map_series_3947') {
layer.setDefinitionExpression("County='KING'");
layer.refresh();
}
});
But I'm getting an error as attached
RobertScheitlin__GISP
MVP Emeritus

Akshay,

   Try this:

var layers = this.map.getLayersVisibleAtScale(this.map.getScale());
array.forEach(layers, function (layer) {
  if (layer.id == 'Spills_map_series_3947') {
    console.info(layer.className)
    layer.setDefinitionExpression("County='KING'");
  }
});

And show me what the console says

akshayloya
Frequent Contributor

It is giving undefined.

Sorry for the late response. Somehow Geonet service was down.

0 Kudos
akshayloya
Frequent Contributor

My bad, I was trying it with map service. I changed it too feature service and it is working now. 

Just need to apply for situation awareness widget now, somehow it doesn't take the filtered layer for query.  

0 Kudos