Select to view content in your preferred language

Getting Layer name from Graphic object

2399
5
Jump to solution
07-14-2013 03:29 AM
bojko108
Emerging Contributor
Hello,

I'm making a widget that asks user to make a selection and then
fills an information about selected objects in a Tree Control.
It searches all the operational layers loaded on the map and executes
spatial query to get FeatureSet for every layer.

I'm using this function to get result from the query and to put the selected
objects in ArrayCollection, later used as dataprovider for Tree Control:

private function onResult(featureSet:FeatureSet, token:Object = null):void {   var queryLayer:FeatureLayer = null;    if(token != null && token.hasOwnProperty("layer")){   queryLayer = token["layer"];       if(featureSet.features.length > 0){        // ArrayCollection holding selected objects by layers    this.SelectedObjectsMap.addItem({label: queryLayer.name, children: new ArrayCollection(featureSet.features)});        // tree control    this.treeSelection.dataProvider = this.SelectedObjectsMap;   }  } }


This function I'm using to label all the items in Tree Contrrol:

private function treeLabeling(item:Object):String{   // here I need information about Layer name  if(item is Graphic){   return (item as Graphic).attributes["STATE_NAME"].toString();  }    return item.label; }


The problem is that here I need to know from which Layer is this object. Is it possible to get this information from Graphic object, or FeatureSet collection?
Thanks

---
Bogdan Hristozov
Pontech Bulgaria
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DasaPaddock
Esri Regular Contributor
Can I get feature layer from Graphic object.


You can use the "graphicsLayer" property on Graphic. FeatureLayer extends GraphicsLayer so you can cast to FeatureLayer if you need to.

See:
https://developers.arcgis.com/en/flex/api-reference/com/esri/ags/Graphic.html#graphicsLayer

View solution in original post

0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Emeritus
Bogdan,

   you already know have the layer object when you add it to your SelectedObjectsMap. So why not just add the layer as a property of the SelectedObjectsMap object that you add?

You also add the layers name to the SelectedObjectsMap so you could just take that label and loop the map layer searching for the layer with that name.

Probably the best solution would be to grab the layerId of the layer in the map when you add it to the SelectedObjectsMap and add that as a property of the object you add that way the object is very light weight and you can just use a line like this to get the layer.

var lyr:Layer = map.getLayer("yourLayerId");
0 Kudos
bojko108
Emerging Contributor
Thanks for replay Robert,
I'm new in Flex programming and the problem is that I can't set custom dataprovider for Tree Control. First I made a class holding information about feature layer and selected objects, but when adding this class as dataprovider for Tree Control nothing was working.
As you can see I'm adding featureSet.features in Tree Control, which is Array of Graphic objects and when I am in treeLabeling(item:Object):String function, type of item is Graphic and I don't have information about feature layer.
I solve the problem by getting parent node for selected item. For each child item in Tree Control I have parent item which has information about feature layer. The question is more general. Can I get feature layer from Graphic object.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Bogdan,

   No there is not that I am aware of.
0 Kudos
DasaPaddock
Esri Regular Contributor
Can I get feature layer from Graphic object.


You can use the "graphicsLayer" property on Graphic. FeatureLayer extends GraphicsLayer so you can cast to FeatureLayer if you need to.

See:
https://developers.arcgis.com/en/flex/api-reference/com/esri/ags/Graphic.html#graphicsLayer
0 Kudos
bojko108
Emerging Contributor
Great idea but now I see that graphicsLayer is null for all Graphic objects, I have to check why is that.
Thanks, the problem is solved for now 🙂
0 Kudos