Select to view content in your preferred language

Can the features in the 3.x Popup window be sorted?

741
5
Jump to solution
01-11-2018 01:53 PM
DavidFriedrich
Occasional Contributor

If we have a feature class where multiple features overlap each over, is there anyway to sort the features shown in the infowindow popup?

For example, if we have multiple point features representing different 3-1-1 calls that overlap each other on the map, is there anyway to enforce an ordering so that when the map is clicked, the newest feature, based on a timestamp column, is shown first ? So that the newest record is 1 of X, the second oldest is 2 of X etc.

It seems that the ordering of item in the popup window is random.

I tried adding code to the "set-features" event handler to sort the features, but this did not make any differenct 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DavidFriedrich
Occasional Contributor

That seems to work, thank you Robert!

One more thing that seemed to be necessary - I had to override the "show" method and change the "closestFirst" parameter to false. 

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

David

I tried adding code to the "set-features" event handler to sort the features, but this did not make any difference

What exactly did you try, because this is the only way to manage the order is to set the order of the setFeatures array?

0 Kudos
DavidFriedrich
Occasional Contributor

Hi Robert,

in the "set-features" event-handler, I added some code like this:

var data = _map.infoWindow.features;
if (data && data.length > 0) {
   data.sort(function (a, b) {
      if (a.LayerSortKey && b.LayerSortKey) {
         if (a.LayerSortKey > b.LayerSortKey) {
            return 1;
         }   
         if (a.LayerSortKey < b.LayerSortKey) {
            return -1;
         }
      }
      return 0;
   });
   data.reverse();
}

(LayerSortKey is an attribute I have on the feature class that I wish to use for sorting)

It seems to sort the array of _map.infoWindow.features, but the order that they appear in the popup seems to be random

RobertScheitlin__GISP
MVP Emeritus

David,

   You are sorting the array after the fact. You need to override the setFeatures method and sort the array before the setFeatures method applies the array.

DavidFriedrich
Occasional Contributor

That seems to work, thank you Robert!

One more thing that seemed to be necessary - I had to override the "show" method and change the "closestFirst" parameter to false. 

RobertScheitlin__GISP
MVP Emeritus

David,

   The community would definitely benefit if you would post the code you end up using.