Count-dependent rendering? Switch layer on/off depending on number of features

621
1
02-10-2011 07:49 PM
StephenLead
Regular Contributor III
I have a set of multiple census layers, where the largest scale layer is very detailed over heavily populated areas, and quite coarse over remote areas.

I need to display the detailed layer when it makes sense to do so - which is not necessarily at the same scale across the entire map.

These screenshots illustrate the problem. At a scale of 1:500k the layer should display in rural areas:



But in urban areas, the layer shouldn't display until about 1:100k:



Using the JavaScript API and REST layers, is there any way to count the features in the current map extent, and turn the layer off/on accordinly? Eg, if there are fewer than 50 polygons, show the detailed layer, otherwise show the coarse layer.

Thanks,
Steve
0 Kudos
1 Reply
HemingZhu
Occasional Contributor III
I have a set of multiple census layers, where the largest scale layer is very detailed over heavily populated areas, and quite coarse over remote areas.

I need to display the detailed layer when it makes sense to do so - which is not necessarily at the same scale across the entire map.

These screenshots illustrate the problem. At a scale of 1:500k the layer should display in rural areas:



But in urban areas, the layer shouldn't display until about 1:100k:



Using the JavaScript API and REST layers, is there any way to count the features in the current map extent, and turn the layer off/on accordinly? Eg, if there are fewer than 50 polygons, show the detailed layer, otherwise show the coarse layer.

Thanks,
Steve


Do a spatial query against your polygon layer using the current extent as query.geometry and then query.executeForCount(query, callback?, errback?) to get the count of the polygon.
0 Kudos