Select to view content in your preferred language

FlexViewer 2.0 LayerList

1420
10
09-01-2010 01:41 PM
MelissaJohnson
Frequent Contributor
I am new to the Flex API and have gotten pretty far with configuring the new flex viewer (I downloaded the version with source) , but I am stuck on the LayerListWidget.  I am trying to set it up to load layers from my dynamic map service.  The dynamic map service displays fine.  I have 3 services under basemaps (in config.xml), an aerial, streets (both tiled), and general data service(dynamic). 

I can't figure out what in LayerListWidget.mxml I need to change to read the layers in my dynamic service.  I hooked it up in config.xml:

<widget label="Layer List" x="600" y="400" icon="assets/images/i_layers.png"
          config="widgets/LayerListWidget.xml"
          url="widgets/LayerList/LayerListWidget.swf"/>

and it shows up in the toolbar and when you select it you get:

Application Error
Error:Event Target:[objectHTTPOperation]
Event Type: Fault
Fault Code: Server.Error.Request
Fault Info: HTTP request errror

The Layer List widget comes up but is empty.  Love the sample viewer and appreciate its being made available, but I do wish there were more detailed explanations in the code to help configure it.

I assume it is not able to figure out where the layer is to pull from.  Is there something else I need to change to configure this correctly?  Thanks in advance!
Melissa
Tags (2)
0 Kudos
10 Replies
SandeepTalasila
Occasional Contributor
Hi Robert,
I've tried to use your code to expand my TOC in layer list widget, but nothing happens. I can't get to expand my TOC automatically, shall I have to add anything in config.xml too for this to work? Thanks.

EDIT: Got it. worked after using validateNow() function.

Melissa,


    If you have the FlexViewer2.0 source code than you just have to add some code to the LayerListWidget.mxml.

<?xml version="1.0" encoding="utf-8"?>
<!--
     ////////////////////////////////////////////////////////////////////////////////
     //
     // Copyright (c) 2010 ESRI
     //
     // All rights reserved under the copyright laws of the United States.
     // You may freely redistribute and use this software, with or
     // without modification, provided you include the original copyright
     // and use restrictions.  See use restrictions in the file:
     // <install location>/License.txt
     //
     ////////////////////////////////////////////////////////////////////////////////
-->
<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   xmlns:viewer="com.esri.viewer.*"
                   xmlns:toccomp="com.esri.viewer.components.toc.*"
                   widgetConfigLoaded="init()"
                   x="600"
                   y="400">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
   import com.esri.viewer.components.toc.tocClasses.TocMapLayerItem;

            private function init():void
            {
                toc.map = map;
                toc.isMapServiceOnly = false; //gotta get this from the config file
                toc.excludeLayers = getExcludeLayers();
                toc.excludeGraphicsLayers = true;
    callLater(expandTOC);
            }
   
   private function expandTOC():void
   { 
    toc.openItems = toc.dataProvider.source;
    for each(var item:TocMapLayerItem in toc.openItems) {
     if (item.isTopLevel()){
      toc.expandItem(item, true);
     }
    }              
   }

            private function getExcludeLayers():ArrayCollection
            {
                var result:ArrayCollection = new ArrayCollection();

                if (configData && configData.basemaps)
                {
                    // exclude basemaps
                    for (var i:int = 0; i < configData.basemaps.length; i++)
                    {
                        result.addItem(configData.basemaps.label);
                    }
                }

                if (configXML)
                {
                    // exclude these layers
                    var layers:XMLList = configXML.excludelayer as XMLList;
                    for (var j:Number = 0; j < layers.length(); j++)
                    {
                        result.addItem(layers.toString());
                    }
                }

                return result;
            }
        ]]>
    </fx:Script>
    <viewer:WidgetTemplate id="wTemplate"
                           height="300"
                           width="300">
        <viewer:layout>
            <s:VerticalLayout gap="8" paddingTop="4"/>
        </viewer:layout>
        <s:Label text="Layer Visibility"/>
        <toccomp:TOC id="toc"
                     height="100%"
                     width="100%"/>
    </viewer:WidgetTemplate>
</viewer:BaseWidget>
0 Kudos