If you're looking to turn off a single layer within the map service, take a look at nliu's Table of Contents(TOC)/Legend Widget.
thanks guys for the answer.
I saw these examples but I'm trying to create a layer list for mobile with jquery mobile and using these examples is changed the style of my check box. I'm a flex developer and i'm new of javascript world.
Is there any example for layer list in mobile device?
Thanks
- Create a list of layers with HTML.
- For each layer there should be a checkbox (input element) and an associated label
- Add a data-layerid attribute to the checkbox with the id of the associated layer. (You can call this attribute whatever you want as long as it starts with data-)
- Create a single event handler function for the checkboxes' click events. This function will do the following:
- Get the layer ID from the data-layerid attribute of the checkbox that was clicked. (The specific checkbox can be accessed in the function via the this keyword.)
- Retrieve the associated layer from the map using the layer id.
- Either show or hide the layer, depending on if the checkbox is checked or not.
- Add the event handler to the checkboxes.
- If you don't have to worry about supporting old versions of IE, use addEventListener
- If you need to support old versions of IE, use jQuery's event handling code (i think it's called .click())
Thanks Jeff i try it.
if (!featureLayerB) { }
featureLayerB.show(), else
featureLayerB.hide()