SwipeSpotlight Widget update layers

1000
18
Jump to solution
03-11-2013 05:22 PM
RhettZufelt
MVP Frequent Contributor
Using FV3.1 and the latest available widgets, I am using the SwipeSpotlight widget and the Map Services widget (not the drag/drop, but this one http://www.arcgis.com/home/item.html?id=4ed10ea387444952a3f3f501fee02b76 ).

I have added the following to the SwipeSpotlight.mxml:

                map.addEventListener(MapEvent.LAYER_ADD, mapLayerAddHandler, false);                 map.addEventListener(MapEvent.LAYER_REMOVE, mapLayerRemoveHandler, false);             }                          private function mapLayerAddHandler(event:MapEvent):void             {                 if(layArr.indexOf(event.layer.name) == -1){                     layArr.push(event.layer.name);                 }             }                          private function mapLayerRemoveHandler(event:MapEvent):void             {                 if(layArr.indexOf(event.layer.name) > -1){                     layArr.splice(layArr.indexOf(event.layer.name),1);                 }             }


Now, if I add a layer using the MapServices widget and tell it to load at the bottom, it will load t the bottom of the TOC and will show in the dropdown list of the SwipeSpotlight widget.  Doesn't really help much, as if it is on the bottom, I don't need to swipe it.  However, if I configure to load at the top of the TOC, it will load it fine, but not show on the SwipeSpotlight dropdown unless I remove it, then add it again.

So, for some reason, it does not add the "first" layer added by the MapServices widget to the SS widget dropdown.  They only get added after a re-order of the list
map.reorderLayer(dynLayer.id,configData.basemaps.length);
or adding/removing from the list.

Any ideas what I am missing?

R_
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   The init function only happens once when the widget is loaded. You can get the id of any widget by it's label using
ViewerContainer.getInstance().widgetManager.getWidgetId("some label")
But as you are going to be in the widget just you can just set its state to closed.

this.widgetState("closed");


Once again untested.

View solution in original post

0 Kudos
18 Replies
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   I am not sure what issue you are having as I have added this widget and it adds the layer that are set to loadbottom="0" just fine at the bottom of the Swipe widget layer list.
0 Kudos
RhettZufelt
MVP Frequent Contributor
After seeing your post, I figure it must be because of my modification.  I modified the SwipeSpotlight widget to allow a list of excluded layers, and modified the MapServices widget to have a checkbox for "Load at bottom" so you can choose at load time instead of hardcoded in the config.

So, I deleted everything, imported a new fv project, copied the API, etc.  added the two widgets, even removed the other widgets.
Now I have a OOTB viewer stripped down with these two widgets added.  I downloaded the latest versions (deleted the fires service from the MapServices.xml as it hangs the browser) and noticed that you have now included the listners in the swipe widget, so figured I'd be good to go.

Same thing, doesn't matter if I set the loadBottom to 0 or 1.  It will put them in the "more" tab or TOC (depending on what fv I test it on as I don't have both loaded) at the top or bottom according to the loadBottom tag, but will NOT put it in the SwipeSpotlight widget list unless I remove that layer and add it back in again.  However, every layer added after the first one will populate the dropdown whether I removed the first one or not.....  Just that the first one won't show up afterwards unless it's removed first.

also, here is the code I added to exclude layers in case you wanted it some time (of course, the one I'm testing now is unaltered):

// My Add
   private var excludeLayers:Array;
   private var exclude:Boolean = false;

// End add
   private function init():void
   {
    if (configXML)
    {
     useBasemaps = configXML.usebasemaps && configXML.usebasemaps == "true";
     askAbout = configXML.askaboutturningonlayer && configXML.askaboutturningonlayer == "true";
//My Add
     excludeLayers = [];
     var elyrList:XMLList = configXML..excludelayer;
     for (var el:int = 0; el < elyrList.length(); el++) {
      excludeLayers.push(elyrList[el].@name.toString());
     }
    }
//End add
    
    if(useBasemaps){
     layArr = [];
     for(var i:int=0; i<map.layerIds.length; i++)
     {
      layArr.push(map.layerIds);
     }
     activeLayer.dataProvider = layArr;
    }else{

     layArr = [];
     for each (var opsLayer:Object in configData.opLayers){
 // My Add
      opsLayer.exclude = false;
      if (excludeLayers.indexOf(opsLayer.label) != -1){
       opsLayer.exclude = true
      }else{
       opsLayer.exclude = false
      }
      if (opsLayer.exclude != true){
       layArr.push(opsLayer.label);
      }
     }
//End add


Anyway, I'm at a loss,

R_
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   See if version 3.1.1 fixes this for you. I reworked the whole dropdown list and events.
0 Kudos
RhettZufelt
MVP Frequent Contributor
Robert,

I think maybe the zip file didn't get updated?  The mxml from my 3.1 and 3.1.1 are identical.

R_
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   Yep I missed updating the uncompiled code... It is fixed now.
0 Kudos
RhettZufelt
MVP Frequent Contributor
That did it.  Seems to be working as expected once it has been opened.

However, I can add as many layers to the map as I want before I open the SwipeS widget, and they will not show up in the list at all.

If I open the SwipeSpotlight widget BEFORE I add any services, then all of them get added to the dropdown.  SwipeSpotlight widget doesn't have to remain open, just as long as it has been opened (can be minimized or closed), the layers get added.

Not sure if this could easily be fixed or not?  If not, is there an easy way to have it open and close the SwipeSpotlight widget automatically on viewer load (I know the preload="open", but what about automatically closing it)?

R_
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   There is always preload="minimized". The MapServices widget does not add the loaded layers to the Viewers operational layers list so that is why when the Swipe is not preloaded it can not track the layers added by the Map Services widget. When the swipe widget is loaded it adds all the viewers operational layers and then adds listeners for new layers added to the map.
0 Kudos
RhettZufelt
MVP Frequent Contributor
Thanks Robert, figured it was something like that.

I know the preload minimized works, but I really don't want the minimized widget floating on the viewer.

Was hoping there was a simple way to automatically close the widget after a preload=open/minimized.  I see some examples of how to close a widget from within a widget, but not externally.

R_
0 Kudos
RhettZufelt
MVP Frequent Contributor
I think I have the code required to close the widget, just not sure where to put it.

Where would one insert code to close widgetID=10 after the map is done loading (for that matter, any time after the widgets have loaded)?

Thanks for any pointers,

R_
0 Kudos