I am using version 3.12 of the ESRI ArcGIS Javascript API and have noticed that the order of the features that show up in my info window popup does not correspond to the order layers those features are in. I want to be able to specify that all of the features from the same layer appear next to each other as I toggle though the selected features.
For example, say I have a map with two feature layers in the following order: 1. tax_parcels and 2. county_border. If I click on a spot within county_border where tax_parcels has overlapping features, I would expect my info window popup to show info for parcel1. When I click the next arrow I expect to see info for parcel2 and info for the county when I click next again. In my actual map in some cases I am seeing parcel1 followed by county followed by parcel2.
I found this thread: https://geonet.esri.com/thread/169793 but it did not provide any solutions. Does anyone know of a way to do this?
Answer
Re-order the features when the Popup's on-set-features event fires.
Here is a code snippet of how to do this:
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[i]._layer.id === 'ImportantLayer') {
orderedFeatures.unshift(map.infoWindow.features[i]);
}
else {
orderedFeatures.push(map.infoWindow.features[i]);
}
}
map.infoWindow.features = orderedFeatures;
});
});
}
No comments:
Post a Comment