Combine basemap layers

2321
23
11-22-2010 06:40 AM
JustinFultz
New Contributor III
I am trying to combine a imagery layer and a boundaries layer, and I don't want the boundaries layer to show up as an option on the base layers selection bar.

Any ideas?
Tags (2)
0 Kudos
23 Replies
JasonLevine
Occasional Contributor II
Hi Justin,
   I did this not too long ago myself.  Follow this thread and you should be able to find the code you need:

http://forums.esri.com/Thread.asp?c=158&f=2421&t=285978&mc=17#888041

-Jason
0 Kudos
JustinFultz
New Contributor III
Thanks Jason!

I looked at that thread and was unable to get it to work for me.  I am able to make the new layers display over all basemaps, but it also shows up in the basemap list.  I couldn't get the last line of code in Robert's post to work, and I couldn't follow exactly what you did in your code (I am as far from a programer as it gets).  I was hoping there might be an easier way in the new viewer.

I'll keep pluggin away.
0 Kudos
JasonLevine
Occasional Contributor II
There are basically three parts to it; I'll show you a working example from one of my sites.  This has the Imagery Streets and Labels layers drawing over the imagery:

1) Add the layers to your config.xml (note the order; the layers you want to draw on top go on the bottom):
 <basemaps menu="menuMap">      
   <mapservice label="Street Map" type="tiled" visible="true" alpha="1" icon="com/esri/solutions/flexviewer/assets/images/icons/i_highway.png">http://10.2.8.73/ArcGIS/rest/services/Base_Map/Streets_Map/MapServer</mapservice>
   <mapservice label="Imagery" type="dynamic" visible="false" alpha="1" icon="com/esri/solutions/flexviewer/assets/images/icons/i_shuttle.png">http://10.2.8.73/ArcGIS/rest/services/Base_Map/Imagery/MapServer</mapservice>         
   <mapservice label="Imagery Streets" type="tiled" visible="false" alpha=".5" icon="com/esri/solutions/flexviewer/assets/images/icons/i_shuttle.png">http://10.2.8.73/ArcGIS/rest/services/Base_Map/Imagery_Street_Map/MapServer</mapservice>             
   <mapservice label="Labels" type="tiled" visible="false" alpha="1" icon="com/esri/solutions/flexviewer/assets/images/icons/i_shuttle.png">http://10.2.8.73/ArcGIS/rest/services/Base_Map/Labels/MapServer</mapservice>             
 </basemaps>


2) tweak the basemapMenuClicked function in the mapmanager.mxml:
private function basemapMenuClicked(event:AppEvent):void
      {
       var id:String = event.data as String;
       var configBasemaps:Array = configData.configBasemaps;
       for (var i:Number = 0; i < configBasemaps.length; i++)
       { 
        var label:String  = configBasemaps.label;
        var lyr:Layer = map.getLayer(label);
        if (lyr != null)
        {
         if (configBasemaps.id == id)
         {
          lyr.visible = true;
         }
         else
         {
          lyr.visible = false;
         }
        }
        var lyrNames:Layer = map.getLayer("Labels");
        if (id == "1")
        {
         lyrNames.visible = true;
        }
        else
        {
         lyrNames.visible = false;
        }
        
        var lyrNames2:Layer = map.getLayer("Imagery Streets");
        if (id == "1")
        {
         lyrNames2.visible = true;
        }
        else
        {
         lyrNames2.visible = false;
        }
        }
      }      


3) tweak the getBasemapMenuItems function in the configmanager.as file:
  private function getBasemapMenuItems(xmlList:XMLList):Array
  {
   var menuItems:Array = [];
   if (xmlList.length() > 1){
    for (var i:int = 0; i < xmlList.length(); i++){
     if(xmlList.@label != "Labels" && xmlList.@label != "Imagery Streets"){
     //if(xmlList.@label != "Labels"){
      var itemLabel:String = xmlList.@label;
      var itemIcon:String = xmlList.@icon;
      var itemValue:String = i.toString();
      var menuItem:Object = 
      {
       id: i,
       label: itemLabel,
       icon: itemIcon,
       value: itemValue,
       action: "basemap"
      }
      menuItems.push(menuItem);
     }
    }
       }
   return menuItems;
  }


Hopefully this simplifies it a little for you,
Jason
0 Kudos
JustinFultz
New Contributor III
I am still struggling.  What version of the flex viewer app are you using.  I don't even have a getBasemapMenuItems function in the conficManager.as file(flex app 2.1 using flash builder 4). Also, how do you know what id # to assign each layer.  Is the 1st one in the list 1, and so on?

Sorry I'm so clueless about this stuff.
0 Kudos
JasonLevine
Occasional Contributor II
Sorry, I should have mentioned that this was for an older version of the Sample Viewer.  The function in the MapManager.mxml would be the same as the one in the new sample viewer, but the configmanager.as files are pretty different. 

Look for the map:basemaps area in the configmanager.as.  This is where you would tell the map to hide the base maps.  Perhaps someone with stronger coding skills can help you with this.
0 Kudos
JustinFultz
New Contributor III
has anyone accomplished this in the new flex viewer app?
0 Kudos
ThomasSchultz
New Contributor III
I just did this same thing in the new viewer, and it's really quite similar to the old one.  The changes to MapManager.mxml are identical.  However, for ConfigManager.as find the basemaps section and add the conditional that loads services into the menu that do not equal the name of the service you want to exclude.  See code:

//================================================
            //map:basemaps
            //================================================
            var configMap:Array = [];
            var mapserviceList:XMLList = configXML.map.basemaps.mapservice;
            basemapGroup = configXML.map.basemaps.@group;
            for (i = 0; i < mapserviceList.length(); i++)
            if(mapserviceList.@label != "Coastal Imagery")
   {
    {
                 configMap.push(getLayerObject(mapserviceList, i, false));
             }
   }
            configData.basemaps = configMap;
0 Kudos
JustinFultz
New Contributor III
I have tried all of these suggestions with the out of the box flex viewer and can't get it to work.

How do you know the layer id? Is there a imagery service available that already has state boundaries on it.  That would allow me to get around this particular issue.
0 Kudos
JustinFultz
New Contributor III
Here is my code. I was able to get the boundaries to overlap the imagery, but when I add this code to the map:basemaps section of the ConfigManager.as, it removes the "Places" layer, and the Aerial and Topo layers are no longer visible when selected.

var configMap:Array = [];      
   var maplayerList:XMLList = configXML.map.basemaps.mapservice;      
   basemapGroup = configXML.map.basemaps.@group;
   if (maplayerList.length() < 1)
   {
    maplayerList = configXML.map.basemaps.layer;
   }
   
   
   for (i = 0; i < maplayerList.length(); i++)
    if(maplayerList.@label != "Places")
    {
   {
    configMap.push(getLayerObject(maplayerList, i, false, bingKey));
   }
    }
   configData.basemaps = configMap;
Any help is appreciated.
0 Kudos