Create FeatureLayer from IdentifyResults

3738
4
01-30-2015 12:54 PM
ViridianaGómez_Olivera
New Contributor

Hello, I want to make a FeatureLayer from IdentifyResults because I want to see the Results in the AttributeTable, like as mentioned in this thread, how can I do that?:

https://community.esri.com/thread/88653#367162

This have to do with the Dynamic Workspace?

Robert Scheitlin, GISP

I really will appreciate your help, regards.

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Viridiana,

  So you will have to loop thought the identify results and make an array of the results feature (which is just a graphic), and then you can use some code like I have in my ShapeFile widget to create a new FeatureLayer using a FeatureCollection. Here is some snippets of code from my Shapefile widget that are the main parts of what you need to do. This code in not copy and paste ready for your application you will have to tailor it to you needs.

featureSet = new FeatureSet(graArr);

layerDetails = creatLayerDetails(sfr, map.spatialReference); //sfr is my custom shapefile result object

featureLayer = new FeatureLayer();

featureLayer.spatialReference = map.spatialReference;

featureLayer.name = "some name";

featureLayer.mode = FeatureLayer.MODE_ON_DEMAND;

featureLayer.featureCollection = new FeatureCollection(featureSet, layerDetails);

featureLayer.renderer = new SimpleRenderer(defaultSymbol);

map.addLayer(featureLayer);

function for making the LayerDetails:

            private function creatLayerDetails(sfr:ShapeFileResult, spatialReference:SpatialReference, isLabel:Boolean = false):LayerDetails

            {

                var layerDetails:LayerDetails = new LayerDetails();

                layerDetails = new LayerDetails();

                layerDetails.canModifyLayer = false;

                layerDetails.canScaleSymbols = false;

                layerDetails.copyright = "";

                layerDetails.defaultVisibility = true;

                layerDetails.extent = sfr.extent;

                layerDetails.hasAttachments = false;

                layerDetails.hasLabels = false;

                layerDetails.hasM = layerDetails.hasZ = false;

                layerDetails.isDataVersioned = false;

                layerDetails.spatialReference = spatialReference;

                layerDetails.version = Number.NaN;

                layerDetails.name = sfr.title;

               

                var di:DrawingInfo = new DrawingInfo();

                di.alpha = 1;

                di.renderer = new SimpleRenderer(sfr.symbol);

                layerDetails.drawingInfo = di;

                return layerDetails;

            }

0 Kudos
ViridianaGómez_Olivera
New Contributor

Thank you Robert for your response. Now I can create the FeatureLayer and add this to the map, but in the AttributeTable I can not see the Features, I attach a snapshot and the code, how can I see the Results in the Attribute Table?

Captura.PNG

This is how I create the array of the results feature:

var arrIdentify:Array = new Array();

  for each (var identifyResult:IdentifyResult in identifyResults){

       arrIdentify.push(identifyResult.feature);

       .

       .

       .

  }

And this is where I create the FeatureLayer:

  var sfr:ShapeFileResult = new ShapeFileResult();

  sfr.title = "Title";

  var sms:SimpleMarkerSymbol = new SimpleMarkerSymbol();

  sms.color = 0x0000FF;

  sms.style = SimpleMarkerSymbol.STYLE_CIRCLE;

  sms.size = 8;

  sfr.symbol = sms;

  sfr.extent = GraphicUtil.getGraphicsExtent(arrIdentify);

  sfr.content = "Length: "+arrIdentify.length;

  var featureSet:FeatureSet = new FeatureSet(arrIdentify); 

  var layerDetails:LayerDetails = creatLayerDetails(sfr, map.spatialReference); //sfr is my custom shapefile result object 

  var featureLayer:FeatureLayer = new FeatureLayer(); 

  featureLayer.spatialReference = map.spatialReference; 

  featureLayer.name = "Identify Results"; 

  featureLayer.mode = FeatureLayer.MODE_ON_DEMAND; 

  featureLayer.featureCollection = new FeatureCollection(featureSet, layerDetails); 

  featureLayer.renderer = new SimpleRenderer(new PictureMarkerSymbol("assets/images/i_target.png",30,30,0,0,0));

  map.addLayer(featureLayer); 

The creatLayerDetails function is like yours.

I will appreciate your help again

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Viridiana,

    As I mention in my last post the code snippet was not copy and paste ready. Unless you have created a ShapeFileResult object on your end then you have some issue with the code you are attempting to use.

0 Kudos
ViridianaGómez_Olivera
New Contributor

Hi Robert, thank you for your response again. I have created a ShapeFileResult object, so I will keep searching the error. Regards!

0 Kudos