Select to view content in your preferred language

Append or merge or move or copy graphic(s) or featureset(s) or array(s) or ?

658
0
10-20-2010 12:34 PM
MelonyBarrett
Occasional Contributor
I have set up a clip and ship geoprocessing service.  The way it works is the user checks a box for each layer they want to download, and then they draw a single polygon or multiple polygons.  After each polygon is drawn the resulting graphic is pushed to an array, and then added to a graphicsLayer.  Finally when the user pushes the a button, the array of graphics is passed to a function that creates a FeatureSet from it and then sends it on to the geoprocessing service.

Independently of this code, I have implemented code for shapefile overlay which ultimately takes a zipfile containing all the files associated with a polygon shapefile and then adds the features from it to a graphicsLayer, and then zooms.

What I want to be able to do is put all of these polygons together somehow into something so that I can use all of them for the clip!  I need to get the graphics from graphicsLayer (from the shapefile code) into my clipGraphicsArray somehow.  I've tried a couple of different things, but they do not work.  Incidentally, I haven't even been able to feed the shapefile graphics alone into the doClip() function to use them for the clip.  So, if someone knows even how to do that, maybe I could hack out the rest on my own.

Does anyone know how I should go about doing this?

Here's all the relevant code:

private var clipGraphicsArray:Array;

private function init():void
{ 
 clipGraphicsArray = [];  
}

private function drawClipPoly(event:MouseEvent):void
{
 clipDrawToolbar.activate(DrawTool.POLYGON, true);
}

private function clipDrawEndHandler(event:DrawEvent):void
{
 clipGraphicsArray.push(event.graphic);
 clipGraphicsLayer.add(event.graphic);
}            



Here's the shapefile code.  It seems like I need to get the graphics from graphicsLayer and somehow push/add them to my clipGraphicsArray, but I just can't figure it out.
private function loadShapefile(shpByteArray:ByteArray, dbfByteArray:ByteArray):void
{
 var index:int = 0;
 const array:Array = [];
 const shpReader:ShpReader = new ShpReader(shpByteArray);
 const dbfHeader:DbfHeader = new DbfHeader(dbfByteArray);
 while (shpReader.hasMore())
 {
  var shpPolygon:ShpPolygon = shpReader.readShpPolygon();
  var dbfRecord:DbfRecord = DbfTools.getRecord(dbfByteArray, dbfHeader, index++);
  // Now takes _all_ attributes
  array.push(new Graphic(shpPolygon, shpSymbol, dbfRecord.values)); 
 }
 
 graphicsLayer.graphicProvider = new ArrayCollection(array);
 map.extent = shpReader.extent.expand(1.5);
}


This code is triggered by a button click once the user has selected the download layers and drawn polygon(s):

private function doClip():void
{
 clipDrawToolbar.deactivate();     
 
 var myEmail:String = inputEmail.text;
 var featureSet:FeatureSet = new FeatureSet(clipGraphicsArray);
 var params:Object = 
  {
   "Area_To_Download": featureSet,
   "Layers_to_Download" : { "features"  : [
    {"attributes" : {"LayerName" : strRow1, "DownLoad" : Row1}},
    {"attributes" : {"LayerName" : strRow2, "DownLoad" : Row2}},
    {"attributes" : {"LayerName" : strRow3, "DownLoad" : Row3}},
    {"attributes" : {"LayerName" : strRow4, "DownLoad" : Row4}},
    {"attributes" : {"LayerName" : strRow5, "DownLoad" : Row5}},
    {"attributes" : {"LayerName" : strRow6, "DownLoad" : Row6}}
   ]},
   "Email_address_to_send_zip_file": myEmail
  };       
 gp.submitJob(params);
} 
Tags (2)
0 Kudos
0 Replies