Select to view content in your preferred language

SwipeSpotlight Widget update layers

1769
18
Jump to solution
03-11-2013 05:22 PM
RhettZufelt
MVP Notable 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
18 Replies
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   I have not done that myself but the init function of the widget is where I would start testing, at the end of that function of course.
0 Kudos
RhettZufelt
MVP Notable Contributor
Thought about that, but not sure how to keep it from closing itself when I do want to open it.

Maybe I could put it in the init function of a widget that loads afterwards?

Would I be correct in assuming that the widgetID number reflects the order that they are loaded in the viewer?

Guess it gives me a place to start.

Thanks,

R_
0 Kudos
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.
0 Kudos
RhettZufelt
MVP Notable Contributor
Thanks again Robert, bottom of the init function works.

However, this.widgetState("closed") gives error of call to undefined method widgetState.  Not sure why it doesn't like it so I addressed it this way:

//Added Code
    var data:Object = {
     id: widgetId,
     state: "closed"
    }
    AppEvent.dispatch(AppEvent.WIDGET_CHANGE_STATE, data); 
//End Added Code 


and seems to be working.  I can breifly see the swipe widget open and going to the minimized state (tranparent background, but not collapsed yet), then it closes.
all layers added with mapservices widget now show up.

Put my excludelayers option back in there (saw you changed layArr to layAc) and everything is working as desired.

Thanks again for you help on this,

R_

BTW, I'm actually using the sample TestOpenClose widget to get my widget ID's.  pretty nifty GUI for that.
0 Kudos
RhettZufelt
MVP Notable Contributor
Hi Robert,

Have noticed that if I do an eSearch before I use the SwipeSpotlightWidget, the list of layers will now have:
Graphical Search Layer
Search Buffer Results
and hiddenLayer_All Waste Sites

If you select them in the dropdown, it doesn't even give you the swipe cursor or anything.

know these are coming from the eSearch widget, but, since they are not "operational" layers, my excluded layer code doesn't catch them.
So, I modified the mapLayerAddHandler to deal with it. Not sure if there is a better way, but this seems to work (at least, haven't found anything else it interferes with "yet").


   private function mapLayerAddHandler(event:MapEvent):void
   {
    if(findInAc(event.layer.name) == -1){
     
     if (event.layer.name != "Search Buffer Results" && event.layer.name != "Graphical Search Layer" && event.layer.name != "hiddenLayer_All Waste Sites"){
      layAc.addItem(event.layer.name);
       }
    }
    layAc.refresh();
   }


However, this obviously will work for the first two, but the hiddenLayer_service (sometimes hiddenLayer_All Waste Sites, hiddenLayer_Buildings, etc) depends on which service you last searched.

Can't for the life of me figure out how to code somthing like this that works in flex:

if (event.layer.name != "Search Buffer Results" && event.layer.name != "Graphical Search Layer" && event.layer.name Not Like "hiddenLayer_%")


Any ideas on the best way to handle this?

R_
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   Here is what you would need:

            private function init():void
            {
                if (configXML)
                {
                    useBasemaps = configXML.usebasemaps && configXML.usebasemaps == "true";
                    askAbout = configXML.askaboutturningonlayer && configXML.askaboutturningonlayer == "true";
                }
                if(useBasemaps){
                    layAc = new ArrayCollection();
                    for(var i:int=0; i<map.layerIds.length; i++)
                    {
                        if(map.layerIds.indexOf("hiddenLayer_") == -1){
                            layAc.addItem(map.layerIds);
                        }
                    }
                    activeLayer.dataProvider = layAc;
                }else{
                    layAc = new ArrayCollection();
                    for each (var opsLayer:Object in configData.opLayers){
                        layAc.addItem(opsLayer.label);
                    }
                    activeLayer.dataProvider = layAc;
                }
                map.addEventListener(MapEvent.LAYER_ADD, mapLayerAddHandler, false);
                map.addEventListener(MapEvent.LAYER_REMOVE, mapLayerRemoveHandler, false);
                wTemplate.header.addEventListener(MouseEvent.CLICK, DisplayVersion);
            }
            
            private function mapLayerAddHandler(event:MapEvent):void
            {
                if(findInAc(event.layer.name) == -1 && event.layer.name.indexOf("hiddenLayer_") == -1){
                    if(!event.layer is GraphicsLayer){
                        layAc.addItem(event.layer.name);
                    }
                }
                layAc.refresh();
            }
0 Kudos
RhettZufelt
MVP Notable Contributor
Thanks Robert,  works like a champ.

I thought about using indexOf, but by then, it was the weekend, and no way to test.

R_
0 Kudos
RhettZufelt
MVP Notable Contributor
Well, guess I spoke to soon.  Didn't realize that this once again made the services added by the MapServicesWidget to not show.

Apperantly, the swipespotlightwidget sees them as GraphicasLayer and adding
 if(!event.layer is GraphicsLayer)
to it makes the services added via the widget not populate the dropdown.

I made this change in the mapLayerAddHandler function, and it seems to be working.  I'm sure not the best way, but this seems to handle graphic/search layers from search and draw widgets, as well as not adding the .zip and lables layers if I add using the ShapefilesWidget.




if(findInAc(event.layer.name) == -1 && 
        event.layer.name.indexOf("hiddenLayer_") == -1 && 
 event.layer.name.indexOf("Graphic") == -1 && 
 event.layer.name.indexOf("Search") == -1 &&
 event.layer.name.indexOf(".zip") == -1 && 
 event.layer.name.indexOf("Labels_") == -1)



R_

PS, tried the 3.2 version in both 3.1 and 3.2 and it does not add services added via the mapservices widget as it has the same coding for the add handler.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
All,


   There is an exciting new version of the widget available:

Version 3.6.1 - Feb 18, 2014
*  Added support for freezing the swipe or spotlight mask. What this means  is can let go of the mouse during a swipe or spotlight and the mask  will remain frozen on the screen until you click again or press the esc  button on the keyboard.
* Added the diagonalswipeenabled tag in the xml.
* Added the freezelayermask tag to the xml. This sets the checkbox on the Swipe widget GUI to true or false.
*  Added support for multiple layers added to the map using the same  label. This mean you can swipe or spotlight basemaps with reference  layers and operational layers that have the same label for multiple  layers.
* Redesigned the GUI to allow selecting the top and the  bottom layer for the swipe or spotlight operations. Setting the layer in  the top and bottom drop down lists will move that layer to the top or  the bottom of the map respectively.
* When the widget is opened the  order and visibility of all map layers are recorded and when the widget  is closed they are reset to this original order/visibility.
* Depreciated the askaboutturningonlayer tag as now layers are set to visible by default when chosen in the top or bottom layer.
0 Kudos