Select to view content in your preferred language

Zoom to specific level when specific basemap button clicked

887
4
Jump to solution
01-11-2012 10:22 AM
philippschnetzer
Frequent Contributor
I am using Robert's enhanced basemap switcher.  I am including the Esri Navigational Charts basemap in an application but it is only visible at 1:577000 and out.  How can I make the app automatically zoom to 1:577000 when that button is clicked.  It would just confuse a user if they are zoomed in to 1:10000 and click that basemap and nothing happens...

Thanks!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Phillip,

  Here is the updated function:

            private function basemapButtonBar_changeHandler(event:IndexChangeEvent):void             {                 var layers:ArrayCollection = map.layers as ArrayCollection;                 basemapButtonBar.fader.value = event.newIndex + 1;                 for (var x:int = 0; x < basemapList.length; x++){                     var basemapLabel:String = basemapList.getItemAt(x).label;                     for each (var layer:Layer in layers){                         if(basemapList.getItemAt(event.newIndex).label != basemapLabel)                             if(layer.id == basemapLabel)                                 layer.visible = false;                         if(layer.id == basemapLabel)                             layer.alpha = 1;                     }                 }                 if(basemapList.getItemAt(event.newIndex).label == "Esri Nav. Charts" && map.scale < 577790.554289)                     map.scale = 577791;                 AppEvent.dispatch(AppEvent.BASEMAP_SWITCH, basemapList.getItemAt(event.newIndex).id);             }

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus
Phillip,

   What does your main config.xml look like?
0 Kudos
philippschnetzer
Frequent Contributor
Robert,

Here's the important section...

<widget right="1" top="1" config="widgets/eMapSwitcher/MapSwitcherWidget.xml" url="widgets/eMapSwitcher/MapSwitcherWidget.swf"/>
    <widget left="8"  top="20"  config="widgets/CoordinateMenu/CoordinateMenuWidget.xml" url="widgets/CoordinateMenu/CoordinateMenuWidget.swf"/>
    <widget horizontalcenter="0" bottom="0"  config="widgets/Coordinate/CoordinateWidget.xml" url="widgets/Coordinate/CoordinateWidget.swf"/>
    <splashpage label="" config="widgets/mySplash/SplashWidget.xml" url="widgets/mySplash/SplashWidget.swf"/>
    <widget top="0" left="5"  url="widgets/MapProgressBarWidget/MapProgressBarWidget.swf"/> 
        
    <map wraparound180="true" initialextent="-7171000 5778500 -7024000 5841700" fullextent="-7600000 5514000 -6426000 6020000" top="40" esrilogovisible="false">
       
        <basemaps>
        
         <layer label="Streets" type="tiled" visible="true"
                   url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
        
         <layer label="Topo"    type="tiled" visible="false"
                   url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
          
            <layer label="Aerial"  type="tiled" visible="false"
                   url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"/>

   <layer label="Esri Nav. Charts"    type="tiled" visible="false"
                   url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
                   
    <layer label="Esri Nav. Charts"  type="tiled" visible="false"
                   url="http://server.arcgisonline.com/ArcGIS/rest/services/Specialty/World_Navigation_Charts/MapServer"/>        
                
            <layer label="Sites" type="tiled" visible="false"
                   url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>     
                   
            <layer label="Sites" type="tiled" visible="false"
                   url="http://www.avcvit.com/ArcGIS/rest/services/pwgsc_sites/MapServer"/>             
                  
            <layer label="2009" type="tiled" visible="false"
                   url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
                   
            <layer label="2009"    type="tiled" visible="false"
                   url="http://www.avcvit.com/ArcGIS/rest/services/pwgsc_2009/MapServer"/>
                   
            <layer label="2010" type="tiled" visible="false"
                   url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
                   
            <layer label="2010"    type="tiled" visible="false"
                   url="http://www.avcvit.com/ArcGIS/rest/services/pwgsc_2010/MapServer"/>
                   
           <layer label="2011" type="tiled" visible="false"
                   url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
                   
         <layer label="2011"    type="tiled" visible="false"
                   url="http://www.avcvit.com/ArcGIS/rest/services/pwgsc_2011/MapServer"/>
      
        </basemaps>


Thanks for having a look!!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Phillip,

  Here is the updated function:

            private function basemapButtonBar_changeHandler(event:IndexChangeEvent):void             {                 var layers:ArrayCollection = map.layers as ArrayCollection;                 basemapButtonBar.fader.value = event.newIndex + 1;                 for (var x:int = 0; x < basemapList.length; x++){                     var basemapLabel:String = basemapList.getItemAt(x).label;                     for each (var layer:Layer in layers){                         if(basemapList.getItemAt(event.newIndex).label != basemapLabel)                             if(layer.id == basemapLabel)                                 layer.visible = false;                         if(layer.id == basemapLabel)                             layer.alpha = 1;                     }                 }                 if(basemapList.getItemAt(event.newIndex).label == "Esri Nav. Charts" && map.scale < 577790.554289)                     map.scale = 577791;                 AppEvent.dispatch(AppEvent.BASEMAP_SWITCH, basemapList.getItemAt(event.newIndex).id);             }
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Phillip,

   This has been added to the new version of the widget 2.5.1 along with another feature called autoswitchtoscale.
0 Kudos