Select to view content in your preferred language

URL Parameters and Layer Visibility

2501
7
06-07-2011 08:47 AM
JustinRobinson
Deactivated User
Hello Everyone,

I've been avoiding this problem for a while now, and my list is now empty enough that I had to start working on it.

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.)

Has anyone implemented something along these lines?

As I understand, 2.3.1 changed the way URL parameters are parsed, no longer using the mapLoadComplete function, which many posts state;

Current investigation has lead to ConfigManager.as containing the current URL parameter parser for itemid, center (scale etc). Another ViewerContainer.urlConfigParams.[tag] would catch new [tag] parameters (i.e. ../index.html?layer=Search%20This would catch "Search This").

Toggling map services is one thing, but how does one change the visibility of a layer within a map service, I'm still a little unclear on this... How to toggle the visibility of a layer.

This all seems a little overwhelming, and I get the feeling that this is not a simple feat. Some guidance would be greatly appreciated.

Thanks!
Tags (2)
0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Emeritus
0 Kudos
JustinRobinson
Deactivated User
Okay, well that was a long day.

I've got a working widget now that can do what I need, once again, a lot of work for a simple solution. However, now I've got an issue. I can get the layer turned on from a map service just fine, now I just need to have the Table of Contents update.

Now, I think I need Roberts help. I'm using your TOC Widget v. 2.3.3 and I was wondering if there was an event (?) I could dispatch that would cause the TOC widget to re-initialize and redetermine layer visibility... is this possible, or will I have to modify the TOC Widget for this purpose?
0 Kudos
JustinRobinson
Deactivated User
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...
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Justin,

  Here is the code needed to have the TOC update when a visibleLayers property is changed problematically.

Code to add to the TocMapLayerItem.as

//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);
                    }
                }
            }
        }


I have this working in my TOC on my development machine. I just don't know if it will work at startup.
0 Kudos
GISDev1
Deactivated User
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...


Can you tell us more information how you passed the URL parameters into this URLLayer() function? Can you post how you populate the ViewerContainer.urlConfigParams.service and ViewerContainer.urlConfigParams.layer variables? Did you add some stuff somewhere in the ViewerContainer setUrlConfigParams() function?
0 Kudos
RhettZufelt
MVP Notable Contributor
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_
0 Kudos
GISDev1
Deactivated User
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_


This is a good way to do it for some workflows. In my case, the URL is created dynamically, so a config would be needed for every single layer combination on and off to do it this way.
0 Kudos