private function URLLayer():void //Is there anything to turn on from URL Function { if (ViewerContainer.urlConfigParams.service + ViewerContainer.urlConfigParams.layer) { var layerIDNum:Number; var service:Layer = map.getLayer(ViewerContainer.urlConfigParams.service); var visibleLayers:ArrayCollection = ArcGISDynamicMapServiceLayer(service).visibleLayers; var layerInfos:Array = ArcGISDynamicMapServiceLayer(service).layerInfos; for each (var item:LayerInfo in layerInfos){ if (item.name == ViewerContainer.urlConfigParams.layer){ layerIDNum = item.id; } } visibleLayers.addItem(layerIDNum); } }
//Add this new import import mx.binding.utils.ChangeWatcher; //Change this code in the createChildren function if (layer is ArcGISTiledMapServiceLayer) { layerInfos = ArcGISTiledMapServiceLayer(layer).layerInfos; ChangeWatcher.watch(ArcGISTiledMapServiceLayer(layer), "visibleLayers", updateVisibilty); } else if (layer is ArcGISDynamicMapServiceLayer) { layerInfos = ArcGISDynamicMapServiceLayer(layer).layerInfos; if (ArcGISDynamicMapServiceLayer(layer).visibleLayers) { visibleLayers = ArcGISDynamicMapServiceLayer(layer).visibleLayers.toArray(); ChangeWatcher.watch(ArcGISDynamicMapServiceLayer(layer), "visibleLayers", updateVisibilty); } } //Add this new function: private function updateVisibilty(evt:Event):void { var visibleLayers:Array; if (layer is ArcGISDynamicMapServiceLayer) { visibleLayers = ArcGISDynamicMapServiceLayer(layer).visibleLayers.toArray(); } else if (layer is ArcIMSMapServiceLayer) { visibleLayers = ArcIMSMapServiceLayer(layer).visibleLayers.toArray(); } for each (var child:TocItem in children) { if(child is TocLayerInfoItem){ var tli:TocLayerInfoItem = child as TocLayerInfoItem; if(visibleLayers.indexOf(tli.layerInfo.id) > -1){ child.setVisible(true, true); }else{ child.setVisible(false, true); } } } }
Hi Robert,
I ended up integrating the url call into your TOC Widget so that I could access some of its features, I'm not sure if this is the right idea or not, but it's semi-working.
I call a function (shown below) during the init() function that checks for URL parameters, and if it finds one enables that layer. This is fine, it also toggles the checkbox of that layer (which wasn't happening when the function was in its own widget). The problem is now toggling the checkbox of the parents/children of that layer. I'm not sure how to get access to this... recommendations?
Here is the function that is called:private function URLLayer():void //Is there anything to turn on from URL Function { if (ViewerContainer.urlConfigParams.service + ViewerContainer.urlConfigParams.layer) { var layerIDNum:Number; var service:Layer = map.getLayer(ViewerContainer.urlConfigParams.service); var visibleLayers:ArrayCollection = ArcGISDynamicMapServiceLayer(service).visibleLayers; var layerInfos:Array = ArcGISDynamicMapServiceLayer(service).layerInfos; for each (var item:LayerInfo in layerInfos){ if (item.name == ViewerContainer.urlConfigParams.layer){ layerIDNum = item.id; } } visibleLayers.addItem(layerIDNum); } }
Thanks for all your help and input Robert (not just here or for me, but across the forum and its archive), if it wasn't for you I think many of our applications would be severely limited...
Hello Everyone,
I am trying to get a URL Parameter to activate a layer, based on the layer name (!), in order to complete functionality for an atlas (links from an html page must open the map viewer with certain layers turned on). Preferably I would like to be able to turn on Groups as well as individual layers (if the url parameter == the name of a group, turn all of that group on.)
So, is the URL "dynamic" meaning that they are "assigned" by code when someone clicks the link from the html page, or are they hard coded links?
This is a little different than you asked for, but if the link is hard coded, a different approach would be to have a different config file within the same FV app for each link. then, the URL would pass the config.xml file with the layers/groups that "should" be turned on set as visible="true", and your are done. http://server.com/flexviewer/?config=URLconfig1.xml
R_