Select to view content in your preferred language

What determines the order of popups?

4623
5
12-14-2015 02:38 PM
TracySchloss
Honored Contributor

I have several overlapping polygon layers on my map, each with their own popup template.   I have a popup defined on my map as

  var popup = new Popup({

    markerSymbol: mySymbols.highlightSymbol(),

    fillSymbol: mySymbols.highlightFillSymbol()},

    domConstruct.create("div"));

   map = new Map("mapDiv", {

    infoWindow: popup,

    basemap: "gray",

    center: [-91, 38.2],

    zoom: 7

   });

When these appear on map click, I get all the selected features, but not always in the same order.  I would have thought they would appear from either top to bottom or vice versa in their drawing order.

Why is this and can I change it?

Tags (1)
5 Replies
RobertScheitlin__GISP
MVP Emeritus

Tracy,

   My assumption is that the map click is doing some deffereds and that depending on the map services load at that exact second would make the difference as to which gets returned in what order.

0 Kudos
ChristopherEby
Deactivated User

I have this same problem and I need to enforce the order that the features appear in my info window popup. Is there anyway to do this? Robert Scheitlin, GISP​, do you have any suggestions?

0 Kudos
TracySchloss
Honored Contributor

I never got a resolution myself.  I didn't attempt this idea, but I wonder if there would be a way to capture the information before it was displayed, reorder the sequence and then display.   I'm not sure what events you'd even be listening for. 

ChristopherEby
Deactivated User

Good idea. I did some research and the onSetFeatures event looked like it might do what I needed. Here's a snippet of code that I used to re-order my features:

function bindInfoWindowSortingFunction(map) {
     require(['dojo/_base/connect'], function (connect) {
        connect.connect(map.infoWindow, "onSetFeatures", function () {
            var orderedFeatures = [];
            for(var i = 0; i< map.infoWindow.features.length; i++) {
                if (map.infoWindow.features._layer.id === 'ImportantLayer') {
                    orderedFeatures.unshift(map.infoWindow.features);
                }
                else {
                    orderedFeatures.push(map.infoWindow.features);
                }
            }
            map.infoWindow.features = orderedFeatures;
        });
    });
}
TracySchloss
Honored Contributor

I'm glad that was enough of a suggestion to work with.  I finished the project I needed this for, leaving it as-is.  I'll have to dig back into that code and see if I can add this.  I didn't have just one layer that was important, I wanted the information from the layers to appear consistently, basically in the same order I had added them to the map.  The concept should still work, though, with modification to your code.