Select to view content in your preferred language

FlexViewer 2.0 LayerList

1418
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
RobertScheitlin__GISP
MVP Emeritus
Melissa,


   In your config.xml make this correction.

currently it has:
config="widgets/LayerListWidget.xml"


it should have:
config="widgets/LayerList/LayerListWidget.xml"
0 Kudos
MelissaJohnson
Frequent Contributor
Thanks!  I was banging my head against a wall with that one and you solved it.  Another couple of questions.  How do you make your layer list come on with the layers already expanded to their group level on your parcel viewer.  By the way, really nice site.  I know this can be done in .NET by using ExpandDepth=.

One more question...I find that I have to clear my internet history almost every time I run the debugger or my changes don't always show up.  Is there any way to change that?

Again, your assistance has been much appreciated!
0 Kudos
JoshuaCoates
Deactivated User
I used this exact xml and I can not get it to show up at all. The layerlist widget does not even appear on my map?
0 Kudos
MelissaJohnson
Frequent Contributor
This took me a lot of trial and error as I am just learning, but do you have the dynamic layer you want in your TOC inside your config.xml <operational layers>tags?  That was one of the things that was throwing me.
Also I put my widget task inside the widgetcontainer as the bookmarks and other icons are.

I did just discover another issue I have to figure out.  I have my map service set up with group layers, and I see that even though the group layer is turned off, any layers that are turned on within that group are coming up turned on, so it isn't honoring the group layer setting.
0 Kudos
JoshuaCoates
Deactivated User
Never mind, it was because I put it under the print widget, i just moved it above and it worked?! Why is it that the layers display twice? I click the layer list widget and then it shows my two layers, and then if u click one...it shows the same title layer and u have to click it again to get to the sublayers in the service? Any ideas? Melissa, does yours do this as well?
0 Kudos
MelissaJohnson
Frequent Contributor
Nope.  Mine only shows it once.  Not sure why it would show twice unless you have it in operational layers 2x???
0 Kudos
JoshuaCoates
Deactivated User
I dont,
<operationallayers>
            <layer label="" type="dynamic" visible="false"
                url="http://publicgis/PublicGISserver/rest/services/Basemap/MapServer"/>
            <layer label="" type="dynamic" visible="false" visiblelayers="1,4,5"
                url="http://publicgis/PublicGISserver/rest/services/2007_DFIRM/MapServer"/>
            <layer label="" type="dynamic" visible="false" visiblelayers="3,4"
                   url="http://publicgis/PublicGISserver/rest/services/2010_BartowFloodplain/MapServer"/>
</operationallayers>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
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
MelissaJohnson
Frequent Contributor
Thanks for all of your help...wish I could give you mvp points.

I have the layers expanded, but another issue has come up.  My data in the map services is organized as

Group Layer
       layer
       layer
and so on.  Most of the group layers are turned off by default with select layers inside the group turned on by default. 
The problem is that when I check a group layer in the layer list, all of the sub-layers turn on regardless of whether or not the main Group Layer is checked?  Is there a place I can find more info on how to configure the tree so that the sub layers don't come on unless the group is checked?

Also I am unable to get my layers I listed as <exclude> not to appear when I build.
Thanks again in advance.
0 Kudos