AnsweredAssumed Answered

Having Issue on Adding/Removing Service Layer by Checkbox

Question asked by BEHSEINI on Oct 23, 2015
Latest reply on Oct 23, 2015 by rscheitlin

Can you please take a look at this code and let me know how I can add and remove some layers based on their index number in a Map Service? I tried this before but it is not working!

 

Layer 52 : <input type="checkbox" value=52 name="overlayLayers"><br  />
Layer 53 : <input type="checkbox" value=53 name="overlayLayers"><br  />

 

   var service ="http://renewablestoolbox.biol.sfu.ca/rorapp/rest/services//RORApp/MapServer";
   
    $('input:checkbox[name=overlayLayers]').on('change', function(){
    if($(this).is(':checked')){
        var index = $(this).val();
        map.addLayer(service+index);
    }
    else{
        var index = $(this).val();
        map.removeLayer(service+index);
        }
});

Outcomes