Select to view content in your preferred language

Table of Contents - Legend Widget for FlexViewer 2.x

186976
664
12-01-2010 07:30 AM
RobertScheitlin__GISP
MVP Emeritus
All,

Here is the next in my line of widgets for the FlexViewer 2.x.

The legend portion of this widget is the same code as my dynamic legend widget so,

IT IS FOR ARCGIS SERVER 10 OR GREATER ONLY

This is just a simple TOC Widget that includes my dynamic legend component.
This widget also includes my enhancement for map service transparency,
right click context menu for zoom to make layer visible, and my scale
dependent renderer for the TOC checkboxes.
Tags (2)
0 Kudos
664 Replies
GauravMaske
Emerging Contributor
In TOCMapLayerItem.as modify the getLegendData function as below (marked with bold letters), to add token to service url-

private function getLegendData(m_layer:*):void
  {
   if (_legendDataLoaded)
   {
    return;
   }
   _legendDataLoaded = true;
  
   if (m_layer.hasOwnProperty("url"))
   {
    const url:String = m_layer["url"];
    if (url === null)
    {
     return;
    }
   }
   else
   {
    return;
   }
  
   var httpServ:HTTPService = new HTTPService();
   httpServ.requestTimeout = lTimeout;
   var lname:String;
   var lInfos:Array;
   if (m_layer is ArcGISTiledMapServiceLayer)
   {
    if(m_layer.version >= 10.01)
    {
     httpServ.url = ArcGISTiledMapServiceLayer(m_layer).url + "/legend?f=json";
     // Source Edit by JMB - add support for token-secured services
     if (ArcGISTiledMapServiceLayer(m_layer).token && ArcGISTiledMapServiceLayer(m_layer).token != "")
     {
      httpServ.url += "&token=" + ArcGISTiledMapServiceLayer(m_layer).token;
     }
     httpServ.resultFormat = "text";
     lname = ArcGISTiledMapServiceLayer(m_layer).id;
     lInfos = ArcGISTiledMapServiceLayer(m_layer).layerInfos;
     httpServ.addEventListener(ResultEvent.RESULT,function(event:ResultEvent):void{processLegend(event,lname,Number.NaN,lInfos,httpServ.url)});
     httpServ.send();
    }else{
     lname = ArcGISTiledMapServiceLayer(m_layer).id;
     ArcGISTiledMapServiceLayer(m_layer).addEventListener(DetailsEvent.GET_ALL_DETAILS_COMPLETE,function(event:DetailsEvent):void{getAllDetailsResult(event,lname)});
     ArcGISTiledMapServiceLayer(m_layer).addEventListener(FaultEvent.FAULT, function(event:Event):void{FlexGlobals.topLevelApplication.dispatchEvent(new Event("legendDataLoaded$"))});
     ArcGISTiledMapServiceLayer(m_layer).getAllDetails();
    }
   }
   else if (m_layer is ArcGISDynamicMapServiceLayer)
   {
    if(m_layer.version >= 10.01)
    {
     httpServ.url = ArcGISDynamicMapServiceLayer(layer).url.replace("?token=", "/legend?f=json&token=");     httpServ.resultFormat = "text";
     lname = ArcGISDynamicMapServiceLayer(m_layer).id;
     lInfos = ArcGISDynamicMapServiceLayer(m_layer).layerInfos
     httpServ.addEventListener(ResultEvent.RESULT,function(event:ResultEvent):void{processLegend1(event,lname,Number.NaN,lInfos,httpServ.url)});
     httpServ.send();
    }else{
     lname = ArcGISDynamicMapServiceLayer(m_layer).id;
     ArcGISDynamicMapServiceLayer(m_layer).addEventListener(DetailsEvent.GET_ALL_DETAILS_COMPLETE,function(event:DetailsEvent):void{getAllDetailsResult(event,lname)});
     ArcGISDynamicMapServiceLayer(m_layer).addEventListener(FaultEvent.FAULT, function(event:Event):void{FlexGlobals.topLevelApplication.dispatchEvent(new Event("legendDataLoaded$"))});
     ArcGISDynamicMapServiceLayer(m_layer).getAllDetails();
    }
   }
   else if (m_layer is FeatureLayer)
   {
    var FeatServId:Number = Number.NaN;
    var msName:String = FeatureLayer(m_layer).url.replace("FeatureServer","MapServer");
    if(msName.substring(msName.length - 9) != "MapServer")
    {
     httpServ.url = msName.substring(0,msName.lastIndexOf("/")) + "/legend?f=json";
     FeatServId = parseInt(msName.substring(msName.lastIndexOf("/")+ 1));
    }else{
     httpServ.url = msName + "/legend?f=json";
    }
    // Source Edit by JMB - add support for token-secured services
    if (FeatureLayer(m_layer).token && FeatureLayer(m_layer).token != "")
    {
     httpServ.url += "&token=" + FeatureLayer(m_layer).token;
    }
    if(m_layer.layerDetails.version >= 10.01)
    {
     httpServ.resultFormat = "text";
     lname = FeatureLayer(m_layer).id;
     httpServ.addEventListener(ResultEvent.RESULT,function(event:ResultEvent):void{processLegend(event,lname,FeatServId)});
     httpServ.send();
    } else {
     lname = FeatureLayer(m_layer).id;
     getFeatureResult(FeatureLayer(m_layer).layerDetails,lname);
    }
   }
  }
0 Kudos
ChristopherBlinn1
Deactivated User
Hi Robert,

I see others have had the same issue I seem to be having, but unfortunately after downloading your latest version (2.4.5) I still have the problem.  When the web application loads, the "Generating TOC Legend" continues to just spin.  I am unsure what the cause may be.  I am running AGS 10 SP3, and using the 2.4 Flex Viewer.

You can see site I am developing here:
http://maps.evansvillegis.com/bicentennial/

Any ideas?

Thanks,
Chris
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Chris,

  Your issue is that you have only one map service in your map and it is a basemap layer and then in the TOCWidget.xml you have the default for excludebasemaplayers set to true. So if you change that to false you will be in business.
0 Kudos
ChristopherBlinn1
Deactivated User
Robert,

Leave it to me to overlook obvious things.  I blame it on it being Monday morning.  Thanks again!

-Chris
0 Kudos
EmilyLaMunyon
Deactivated User
Hello,

After reading through this thread I am still not clear about this.

Is it possible to exclude one layer from the TOC? I have layers in my base map that I do not want repeated in the TOC. If so, what is the correct way to configure the code, this is not working for me.
<excludelayers>
  <excludelayer mapservice="Cities">6</excludelayer>
 
  <excludelayer mapservice="Roads">5</excludelayer>
</excludelayers>


Thanks!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Emily,

   It is very straight forward. If Cities is the label of a mapservice in your main config.xml than the layer with the id NUMBER of 6 will not appear in the TOC. I am not sure what else to tell you as this feature has been throughly tested and it works.
0 Kudos
EmilyLaMunyon
Deactivated User
Thanks Robert, I apologize for my lack of understanding.:o I just am unable to get the layers to not show up in the TOC, even after clearing the browser many times.

My main config.xml references my entire mapservice, could this be the issue?


<layer label="Salt Lake County" type="dynamic"  visible="false" alpha="1"
                   url="http://slcarcgisdev1/SLCOGIS/rest/services/public/Surveyor/MapServer/">
   <sublayer id="1" popupconfig="popups/PopUp_corner_reports.xml"/>
   <sublayer id="0" popupconfig="popups/PopUp_control.xml"/>
   <sublayer id="12" popupconfig="popups/PopUp_surveys.xml"/>
  </layer>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Emily,

   You need to use the "Salt Lake County" then, that was what I was trying to explain.

<excludelayers>
  <excludelayer mapservice="Salt Lake County">5,6</excludelayer>
 </excludelayers>
0 Kudos
EmilyLaMunyon
Deactivated User
That did it Robert, I really appreciate you putting up with me!!
0 Kudos
KarlWilson
Frequent Contributor
Robert,

Is there a way of displaying a raster image in the TOC legend without it appearing as "Red, Green, Blue"?

I notice that in your sample application the "Tornado 2011" image has a nice little raster icon.

See attached screen shots.

Cheers,
Karl
0 Kudos