How to "raise" selected feature in FeatureLayer

632
3
Jump to solution
03-23-2012 04:00 AM
MihkelOviir
New Contributor
I'm using jsapi v2.7 compact version. I have a FeatureLayer layer with lines features from REST service. Lines are quite messy, so there is basically one big haystack. If I select one line (not from map by mouse, but from list of items, with FeatureLayer.selectFeatures()), it will be highlighted, but it is not visible, because others lines a above highlighted line (see picture). If I unselect this line, then it shows above all others. Is it normal behavior? In OpenLayers, select is control and it is above all other layers. How to accomplish that selected feature is always above all others features?

[ATTACH=CONFIG]12946[/ATTACH]
selected feature (red, wider) is not visible, because all other features are above
0 Kudos
1 Solution

Accepted Solutions
MattMoyles
New Contributor III
get a handle to the esri.Graphic (the feature you have selected) and call

g.getDojoShape().moveToFront();

where g is your esri.Graphic

If you need to loop through a map's features you can do something like this:
dojo.forEach(this.map.getLayer('Points').graphics, function(g) {                                     if(g.attributes.OBJECTID == objectId)                     {                         if(g.getDojoShape() != null) g.getDojoShape().moveToFront();                     } });  

View solution in original post

0 Kudos
3 Replies
KenDoman
Occasional Contributor II
Quick question: Are the other lines on top of the selected line in the same FeatureLayer?
0 Kudos
MattMoyles
New Contributor III
get a handle to the esri.Graphic (the feature you have selected) and call

g.getDojoShape().moveToFront();

where g is your esri.Graphic

If you need to loop through a map's features you can do something like this:
dojo.forEach(this.map.getLayer('Points').graphics, function(g) {                                     if(g.attributes.OBJECTID == objectId)                     {                         if(g.getDojoShape() != null) g.getDojoShape().moveToFront();                     } });  
0 Kudos
MihkelOviir
New Contributor
Quick question: Are the other lines on top of the selected line in the same FeatureLayer?

Yes, they are. I already thought, that if I do not get some reasonable solution, I add selected graphic to the map.graphics layer, and remove it on unselection.

get a handle to the esri.Graphic (the feature you have selected) and call
g.getDojoShape().moveToFront();



Almost nice. It did the trick, except if I zoom the map, layer content gets refreshed (ondemand mode), and selected feature seems to be first, that are drawn to the map, so all others are drawn over it. The way how ESRI JSAPI handles selected graphics is stupidity squared (imo).

I guess that I have two options here, I use other layer above to render selected graphics or use...
g.getDojoShape().moveToFront();

... everywhere if I have selection and layer content might change.

But thanks for help!
0 Kudos