Select to view content in your preferred language

2 buttons for 3 services (and a slider...)

516
3
08-03-2010 01:09 PM
MegPeterson
Regular Contributor
Hi all -

I have three services for use as basemaps:

1. Street view
2. Vector (roads and boundary lines only)
3. Photography

I need to toggle between the street view service, and the vector+photography services (they always need to be displayed together).  Is there a way to make two services visible at the same time, and not display the other?

I am also using Robert Scheitlin's slider for fading between two basemaps and would love to keep that functionality sliding between the street view, and the combined vector and photography services.  I've seen posts on the old forum board but it didn't allow for keeping the slider.

Many thanks.
Tags (2)
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus
Meg,

  OK here is the code.

I hope we are talking about the SFV 1.3 or less

//Replace existing function in MapManager
//basemap menu clicked
      private function basemapMenuClicked(event:AppEvent):void
      {
       var id:String = event.data as String;
       
       var configBasemaps:Array = configData.configBasemaps;
       var sellabel:String  = configBasemaps[id].label;
       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;
          if(lyr.id == "Photography"){
           this.parentApplication.fader.value = 0;
           lyr.alpha = 1;
          }else if(lyr.id == "Street Map"){
           this.parentApplication.fader.value = 1;
           lyr.alpha = 1;
          } 
         }
         else
         {
          if(sellabel == "Photography" && lyr.id == "Vector"){
           lyr.visible = true;
           lyr.alpha = 1;
           map.reorderLayer(lyr.id,1000);
          } else {
           lyr.visible = false;
          }
         }
        }
       }
      }

//Replace existing in ConfigManager

//get basemap menu items
  private function getBasemapMenuItems(xmlList:XMLList):Array
  {
   var menuItems:Array = [];
   if (xmlList.length() > 1)
   {
    for (var i:int = 0; i < xmlList.length(); i++)
    {
     var itemLabel:String = xmlList.@label;
     var itemIcon:String = xmlList.@icon;
     var itemValue:String = i.toString();
     if(itemLabel != "Vector"){
      var menuItem:Object = 
      {
       id: i,
       label: itemLabel,
       icon: itemIcon,
       value: itemValue,
       action: "basemap"
      }
      menuItems.push(menuItem);
     }
    }
   }
   return menuItems;
  }

//Add or maybe replace for you to the index.mxml

//Add import
import com.esri.ags.layers.Layer;

//Add or replace functions
private function faderFade(evt:Event):void
      {
       var lyr:Layer = SiteContainer.getInstance().controller.map.getLayer("Street Map");
       var lyr2:Layer = SiteContainer.getInstance().controller.map.getLayer("Photography");
       var lyr3:Layer = SiteContainer.getInstance().controller.map.getLayer("Vector");
       lyr.visible = true;
       lyr2.visible = true;
       lyr3.visible = true;
       lyr.alpha = fader.value;
       lyr2.alpha = (1 - fader.value);
       lyr3.alpha = (1 - fader.value);
      }
      
      private function sldrDataTipFormatter(value:Number):String 
      { 
       return int(value * 100) + "%"; 
      }

//Add or replace canvas

<mx:Canvas width="150" right="450" top="0" height="35" styleName="WidgetCanvas">
       <mx:HSlider id="fader" x="25" y="10" width="100" minimum="0" maximum="1"  snapInterval="0.1" liveDragging="true" allowTrackClick="true" enabled="true" change="faderFade(event)" value="1" dataTipFormatFunction="sldrDataTipFormatter"/>
       <mx:Image x="7" y="10" width="20" height="20">
        <mx:source>com/esri/solutions/flexviewer/assets/images/icons/i_shuttle.png</mx:source>
       </mx:Image>
       <mx:Image x="125" y="10" width="20" height="20">
        <mx:source>com/esri/solutions/flexviewer/assets/images/icons/i_highway.png</mx:source>
       </mx:Image>
    </mx:Canvas>


I made improvements to the slider code and it's interaction with the basemap menu items so if you already have some of these function be sure to replace them with these new ones.

These are the basemaps I am using in this example code:
<basemaps menu="menuMap">      
   <mapservice label="Photography" type="tiled" visible="false" alpha="1" icon="com/esri/solutions/flexviewer/assets/images/icons/i_shuttle.png">http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer</mapservice>
   <mapservice label="Vector" type="tiled" visible="false" alpha="1">http://server.arcgisonline.com/ArcGIS/rest/services/Reference/ESRI_BoundariesPlaces_World_2D/MapServer</mapservice>
   <mapservice label="Street Map" type="tiled" visible="true" alpha="1" icon="com/esri/solutions/flexviewer/assets/images/icons/i_highway.png">http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer</mapservice>
 </basemaps>


Notice that the code is hard coded to look for certain map service labels like "Vector" and "Photography"
0 Kudos
MegPeterson
Regular Contributor
A million thank yous, Robert!
0 Kudos
MayJeff
Deactivated User
Can someone show me this application for non_sfv?

Thank you.

May
0 Kudos