Select to view content in your preferred language

Autorefresh Attribute Table Widget

2378
11
Jump to solution
03-10-2014 12:25 PM
JustinFultz
New Contributor III
Hello,

We have a table that refreshes every 5 minutes, and I would like to push those updates to the user in the attribute table widget so that they data updates while the table is open in the flex viewer.

If that isn't possible, can it at least be designed where the widget hits the table each time it closes and reopens, rather than only when the map extent changes. It seems like the data in the table is cached until the extent changes.

Currently at release 3.3 and Server 10.1.

Any help would be appreciated.

Thanks,

Justin
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
AnthonyGiles
Frequent Contributor II
Justin,

I think using the layer refresh will just refresh the map and not the table, I think you still need to use the AttributeTable(featureLayerToAttributeTable[featureLayer]).refresh() function. You will need to change the featurelayer to your layer.

Regards

Anthony

View solution in original post

0 Kudos
11 Replies
AnthonyGiles
Frequent Contributor II
Justin,

Have you tried using the autorefresh attribute in your layer parameters:

http://resources.arcgis.com/en/help/flex-viewer/concepts/index.html#/Layer_tag_overview/01m30000000p...

Regards

Anthony
0 Kudos
JustinFultz
New Contributor III
I am using the autorefresh parameter as you suggest. That seems to update the data that I click on for popups, but the attribute table widget doesn't appear to refresh when the autorefresh fires. I can also close and reopen the widget and it still appears to have the previous data cached.

Is there somewhere i need to add the autorefresh in my attribute widget config?
0 Kudos
AnthonyGiles
Frequent Contributor II
Ok if that's the case you will need to amend the attribute table mxml and set a timer that refreshes the attribute table, you can see an example of setting a timer in the GeoRSS widget:

https://github.com/Esri/arcgis-viewer-flex/blob/develop/src/widgets/GeoRSS/GeoRSSWidget.mxml

you will probably have to loop through your layers and force a refresh on each layer. This can be done using something like:

AttributeTable(featureLayerToAttributeTable[featureLayer]).refresh();

Regards

Anthony
0 Kudos
JustinFultz
New Contributor III
Anthony,

Thanks so much for your help! I am trying to incorporate the code you suggested, but I am not a developer and am having some trouble. I'm not sure exactly how I would loop through the feature layers and force the refresh. I have added the following code to my AttributeTableWidget.mxml, along with the corresponding variable declarations at the beggining of the file. I also added the <refreshrate> tag in my config. Can you help me get from where I am to a working version of this timer?

   }
                map.addEventListener(MapEvent.LAYER_ADD, mapLayerAddHandler, false);
                map.addEventListener(MapEvent.LAYER_REMOVE, mapLayerRemoveHandler, false);
                map.addEventListener(MapEvent.LAYER_REORDER, mapLayerReorderHandler, false);

                mapLayers = map.layers as ArrayCollection;
                layersUsedInAttributeTable = getLayers(mapLayers);
                for each (var layer:Layer in nonMappedLayers)
                {
                    layersUsedInAttributeTable.push(layer);
                }
                populateAttributeTableTabBar(layersUsedInAttributeTable);
    startWidgetTimer();
            }

   private function startWidgetTimer():void
   {                
    if (queryRefreshRate)
    {
     var seconds:Number = Number(queryRefreshRate);
     var rate:Number = seconds * 1000;
     stopWidgetTimer();
     timer = new Timer(rate);
     timer.addEventListener(TimerEvent.TIMER, timerTick);
     timer.start();
    }
   }
   
   private function stopWidgetTimer():void
   {
    if (timer != null)
    {
     if (timer.running)
     {
      timer.stop();
     }
    }
   }
   
   private function timerTick(event:TimerEvent):void
   {
   
    AttributeTable(featureLayerToAttributeTable[featureLayer]).refresh();
   }
   
            private function configureAttachmentInspectorLabels():void
            {
                AttributeTableWidgetAttachmentInspectorSkin.noAttachmentsText = getDefaultString("noAttachmentsText");
                AttributeTableWidgetAttachmentInspectorSkin.chooseFileText = getDefaultString("chooseFileText");
                AttributeTableWidgetAttachmentInspectorSkin.attachmentSubmitLabel = getDefaultString("attachmentSubmitLabel");
                AttributeTableWidgetAttachmentInspectorSkin.attachmentCancelLabel = getDefaultString("attachmentCancelLabel");
            }


Thanks again for your help!

Justin
0 Kudos
AnthonyGiles
Frequent Contributor II
Justin,

Have a look at the function:

private function getLayers(layers:ArrayCollection):Array

It is doing a loop through all the layers

Anthony
0 Kudos
JustinFultz
New Contributor III
Anthony,

I'm sorry to keep requesting more help(especially if this is super simple) but i have been trying to get this to work all morning to no avail.  I am struggling with the function that loops through the layers. Do just add the call to startWidgetTimer() in the existing getLayer() function, or do I need to create a new function looping through the layers that is embedded in the startWidgetTimer function?

Thanks again for your help!

Justin
0 Kudos
JustinFultz
New Contributor III
Would it be easier to specify a single layer to update? I only have one layer (right now) that needs to update at 5 minute intervals. Can I specify that layer to refresh rather than looping through all layers?

I've tried using map.getLayer("RTBM Binding Constraints").refresh(); in the timerTick() function with no luck. Any other suggestions would be appreciated.

Thanks,

Justin
0 Kudos
AnthonyGiles
Frequent Contributor II
Justin,

I think using the layer refresh will just refresh the map and not the table, I think you still need to use the AttributeTable(featureLayerToAttributeTable[featureLayer]).refresh() function. You will need to change the featurelayer to your layer.

Regards

Anthony
0 Kudos
JustinFultz
New Contributor III
I am still really struggling with this. I have tried a number of different code possibilites and haven't had any success. The tab on the attribute table will flash like something is being refreshed, but the data isn't updated. Below is one of my attempts to make this work. I'd appriciate anythign that could help me get me moving on this. I only have one layer in the attribute table to update.

 private var featureLayerToNavigatorContent:Dictionary = new Dictionary;
            private var featureLayerToAttributeTable:Dictionary = new Dictionary;
            private var featureLayerToDynamicMapService:Dictionary = new Dictionary;
            private var featureLayerToSettings:Dictionary = new Dictionary;
            private var hiddenFeatureLayerToSettingsName:Dictionary = new Dictionary;
   private var timer:Timer;
   private var querySource:String
   private var queryRefreshRate:String;
   private var featureLayer:FeatureLayer

            private function basewidget_initializeHandler():void
            {
                if (isPartOfPanel) // if widget is part of "left", "right" or "bottom" panel
                {
                    this.percentWidth = this.percentHeight = 100;
                    wTemplate.percentWidth = wTemplate.percentHeight = 100;
                }
                else
                {
                    wTemplate.width = map.width - map.width / 100 - Number(this.left);
                    wTemplate.minWidth = 800;
                    wTemplate.height = wTemplate.minHeight = 300;
                }
            }

            private function basewidget_widgetConfigLoaded():void
            {
                if (configXML)
                {
     querySource = configXML.source; 
     queryRefreshRate = configXML.refreshrate;
                    // non-mapped layers
                    var nonMappedLayers:Array = [];
                    var players:XMLList = configXML.layer as XMLList;
                    for (var p:Number = 0; p < players.length(); p++)
                    {
                        const layerXML:XML = players
 as XML;
                        nonMappedLayers.push(createNonMappedLayer(layerXML));
                    }

                    //excludeLayers
                    excludeLayers = [];
                    var elayers:XMLList = configXML.excludelayer as XMLList;
                    for (var n:Number = 0; n < elayers.length(); n++)
                    {
                        excludeLayers.push(elayers.toString());
                    }

                    // layerSettings, overriding default settings  
                    configureLayerSettings(configXML.layersettings.layer);
                    // attachment inspector labels
                    configureAttachmentInspectorLabels();
                }
                map.addEventListener(MapEvent.LAYER_ADD, mapLayerAddHandler, false);
                map.addEventListener(MapEvent.LAYER_REMOVE, mapLayerRemoveHandler, false);
                map.addEventListener(MapEvent.LAYER_REORDER, mapLayerReorderHandler, false);

                mapLayers = map.layers as ArrayCollection;
                layersUsedInAttributeTable = getLayers(mapLayers);
                for each (var layer:Layer in nonMappedLayers)
                {
                    layersUsedInAttributeTable.push(layer);
                }
                populateAttributeTableTabBar(layersUsedInAttributeTable);
    startWidgetTimer();
            }

   private function startWidgetTimer():void
   {                
    if (queryRefreshRate)
    {
     var seconds:Number = Number(queryRefreshRate);
     var rate:Number = seconds * 1000;
     stopWidgetTimer();
     timer = new Timer(rate);
     timer.addEventListener(TimerEvent.TIMER, timerTick);     
     timer.start();
    }
   }
   
   private function stopWidgetTimer():void
   {
    if (timer != null)
    {
     if (timer.running)
     {
      timer.stop();
     }
    }
   }
   
   private function timerTick(event:TimerEvent):void
   {    
    var layer:Layer = layersUsedInAttributeTable.getItemAt(0) as Layer;
    createFeatureLayersFromDynamicMapService(ArcGISDynamicMapServiceLayer(layer), 0);
    AttributeTable(featureLayerToAttributeTable[featureLayers]).refresh();    
   }
0 Kudos