Select to view content in your preferred language

TOC excludeLayers problem

1098
9
06-23-2010 03:00 PM
MelonyBarrett
Occasional Contributor
I'm calling a function on creationComplete of the TOC (I'm using this TOC, not the Sample Flex Viewer) in order to exclude some basemap layers from it, and then expand the remaining services.  The code works, too, just not without errors.  The first error starts with:
Error #1009: Cannot access a property or method of a null object reference.
at com.esri.maplib.tocClasses::TocLayerInfoItem/set minScale()
then I hit Dismiss All and the next error starts with:
Error #1009: Cannot access a property or method of a null object reference.
at com.esri.maplib.tocClasses::TocLayerInfoItem/checkExtent()


Here's the code from my main application file for the TOC, and the function being called:

     <maplib:TOC id="TOC" creationComplete="initTOC();"
     width="100%" height="100%" 
     map="{map}" 
     useLayerFadeEffect="true" 
     excludeGraphicsLayers="true" />              


And here's the initTOC function:

 //Exclude base map layers and expand top level TOC items on creationComplete of TOC     
   private function initTOC():void
   {
    TOC.excludeLayers = ["World_Street_Map", "World_Topo_Map", "USA_Topo_Maps"];
    TOC.openItems = TOC.dataProvider.source;    
   }


Note:  Everything works fine (without errors) when I comment out the TOC.excludeLayers line. 

So far, I've only been able to find threads for the excludeLayers method for the Sample Flex Viewer Live Maps Widget, and no one using it there seems to be having this problem.

Thanks in advance for any insight into this issue.
Tags (2)
0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus
Melony,

   Here is an example of how to get it working.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:esri="http://www.esri.com/2008/ags" xmlns:maplib="com.esri.maplib.*"
 pageTitle="Flex TOC Sample"
 layout="horizontal"
 paddingTop="0" paddingBottom="0" paddingLeft="0" paddingRight="0"
 horizontalGap="0"
 >
 
 <mx:Panel title="Map Content" width="300" height="100%">
  <maplib:TOC width="100%" height="100%" map="{map}" useLayerFadeEffect="true" excludeGraphicsLayers="true" excludeLayers="{[AerialMap,TopoMap,StreetMap]}"/>
 </mx:Panel>
 
 <esri:Map id="map">
  <!-- base maps -->
  <esri:ArcGISTiledMapServiceLayer id="AerialMap" visible="true" url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer"/>
  <esri:ArcGISTiledMapServiceLayer id="TopoMap" visible="false" url="http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer"/>
  <esri:ArcIMSMapServiceLayer id="IMSWorld" visible="false" serviceHost="http://www.geographynetwork.com" serviceName="ESRI_World"/>
  <esri:ArcGISTiledMapServiceLayer id="StreetMap" visible="false" url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"/>
  
  <!-- base map overlays -->
  <esri:ArcGISTiledMapServiceLayer visible="true" url="http://server.arcgisonline.com/ArcGIS/rest/services/Reference/ESRI_Transportation_World_2D/MapServer"/>
  <esri:ArcGISTiledMapServiceLayer visible="false" url="http://server.arcgisonline.com/ArcGIS/rest/services/Reference/ESRI_Boundaries_World_2D/MapServer"/>
  <esri:ArcGISTiledMapServiceLayer visible="false" url="http://server.arcgisonline.com/ArcGIS/rest/services/Reference/ESRI_BoundariesPlacesAlt_World_2D/MapServer"/>
  <esri:ArcGISTiledMapServiceLayer visible="true" url="http://server.arcgisonline.com/ArcGIS/rest/services/Reference/ESRI_BoundariesPlaces_World_2D/MapServer"/>
  
  <!-- thematic overlays -->
  <esri:ArcGISDynamicMapServiceLayer visible="false" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer"/>
  <esri:GraphicsLayer visible="true">
   <esri:Graphic>
    <esri:geometry>
     <esri:MapPoint x="-117.195533" y="34.057058"/>
    </esri:geometry>
    <esri:symbol>
     <esri:SimpleMarkerSymbol style="diamond" color="0x33FF00" alpha="0.8" size="18"/>
    </esri:symbol>
   </esri:Graphic>
  </esri:GraphicsLayer>
 </esri:Map>
</mx:Application>
0 Kudos
MelonyBarrett
Occasional Contributor
Hi there, Robert,

Of course, that worked!  So simple.  Do I understand correctly, that by calling my function with excludeLayers in it in the creationComplete event, I was calling it too late?  Is your solution the same thing as calling the function with excludeLayers in it from the initialize event?  I'm just trying to understand so I can store it away in my brain for future reference. 

You and some other notables have been an invaluable resource to me since starting out with Flex in October 2009.  I've received a real education from your answers to my posts and others' posts.  Yay!  😄

Thanks so much!!
Melony
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Melony,

   The way I am doing it in the sample is I am passing an array of Layer objects and not an array of strings like you were. The array of strings will work also if those are the EXACT ids of the layers in your code.
0 Kudos
MelonyBarrett
Occasional Contributor
Well, duh, I'm glad I asked.  Funny how you can look at something, but not SEE it.  I'm always trying to make it harder than it is.

Again, thanks,

Melony
0 Kudos
tanyabisen
Emerging Contributor
Hi Melony,

The link which you have provided in the thread for TOC,can you share it with me I am currently facing the same problem. I want to hide some of the layers from my TOC.

Any help would be great

Thanks,
Tanya Bisen
0 Kudos
MelonyBarrett
Occasional Contributor
Just do exactly what Robert said.  Your TOC mxml should look something like the following code (where AerialMap, TopoMap, and StreetMap are the ids of the services you want to exclude from the TOC.

 
<maplib:TOC width="100%" height="100%" map="{map}" useLayerFadeEffect="true" excludeGraphicsLayers="true" excludeLayers="{[AerialMap,TopoMap,StreetMap]}"/>


Here's an example of the mxml for one of the excluded layers, AerialMap (notice the id):

 
<esri:ArcGISTiledMapServiceLayer id="AerialMap" visible="true" url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer"/>
0 Kudos
tanyabisen
Emerging Contributor
Hey Melony..Sorry for replying late..Thanks for the reply...its working now... but now I just have one issue... since I am using Bing maps as my base map...I can see that service also in my TOC with "Unknown " name... how do i change the name... ???
0 Kudos
YasmineMegahed1
Deactivated User
Hi, I've tried the code, but when run on the browser nothing appears !!! & when click on screen it becomes totally black, can anyone help me solving that issue?
0 Kudos
RhettZufelt
MVP Notable Contributor
Yasmine,

So, are you saying that you are trying to get this to work in an old 2.x version of the FlexViewer?

Not sure what you are asking, as if you have the new viewer and installed the latest TOC widget as described in the documentation, then this code shouldn't be needed as the exlcudelayers is a configurable option now.

R_
0 Kudos