How can I change the order of the layers information displayed in the popup window?. I have the popup window enabled in two layers, but I need one of them specifically to be shown first. How can I do that?, where in the code I need to change that?

3490
6
Jump to solution
07-09-2015 06:51 AM
MaribelValderrama
New Contributor

How can I change the order of the layers information displayed in the popup window?. I have the popup window enabled in two layers,
but I need one of them specifically to be shown first. How can I do that?, where in the code I need to change that?

Thanks,

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Maribel,

   Then currently there is no way to configure the popups order.

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

Maribel,

   Does changing the layer order in the webmap not help this?

0 Kudos
MaribelValderrama
New Contributor

No, I tried that but it didn't changed the order in the popup window.

Thanks,

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Maribel,

   Then currently there is no way to configure the popups order.

MaribelValderrama
New Contributor

Thanks Robert.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Maribel,

Glad to help. Now it is your turn to help the community by marking this question as answered. All you have to do is click the "Correct Answer" link (the one with the little green star) on the post that provided the answer for you. If the answer was not provided by one of the responders then you can mark any of the replies that you received as helpful by clicking on the "Actions" menu and choosing "Mark as Helpful"

0 Kudos
LarryStout
Occasional Contributor III

Maribel,

It is possible and I have done it.  Here is a snippet of code that I use:

var layerOrder = ['layer1', 'layer2', 'layer3'];
if (layerOrder && layerOrder.length) {
  var ignore = false;
  on(this.map.infoWindow, 'dfd-complete', function(evt) {
    // The dfd-complete event is undocumented and may not work in future versions.
    if (evt.target.count > 1) {
      evt.target.setContent('');
    }
  });
  on(this.map.infoWindow, 'set-features', function(evt) {
    if (ignore || evt.target.count < 2) { 
      return; 
    }
    
    var features = evt.target.features;
    var layerNames = [];
    var newLayerIndexes;
    var index;
    var newFeatures = [];
    array.forEach(features, function(feature) {
      layerNames.push(feature.getLayer().name);
    });
   
    newLayerIndexes = Array(layerNames.length);
    array.forEach(layerNames, function(layerName, idx) {
      index = array.indexOf(layerOrder, layerName);
      if (index === -1) {
        newLayerIndexes.push(idx);
      } else {
        // In the case of multiple features from the same layer
        while (newLayerIndexes[index] !== undefined) {
          index++;
        }
        newLayerIndexes[index] = idx;  
      }
    });


    array.forEach(newLayerIndexes, function(index) {
      if (index !== undefined) {
        newFeatures.push(features[index]);
      }
    });
    
    ignore = true;
    evt.target.setFeatures(newFeatures);
    evt.target.show();
    ignore = false;
  });
}










This code should go into a "headless" widget (like my Anvil Widget).  You can see it in action here: Hamilton County Map Viewer​.  My layerOrder is:

[
  "Cemetery", 
  "School", 
  "Railroads", 
  "Interstates and US Highways", 
  "State Highways", 
  "Major Roads", 
  "Minor Roads", 
  "Parcels", 
  "Subdivision", 
  "Corporate Limits", 
  "Political Township"
]


When I have some time, I'll put this into another variation of the Anvil Widget.

Larry