0

I have created a map that has a Table of Content that i use to turn on and off desired layers. Is there a way to create a 'Clear' button that will untoggle the selected layers? I have a clear button that clears other selections but I am stuck. I am using ArcGIS API for JavaScript 3.17.

    var myLayerList = new LayerList({
        map: map,
        showLegend: false,
        layers: [
        waterFeature,
        volleyball,
        trashcan,
        tennis,
        table,
        soccerField,
        shadeStructure,
        restroom,
        ramada,
        pool,
        playground,
        pathway,
        parkSign,
        parking,
        park,
        light,
        horseShoe,
        grill,
        drinkingFountain,
        dogPark,
        dogBag,
        discGolf,
        communityGarden,
        bikeRack,
        benches,
        battingCages,
        basketball,
        ballfield]
    }, "layerList");
    myLayerList.startup();




       query("#clearQuery").on('click', function (evt) {
           //reset the definition expression
           selectedLayer.setDefinitionExpression('1=1');
           map.graphics.clear();



       });
  • I've tried using 'if' statements but im still new to coding and wasn't sure on how to go about it. I was hope there was an example on the developers.arcgis.com website but i could not find anything. – Chris Lai Jul 22 '16 at 0:58
  • 2
    please edit your question to include a snippet of the code you've tried, and what happens when you try it (any errors) – Midavalo Jul 22 '16 at 1:14
1

This link provides some good sources to get you started:

https://developers.arcgis.com/javascript/3/jssamples/map_explicitlayerlist.html

Dynamically create a list of all the loaded layers referencing this code snippet

https://developers.arcgis.com/javascript/3/jssamples/map_dynamiclayerlist.html

You may then tie the updateLayerVisibilty() method from a button click event to loop through the layer list and turn each off.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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