Combine basemap layers

2325
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
RobertScheitlin__GISP
MVP Emeritus
Justin,

   Here is what needs to be done for FlexViewer 2.x

MapManager.mxml is the only file to be changed and two functions need to be altered.

This code is developed for combining two basemap layers called "Places" and "Aerial":
            //basemap menu clicked
            private function basemapMenuClicked(event:AppEvent):void
            {
                var id:String = event.data as String;
                var configBasemaps:Array = configData.basemaps;

                if (id)
                {
     var BaseMapChoosen:String = "";
     var lyrNames:Layer = map.getLayer("Places");
                    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;
        BaseMapChoosen = configBasemaps.label
                            }
                            else
                            {
                                lyr.visible = false;
                            }
       if(lyrNames){
        if(BaseMapChoosen == "Aerial")
        {
         lyrNames.visible = true; 
        }else{
         lyrNames.visible = false;
        }
       }
                        }
                    }
                }
            }

            private function configBasemaps():void
            {
                var i:int = 0;
                for (i = 0; i < configData.basemaps.length; i++)
                {
                    if (i == configData.basemaps.length - 1)
                    {
                        map.addEventListener(MapEvent.LAYER_ADD, layerloadComplete);
                    }
                    addLayerToMap(configData.basemaps, false);
                }
    // remove the excluded basemaps
    var shownBaseMaps:Array = configData.basemaps.slice();
    for (var n:Number = 0; n < shownBaseMaps.length; n++)
    {
     if (shownBaseMaps.label == "Places")
      shownBaseMaps.splice(n, 1);
    }
    configData.basemaps = shownBaseMaps;
            }
0 Kudos
JustinFultz
New Contributor III
Thanks Robert! I'm almost there! I'm sure this last part is something easy, but I am actually using two boundary layers (one for imagery the other for a light background). I have managed to get both layers where I want them by just copying and pasting some of your code, but things get screwy when I try to do the same with the portion of code that would remove the second boundary layer(blue lettering below). Could you help me with that?

Thanks so much for all of your help!!!!

private function basemapMenuClicked(event:AppEvent):void
            {
                var id:String = event.data as String;
                var configBasemaps:Array = configData.basemaps;        
    if(id)
    {
     var BaseMapChoosen:String = "";
     var lyrNames:Layer =map.getLayer("Footprint Boundaries")
    }
     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;
               BaseMapChoosen = configBasemaps.label
       }
       else
       {
        lyr.visible = false;
       }
            if(lyrNames){
             if(BaseMapChoosen == "SPP Footprint")
             {
              lyrNames.visible = true;
             }else{
              lyrNames.visible= false;
             }
            }
      }
     }
     if(id)
     {
      var BaseMapChoosen:String = "";
      var lyrNames:Layer =map.getLayer("Imagery Boundaries")
     }
     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;
        BaseMapChoosen = configBasemaps.label
       }
       else
       {
        lyr.visible = false;
       }
       if(lyrNames){
        if(BaseMapChoosen == "Aerial")
        {
         lyrNames.visible = true;
        }else{
         lyrNames.visible= false;
        }
       }
      }
     }
   }
   private function configBasemaps():void
   {
    var i:int = 0;
    for (i = 0; i < configData.basemaps.length; i++)
    {
     if (i == configData.basemaps.length - 1)
     {
      map.addEventListener(MapEvent.LAYER_ADD, layerloadComplete);
     }
     addLayerToMap(configData.basemaps, false);
    }
    // remove the excluded basemaps
    var shownBaseMaps:Array = configData.basemaps.slice();
    for (var n:Number = 0; n < shownBaseMaps.length; n++)
    {
     if (shownBaseMaps.label == "Footprint Boundaries")
      shownBaseMaps.splice(n, 1);   }
    
    configData.basemaps = shownBaseMaps;
   }
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Justin,

    Not really sure I understand what you are doing here but maybe the answer you are looking for is

if (shownBaseMaps.label == "Footprint Boundaries" || shownBaseMaps.label == "your other layer")
0 Kudos
JustinFultz
New Contributor III
That is what I assumed would be the answer, but when I do that it adds "Footprint Boundaries" back to the list, removes "Imagery Boundaries", and removes the visibility of Footprint Boundaries in the map.

The reason I need two boundary layers is that I have a dark (Aerial) background and a light background (SPP footprint).  ESRI has seperate services created for dark/light backgrounds to improve visibility.  Please let me know if you think of something.

Thanks!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Justin,

   I can probably help if I have more exact details. Like the label of each service and the label of the service it is to be paired with and if that is the only layer it should ever appear with etc.
0 Kudos
JustinFultz
New Contributor III
I have the following Basemap Layers:
Streetmap, Aerial, Topo, SPP Footprint, Footprint Boundaries, Imagery Boundaries

I don't want to see the boundary layers buttons on the menu.

I successfully made the following pairings by modifying the code you sent, and these are the only pairings I want to see:
Aerial to Imagery Boundaries
SPP Footprint to Footprint Boundaries

I am able to remove one of the boundary layer buttons at a time with:

if (shownBaseMaps.label == "Footprint Boundaries")
      shownBaseMaps.splice(n, 1);


When I add the Imagery Boundaries layer as shown below, the Footprints Boundaries button shows up again, the Footprint Boundary layer isn't visible in the map, and the Imagery Boundary button disapears.

if (shownBaseMaps.label == "Footprint Boundaries"|| shownBaseMaps.label== "Imagery Boundaries")
      shownBaseMaps.splice(n, 1);


Thanks for being patient with me!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Justin,


   See if this works.

            private function configBasemaps():void
            {
                var i:int = 0;
                for (i = 0; i < configData.basemaps.length; i++)
                {
                    if (i == configData.basemaps.length - 1)
                    {
                        map.addEventListener(MapEvent.LAYER_ADD, layerloadComplete);
                    }
                    addLayerToMap(configData.basemaps, false);
                }
    // remove the excluded basemaps
    var excludeBaseMaps:Array = ["Footprint Boundaries","Imagery Boundaries"];
    var shownBaseMaps:Array = configData.basemaps.slice();
    for (var n:Number = 0; n < shownBaseMaps.length; n++)
    {      
     for (var j:Number = 0; j < excludeBaseMaps.length; j++)
     {
      if (shownBaseMaps.label == excludeBaseMaps)
      {
       shownBaseMaps.splice(n, 1);
      }
     }
    }
    configData.basemaps = shownBaseMaps;
            }
0 Kudos
JustinFultz
New Contributor III
Perfect!!!

You're the man, Robert!
0 Kudos
JustinFultz
New Contributor III
Robert,

I have noticed one other small issue with this code.  While it does remove the layers from the basemap list, it adds the layer to the operational map list in the "More" dropdown box.  Is there an easy way to remove it from that list.

Thanks!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Justin,

   Sure, just add then to the MapSwitcherWidget.xml
0 Kudos