Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

How to toggle the visibility of features in a feature-layer using check-boxes .I have grid containing check-boxes in a columns representing each feature in Feature-layer and so if I check off the check-box i can turn off the visibility and if i check in turn on the visibility using ArcGIS JavaScript API 3.1.Thank you in advance.

share|improve this question
    
Are you using a feature service with a renderer or a map service? –  blord-castillo Sep 12 '12 at 13:15
    
Feature service @ blord-castillo –  Gunner Sep 12 '12 at 15:09

2 Answers 2

up vote 2 down vote accepted

Use Selection mode for the feature layer. Set your symbol using Layer.setSelectionSymbol(symbol). If you have a complex symbology, set the renderer instead and leave the selection symbol blank.

There are two ways to go about the next part.

Method one:

Use the checkboxes to composite a complex query. For example, if each feature has a unique identifier (call it IID), then you query will be:

IID IN (<List of IDs>)

Where the list of IDs is built from all the checked check boxes. jQuery can be very effective in building this list. Whenever a checkbox is updated, you want to execute

Layer.selectFeatures(IID IN (<List of IDs>),esri.layers.FeatureLayer.SELECTION_NEW)

Method two:

Use simple queries to add and remove each feature individually as boxes are checked or unchecked. When a checkbox is checked, you use:

Layer.selectFeatures(IID = '<UniqueID>',esri.layers.FeatureLayer.SELECTION_ADD)

When a checkbox is unchecked, you use:

Layer.selectFeatures(IID = '<UniqueID>',esri.layers.FeatureLayer.SELECTION_SUBTRACT)

As you add features to the current selection (or create a new selection) those features will be displayed. As you remove them, they will be hidden. Since selectFeatures() will execute client side if possible, this actually operates very quickly.

share|improve this answer

Try this sample from ESRI. It sounds like exactly what you are asking for.

share|improve this answer
    
It is switching visibility of entire layer.I want to switch on and off visibility of features in feature Layer.Thanks @Craig –  Gunner Oct 15 '12 at 7:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.