Select to view content in your preferred language

How to set Refresh Interval for Feature Collection in Web AppBuilder?

3261
12
11-01-2016 03:42 PM
MarkMcCart
Regular Contributor

I need to set the refresh interval for a Feature Collection for a hosted site developed in Web AppBuilder. I cannot use the 'Info Summary Widget' for this because it won't allow 2 widgets to be run at the same time. If I enable the Info Summary Widget to start refreshing the Feature Collection, it turns on my 'Summary Widget'/Ticker that I need open all the time for the end user.

I don't want to use a Feature Service due to the connection limitations we've run into in the past for our popular AGOL-hosted apps. 

I've downloaded the app to Web AppBuilder Developers 2.2 edition and download the code to host it locally. However, I am not seeing where I can set the refreshInterval for the only layer I have in the map (excluding the basemap, which we are not allowing users to change).

Can someone point me to the correct file I need to update? I'm pretty sure the update needs to occur to one of the .js files in jimus.js\LayerInfos\ directory but I am rather new to the Web AppBuilder.

Thanks in advance!

-Mark

Tags (1)
0 Kudos
12 Replies
RobertScheitlin__GISP
MVP Emeritus

Mark,

   I have to say that this question has me saying "What?..." If you are building a featurecollection then you are in complete control of the code and data that is used to create that collection. So would you not just set a refresh method in your code on a timer?

0 Kudos
MarkMcCart
Regular Contributor

Robert,

I am using a Python Script inside my FME job that runs FME Server every 10 minutes to rebuild the feature collection in AGOL. However, when the data is refreshed, the map doesn't automatically refresh to show the latest data. That's why I need to have some type of refresh interval set for that layer in my application so that users don't have to keep hitting the refresh button on their browser to see current data.

As I mentioned the Info Summary Widget that it out there now in Web AppBuilder is okay for setting refresh rates on Feature Collections, but since I need the Summary Widget open at all times, I can't have both widgets running at the same time. Thus, my dilemma.

-Mark

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Mark,

to rebuild the feature collection in AGOL

So you have a map service url that you are adding to a web map?

0 Kudos
MarkMcCart
Regular Contributor

Not a map service URL, I'm just adding an AGOL hosted Feature Collection to an AGOL map by clicking 'Add Layers' in the AGOL map document. There is no REST service-like URL for a Feature Collection, just a JSON-like-feed URL that can be used externally to parse the data.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Mark,

    No the refresh has to set on the FeatureLayer.

FeatureLayer | API Reference | ArcGIS API for JavaScript 3.18 | setRefreshInterval 

So you will need to get the layer object in WAB and set call the setRefreshInterval method.

So for WAB this would be done in the MapManager.js (my addition is commended below):

      _show2DWebMap: function(appConfig) {
        //should use appConfig instead of this.appConfig, because appConfig is new.
        // if (appConfig.portalUrl) {
        //   var url = portalUrlUtils.getStandardPortalUrl(appConfig.portalUrl);
        //   agolUtils.arcgisUrl = url + "/sharing/content/items/";
        // }
        if(!appConfig.map.mapOptions){
          appConfig.map.mapOptions = {};
        }
        var mapOptions = this._processMapOptions(appConfig.map.mapOptions) || {};
        mapOptions.isZoomSlider = false;

        var webMapPortalUrl = appConfig.map.portalUrl;
        var webMapItemId = appConfig.map.itemId;
        var webMapOptions = {
          mapOptions: mapOptions,
          bingMapsKey: appConfig.bingMapsKey,
          usePopupManager: true
        };

        if(!window.isBuilder && !appConfig.mode && appConfig.map.appProxy &&
            appConfig.map.appProxy.mapItemId === appConfig.map.itemId) {
          var layerMixins = [];
          array.forEach(appConfig.map.appProxy.proxyItems, function(proxyItem){
            if (proxyItem.useProxy && proxyItem.proxyUrl) {
              layerMixins.push({
                url: proxyItem.sourceUrl,
                mixin: {
                  url: proxyItem.proxyUrl
                }
              });
            }
          });

          if(layerMixins.length > 0) {
            webMapOptions.layerMixins = layerMixins;
          }
        }

        var mapDeferred = jimuUtils.createWebMap(webMapPortalUrl, webMapItemId,
          this.mapDivId, webMapOptions);

        mapDeferred.then(lang.hitch(this, function(response) {
          var map = response.map;

          //hide the default zoom slider
          map.hideZoomSlider();

          // set default size of infoWindow.
          map.infoWindow.resize(270, 316);
          //var extent;
          map.itemId = appConfig.map.itemId;
          map.itemInfo = response.itemInfo;
          map.webMapResponse = response;
          // enable snapping
          var options = {
            snapKey: keys.copyKey
          };
          map.enableSnapping(options);

          html.setStyle(map.root, 'zIndex', 0);

          map._initialExtent = map.extent;

          LayerInfos.getInstance(map, map.itemInfo).then(lang.hitch(this, function(layerInfosObj) {
            this.layerInfosObj = layerInfosObj;
//My addition to do a refresh on the layer
            array.some(layerInfosObj._finalLayerInfos, lang.hitch(this, function(layer){
              if(layer.title === "CountyCrimeMap - Crimes"){
                layer.layerObject.setRefreshInterval(10); //the interval is in minutes
                return true;
              }
            }));
//end my add
            this._publishMapEvent(map);
            setTimeout(lang.hitch(this, this._checkAppState), 500);
            this.loading.hide();
            this._addDataLoadingOnMapUpdate(map);
          }));
        }), lang.hitch(this, function() {
          this._destroyLoadingShelter();
          topic.publish('mapCreatedFailed');
        }));
      },
0 Kudos
MarkMcCart
Regular Contributor

Thanks! I'll give this a try.

0 Kudos
MarkMcCart
Regular Contributor

Robert,

I'm not able to get it working. Could you please confirm the following:

1. Should there be 3 '=' symbols in line 67:

if(layer.title === "CountyCrimeMap - Crimes"){

2. Is the Layer.title referring the layer name in the map or the name of the feature layer it's pulling from?

I've changed the options around to account for every possible option, but still no luck. 

-Mark

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Mark,

  1. Yes it is suppose to bee ===
  2. That is the title of the layer as it appears in the LayerList widget
0 Kudos
MarkMcCart
Regular Contributor

What if I don't have the layer list widget? We really didn't want to have it for this application, but if its required, I can add it.

0 Kudos