add a new selection as the upper layer

473
1
06-27-2017 07:33 PM
SaraEL_MALKI
Occasional Contributor II

Hi everyone,

When I create a new selection in a layer, I notice that that selection can be covered by other layers if my layer wasn't the upper one, I wanna make that layer the upper one when an element of it is selected, How can that be achieved ?

myFeatureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW);

Robert Scheitlin, GISP‌ Rebecca Strauch, GISP TSolow-esristaff

0 Kudos
1 Reply
ThomasSolow
Occasional Contributor III

I think you could manually move the layer around so that it's the last layer.  Another option would be to set the opacity of all other layers to something like .5 so you can ensure that you can see through them at least.

Here's how you might approach the first option:

var map;
var myFeatureLayer;
var query;

myFeatureLayer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(event){
  if (event.features.length>0){
    map.reorderLayer(myFeatureLayer, map.layerIds.length - 1);
  }
});

When the features are deselected you may want to change the order of this layer back to where it was previously.