How can we clear the map contents

603
5
03-07-2012 10:54 PM
MohammedIsmail
New Contributor
hi

i was trying to clear the map object so that at a time only one service should be visible and same should reflect in the legend

but i am unable to do that


as you can see in the screen shot i have attached


Thanks & regards
ISmail
Tags (2)
0 Kudos
5 Replies
IvanBespalov
Occasional Contributor III
0 Kudos
MohammedIsmail
New Contributor
hi

i have added the highligted code to LEgendSkin skin class file (com.esri.ags.skins.LegendSkin) but it makes no difference to the legend
and i tried commenting few lines  in the legendskin class file




// exclude Spacer if sublayer is not visible
  if (serviceGroups.getElementAt(e) is mx.controls.Spacer)
  {
      if (isSubLayerVisible)
      {
          mx.controls.Spacer(serviceGroups.getElementAt(e)).visible = mx.controls.Spacer(serviceGroups.getElementAt(e)).includeInLayout = true;
   if (!subLayerInScaleRange(leafLayerLegendInfo))
   {
       if (hostComponent.respectCurrentMapScale)
       {
           mx.controls.Spacer(serviceGroups.getElementAt(e)).visible = mx.controls.Spacer(serviceGroups.getElementAt(e)).includeInLayout = false;
       }
   }
      }
      else
      {
          mx.controls.Spacer(serviceGroups.getElementAt(e)).visible = mx.controls.Spacer(serviceGroups.getElementAt(e)).includeInLayout = false;
      }
                }



what could be the reason if u can tell me it will be great help


thanks
ismail
0 Kudos
IvanBespalov
Occasional Contributor III
Legend for 2 standalone layers. (code) - only selected service visible in Legend component.

Show your code. (it's easyest way to find bugs in your code)
0 Kudos
MohammedIsmail
New Contributor
hi

Below is the code , pls tell me

1.  i want to clear map i.e. is should display only one service at a time

2.  Legend should show only one service layers

Thanls

<?xml version="1.0" encoding="utf-8"?>
<s:Application 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:esri="http://www.esri.com/2008/ags">
<fx:Script>
  <![CDATA[
   import com.esri.ags.events.LayerEvent;
   import com.esri.ags.geometry.MapPoint;
   import com.esri.ags.layers.ArcGISDynamicMapServiceLayer;
  
   import mx.charts.chartClasses.LegendData;
  
   [Bindable] private var layerCount:int = 0;

  
   protected function myURL_creationCompleteHandler(event:Event):void
   {
    if(!MyML.getLayer(myURL.selectedItem)){
     var myDynamicService:ArcGISDynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer();
    
     myDynamicService.url = "http://gis-server/ArcGis/rest/services/" + myURL.selectedItem + "/MapServer";
     myDynamicService.name = myDynamicService.id = myURL.selectedItem;
     myDynamicService.addEventListener(LayerEvent.LOAD, setMapCenter);
     MyML.addLayer(myDynamicService);
     layerCount++;
   
    }else{
     setMapCenter(null);
    }
   }
  
   private function setMapCenter(evt:Event):void
   {
   
    switch(myURL.selectedItem)
    {
     case "Raichur":{
     
      MyML.centerAt(new MapPoint(76.90,16.12));
      break;
     }
     case "Yadgir":{
      MyML.centerAt(new MapPoint(76.88,16.89));
      break;
     }
     case "BangalururRural":{
      MyML.centerAt(new MapPoint(77.56,13.30));
      break;
     }
     case "Bidar":{
      MyML.centerAt(new MapPoint(77.27,17.95));
      break;
     }
     case "Bijapur":{
      MyML.centerAt(new MapPoint(75.98,16.78));
      break;
     }
    }
   }
  
  
  
  ]]>
</fx:Script>
<esri:Map id="MyML" width="100%" height="100%"
     scaleBarVisible="true"/>



<s:VGroup width="250" height="358" y="400" x="1230">
  <esri:Legend id="myLegend" 
      width="100%" height="100%"
      map="{MyML }"
    
      updateComplete="true"
      visible="true"
      respectCurrentMapScale="true" skinClass="com.esri.ags.skins.LegendSkin"/>
</s:VGroup>




<s:DropDownList id="myURL" change="myURL_creationCompleteHandler(event)"
    
     creationComplete="myURL_creationCompleteHandler(event)" selectedIndex="0">
  <s:ArrayList>
   <fx:String>Raichur</fx:String>
   <fx:String>Yadgir</fx:String>
   <fx:String>BangalururRural</fx:String>
   <fx:String>Bidar</fx:String>
   <fx:String>Bijapur</fx:String>
  </s:ArrayList>
</s:DropDownList>
<s:Label text="{layerCount}" x="200" y="3" />
</s:Application>
0 Kudos
IvanBespalov
Occasional Contributor III
In this sample:
1 - Layer visibility change works.
2 - Legend content change works.

<?xml version="1.0" encoding="utf-8"?>
<s:Application 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:ags="http://www.esri.com/2008/ags">
 
 <!-- Adobe Flex SDK 4.5.1 -->
 <!-- ArcGIS API for Flex 2.5 -->
 
 <s:layout>
  <s:HorizontalLayout gap="5"
        paddingBottom="10"
                                           paddingLeft="20"
        paddingRight="20"
        paddingTop="20"/>
 </s:layout>
 <fx:Script>
  <![CDATA[
   import com.esri.ags.events.LayerEvent;
   import com.esri.ags.layers.Layer;
   
   import mx.collections.ArrayCollection;
   
   import spark.events.IndexChangeEvent;

   [Bindable]
   private var layersList:ArrayCollection = new ArrayCollection();
   
   protected function onLayerLoad(event:LayerEvent):void
   {
    layersList.addItem(event.layer);
    if (layersList.length == 1)
    {
     ddlLayers.selectedIndex = 0;
     ddlLayers.dispatchEvent(new IndexChangeEvent(IndexChangeEvent.CHANGE, false, false, -1, 0));
    }
   }

   protected function onLayerSelectionChange(event:IndexChangeEvent):void
   {
    for each (var layer:Layer in myMap.layers)
    {
     if (layer == ddlLayers.selectedItem)
     {
      layer.visible = true;
      layer.validateNow();
      
      myLegend.map = myMap;
      myLegend.respectCurrentMapScale = true;
      myLegend.layers = new Array(layer);      
     }
     else if (layer is ArcGISDynamicMapServiceLayer)
     {
      layer.visible = false;
     }
    }
   }

  ]]>
 </fx:Script>
 
 <ags:Map id="myMap">
  <ags:ArcGISTiledMapServiceLayer id="baseLayer" 
             url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
  <ags:ArcGISDynamicMapServiceLayer id="layer1"
           load="onLayerLoad(event)"
           imageFormat="png32"
           name="Events"
           url="http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/LocalGovernment/Events/MapServer" />
  <ags:ArcGISDynamicMapServiceLayer id="layer2"
           load="onLayerLoad(event)"
           imageFormat="png32"
           name="Recreation"
           url="http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/LocalGovernment/Recreation/MapServer" />
  <ags:ArcGISDynamicMapServiceLayer id="layer3"
           load="onLayerLoad(event)"
           imageFormat="png32"
           name="Geology"
           url="http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/Energy/Geology/MapServer" />
 </ags:Map>
 
 <s:VGroup gap="5"
         paddingLeft="5"
         paddingTop="5"
         paddingRight="5"
         paddingBottom="5"
         height="100%"
         width="100%">
  
  <s:DropDownList id="ddlLayers"
           minWidth="200"
           dataProvider="{layersList}" 
           labelField="name" 
           change="onLayerSelectionChange(event)"/>
  
  <s:Scroller height="100%">   
   
   <s:Group height="100%">    
    
    <ags:Legend id="myLegend" />
    
   </s:Group>
   
  </s:Scroller>  
  
 </s:VGroup>
 
</s:Application>


Good luck.
0 Kudos