Select to view content in your preferred language

creating a graphic layer from another feature layer

3093
8
01-10-2011 07:24 AM
abukhan
Occasional Contributor
I have a feature layer and it shows polygons.

i want to create another graphic layer from the above ..
I tried to use graphiclayer.graphicprovider = featurelayer.graphicprovider , but it did not work..
I tried creating a deep copy of the arraycollection of the featurelayer and then use that as the graphiclayer graphicprovider  but that did not work

Is there any way of creating this?

Thanks
Tags (2)
0 Kudos
8 Replies
RobertScheitlin__GISP
MVP Emeritus
Abu,

  This code worked for me:

<?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"
      minWidth="955" minHeight="600">
 <fx:Script>
  <![CDATA[
   import com.esri.ags.events.LayerEvent;
   import com.esri.ags.layers.GraphicsLayer;
   
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;

   // the following four functions are 'just' error handling and showing/hiding the busy cursor
   protected function fLayer_updateStartHandler(event:LayerEvent):void
   {
    this.cursorManager.setBusyCursor();
   }
   
   protected function fLayer_updateEndHandler(event:LayerEvent):void
   {
    var ac:ArrayCollection = fLayer.graphicProvider as ArrayCollection;
    var gl:GraphicsLayer = new GraphicsLayer();
    gl.graphicProvider = ac;
    myMap.addLayer(gl);
    fLayer.visible = false;
    this.cursorManager.removeBusyCursor();
   }
  ]]>
 </fx:Script>
 <esri:Map id="myMap">
  <esri:extent>
   <esri:Extent xmin="-14305000" ymin="2748000" xmax="-6815000" ymax="7117000">
    <esri:SpatialReference wkid="102100"/>
   </esri:Extent>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Physical_Map/MapServer"/>
  <esri:FeatureLayer id="fLayer"
         mode="snapshot"
         updateEnd="fLayer_updateEndHandler(event)"
         updateStart="fLayer_updateStartHandler(event)"
         url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSFields/FeatureServer/0"/>
 </esri:Map>
</s:Application>
0 Kudos
abukhan
Occasional Contributor
Thanks robert..yes it works..

Abu
0 Kudos
abukhan
Occasional Contributor
However it looks like the feature layer does not show (even though you make fLayer visible and gl not visible)
0 Kudos
DasaPaddock
Esri Regular Contributor
A Graphic is a Flash DisplayObject so it can only exist in one container at a time. You'll need to create separate instances if you want them to exist in both layers.
0 Kudos
abukhan
Occasional Contributor
what i wanted was:
create graphic layer from the feature layer and render it differently than the feature layer..I donot want to loose the feature layer and it will be rendered different than the graphic layer..
0 Kudos
abukhan
Occasional Contributor
Desa:

any example of the above scenerio will be appreciated
0 Kudos
DasaPaddock
Esri Regular Contributor
You could create two FeatureLayers where you've set your own renderer or symbol on the 2nd one. This will put more load on the network and the server though so you could duplicate the Graphics and put the copy in the GraphicsLayer.

e.g. create a shallow clone that has a reference to the same geometry and attributes:

var newG:Graphic = new Graphic(oldG.geometry, null, oldG.attributes);
graphicsLayer.add(newG);
0 Kudos
abukhan
Occasional Contributor
Dasa:

Thanks a lot.. it was very useful.

Abu
0 Kudos