Wednesday, April 24, 2013

Sublayers with ArcGIS Online webmap and Javascript API

ArcGIS Online ( does a nice job of providing front ends for your web mapping services (particularly of the ArcGIS Server variety).  In fact, ArcGIS Server 10.1 no longer comes with out of the box web mapping applications, relying instead on deployment through provides a couple templates, for different use cases, that you can download and modify (though the performance hit of having the middleman is a concern).

One of the stumbling blocks I've identified in this new model is that -- and by extension ArcGIS Server -- does not provide any templates to allow the end user to control sublayer visibility.  Thus, in migrating from ArcGIS Server pre-10.1 you may find that the sublayer control that was previously available by default  through the out-of-the-box .NET (Java?) web applications is missing ... halting your entire migration.

After contacting Esri, I found it was necessary to code a custom solution.  

Here is a modified Basic Viewer web template, which supports sublayers, through the layers checkbox widget (dojo dijit):

You'll need to add your webmap ID to that code, for it to function.

Or if you'd like to patch it yourself, apply this patch to /javascript/layout.js:

Note that this code will probably break if your map contains multiple map services with sublayers.

No comments: