Select to view content in your preferred language

Inserting images into LayerTOC datagrid.

1581
12
12-06-2010 10:11 AM
JasonLevine
Deactivated User
Hello all,
   I'm using the "Dynamic Map Layers on/off" sample in the code sample gallery.  I'm trying to insert a new DataGridColumn in the data grid and embed an image that represents each layer's symbol.  This is what my code looks like in the LayerTOC.mxml:
    <mx:columns>
        <mx:DataGridColumn width="57"
                           headerText="Visibility"
                           itemRenderer="com.esri.ags.samples.LayerVizRenderer"/>
  <mx:DataGridColumn width="57"
         headerText="Symbol">
   <mx:itemRenderer>
    <fx:Component>
     <mx:HBox width="100%" horizontalAlign="center" verticalAlign="middle">
      <mx:Image id="legendSymbol2" source="assets/images/crosshair.png"/>
     </mx:HBox>
    </fx:Component>
   </mx:itemRenderer>
  </mx:DataGridColumn>
        <mx:DataGridColumn dataField="name" headerText="Layer Name" width="163"/>
    </mx:columns>


The problem that I'm having is that every layer shows my crosshair.png image (see attached image).

How do I code a separate image for each of the layers in my TOC?

An example of this can be seen in the map at the bottom of this page: http://crownpeak.vipnet.org/cmsportal3/

Thanks for your help,
Jason
Tags (2)
0 Kudos
12 Replies
JasonLevine
Deactivated User
Hi Robert,
Inserting setDataProvider() into my itemClick function caused some very odd behavior.   Every time I click on a row in the datagrid, some (sometimes several) items disappear and I�??m eventually left with a completely empty datagrid.  It seems like when the setDataProvider() function is run more than once in the LayerTOC, the result is the removal of items from the datagrid.  I understand what you�??re saying though�?� The reason the images work for the symbol column is because the dataprovider is set in the LayerTOC.mxml further down.  Is there any way I can reset the dataprovider to reflect the changes in the imagerenderer without causing that strange behavior?

Thanks,
Jason
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Jason,

   Not real sure but try
dataProvider.refresh();
instead.
0 Kudos
JasonLevine
Deactivated User
Hi Robert,
   The strange behavior was happening because I remove a couple rows (using split) from my dataprovider array so that some of the layers don't show up in my TOC list.  when I run the setDataProvider() function a second time, it continues to remove rows where i've previously specified (that's why layers kept disappearing).  I tried using dataProvider.refresh() instead but it didn�??t work.  What I then tried was setting the itemrenderer in actionscript in my itemClick function:

private function onItemClick(event:ListEvent):void
   {
    SelectedLayerName = this.selectedItem.name;
    iRenderer.itemRenderer = new ClassFactory(com.esri.ags.samples.iRenderer);
   }


With my columns:
    <mx:columns>
        <mx:DataGridColumn width="57"
                           headerText="Visibility"
                           itemRenderer="com.esri.ags.samples.LayerVizRenderer"/>
  <mx:DataGridColumn width="57"
         headerText="Symbol" 
         dataField="name" 
         itemRenderer="com.esri.ags.samples.SymRenderer"/>
  <mx:DataGridColumn id="iRenderer" 
         width="45" 
         headerText="I" 
         dataField="name" />
        <mx:DataGridColumn dataField="name" headerText="Layer Name" width="163"/>
    </mx:columns>


What happens is only the last item in my if statement gets run.  For example, if its:
public function set listData(value:BaseListData):void
   {
    _listData = value;
    {
    if (LayerTOC.SelectedLayerName == "Zoning")
    {
     switch(listData.label)
     {
      case "Zoning":
      {
       SymPath = "assets/images/identify.png";
       break;
      }
      default:
      {
       SymPath = null;
       break;
      }
     }
    }
    if (LayerTOC.SelectedLayerName == "Land Use Policy")
    {
     switch(listData.label)
     {
      case "Land Use Policy":
      {
       SymPath = "assets/images/identify.png";
       break;
      }
      default:
      {
       SymPath = null;
       break;
      }
     }
    }
    if (LayerTOC.SelectedLayerName == "Transit Oriented District")
    {
     switch(listData.label)
     {
      case "Transit Oriented District":
      {
       SymPath = "assets/images/identify.png";
       break;
      }
      default:
      {
       SymPath = null;
       break;
      }
     }
    }
    if (LayerTOC.SelectedLayerName == "Parcel Boundary")
    {
     switch(listData.label)
     {
      case "Parcel Boundary":
      {
       SymPath = "assets/images/identify.png";
       break;
      }
      default:
      {
       SymPath = null;
       break;
      }
     }
    }
    else
    {
     SymPath = null;
    }
    }
   }


Only the Parcel Boundary works; the rest, when clicked on, stay blank. I've switched around the order, and every time, only the last one works.  Why would only the last one in the list work?

-Jason
0 Kudos