[GIS] How to control the rendering priority/order of feature layers

arcgis-10.1arcgis-javascript-apiarcgis-serverfeature-layerrendering

I am displaying polygon, line and point feature layers on a button click event and adding layers in order based on their geometry type, e.g.: polygon -> line -> point.

In certain cases layers are rendered fine as we add them, but in some cases as the amount of data (and response time) increases in one of the layers, the polygon layer is rendered on top of the point and line layers and these layers get hidden.

We have already used reordering code but its not much of use. Are there any methods to control the rendering of layers or move layers one above the other?

I am using ArcGIS Server 10.1, feature service and the ArcGIS JavaScript API 3.1.

Best Answer

The Layer class has methods suspend() and resume(), so you could catch the onUpdateStart event to suspend all but the lowest layer from drawing. Then, in the onUpdateEnd event of the lowest layer you could call resume() for the next layer up, and so on.

Or if you're using FeatureLayers you could trigger each layer's refresh() method in order. Either way would probably be subject to random bugs.

Have you considered looking at the map services to see if any of them are slowing things down? Limiting the amount of data or implementing some kind of clustering might be better than trying to hack the layer refresh process.