Select to view content in your preferred language

FV3 swipe spotlight widget refresh layer list

1955
4
Jump to solution
08-23-2012 02:44 PM
RhettZufelt
MVP Notable Contributor
I am using the swipespotlight widget as well as the add map services widget.

Everything is working, however, once the map is loaded and I add services by drag/drop from the mapservices widget the "new" layers are not available to the swipe widget.

Is it possible to get the swipe/spotlight widget to actually list the layers currently loaded, or are we stuck getting this list from the original config.xml?

Thanks again,

R_
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Rhett,

    This would involve fixing code in the MapServicesWidget.mxml and Adding some event listeners to the SwipeSpotlightWidget.mxml.

So lets start with Odoe's Drag and Drop Map Services Widget.

In the MapServicesWidget.mxml find the AddLayerToMap function:

                if (item.type == DYNAMIC)                 {                     var dLayer:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer();                     dLayer.url = item.url;                     dLayer.name = dLayer.id = item.name;                     map.addLayer(dLayer);                 }                 else                 {                     var tLayer:ArcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer();                     tLayer.url = item.url;                     tLayer.name = tLayer.id = item.name;                     map.addLayer(tLayer);                 }


Then in my SwipeSpotlightWidget.mxml:

Add this import
            import com.esri.ags.events.MapEvent;

Make these changes / additions:

            private function init():void             {                 if (configXML)                 {                     useBasemaps = configXML.usebasemaps && configXML.usebasemaps == "true";                     askAbout = configXML.askaboutturningonlayer && configXML.askaboutturningonlayer == "true";                 }                 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){                         layArr.push(opsLayer.label);                     }                     activeLayer.dataProvider = layArr;                 }                 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);                 }             }

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Rhett,

    This would involve fixing code in the MapServicesWidget.mxml and Adding some event listeners to the SwipeSpotlightWidget.mxml.

So lets start with Odoe's Drag and Drop Map Services Widget.

In the MapServicesWidget.mxml find the AddLayerToMap function:

                if (item.type == DYNAMIC)                 {                     var dLayer:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer();                     dLayer.url = item.url;                     dLayer.name = dLayer.id = item.name;                     map.addLayer(dLayer);                 }                 else                 {                     var tLayer:ArcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer();                     tLayer.url = item.url;                     tLayer.name = tLayer.id = item.name;                     map.addLayer(tLayer);                 }


Then in my SwipeSpotlightWidget.mxml:

Add this import
            import com.esri.ags.events.MapEvent;

Make these changes / additions:

            private function init():void             {                 if (configXML)                 {                     useBasemaps = configXML.usebasemaps && configXML.usebasemaps == "true";                     askAbout = configXML.askaboutturningonlayer && configXML.askaboutturningonlayer == "true";                 }                 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){                         layArr.push(opsLayer.label);                     }                     activeLayer.dataProvider = layArr;                 }                 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);                 }             }
0 Kudos
RhettZufelt
MVP Notable Contributor
Thanks again Robert, is working for the most part, but also created some strange behaviour.

If I open the SwipeSpotlight widget before I drag/drop any mapservices they will show up in the swipable list.  If I drag/drop mapservices and THEN open the SwipeSpotlight, they do not show.  It only captures the services added when the SwipeSpotlight widget is "open".  Also, I noticed that if I have the dynamic legend widget open and drag/drop "layer1" onto the map, it does not show on the legend.  However, if I then drop "layer2" on the map, then layer1 will display on the legend so there seems to be a slight delay (the TOC widget show the change immediately).  Not that I mind the "delay" here, just thought it might give you a better idea of what is going on.


However, if I so much as touch ANYother widget (legend, TOC, print, bookmark, etc.) I can then never drag/drop again without a complete refresh of the map.  If I try, it always gives me the little red X so it seems to "disable" the mapservices widget on widget change.

R_

also, trying to figure out the code you sent, what is the purpose of the = dLayer.id change to mapservices?  I.e., how does that tie in with the swipespotlight.mxml changes?  It seems as if you are setting another variable name, but not sure what the reference to it is in the other mxml.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rhett,

   All those issues are related to the way Odoe (the other developer) has developed his widget. When you dynamically drag and drop layer into the map they are just added and not added to the operational layers list of the viewer. There for my widget does not recognise them to be added to the drop down as they are not listed as operational layers. Anyway I will not be assisting any further with making another developers widget more flex viewer framework accurate. The reason for the code I had you add to his widget is that a layer need an id to be progammatically searched for and he was only giving it a name attribute and not an id.
0 Kudos
RhettZufelt
MVP Notable Contributor
Thanks again Robert.  I figured it was to assign an ID, but then your adds to the other mxml were referencing by name.

I see now where they are iterating by id's and why they are needed.

R_
0 Kudos