0

I have a map with around 20 WMS layers but I want the person exploring the map to only be able to have 3 layers active at a time. For my layer control I am using Styled Layer Control. What is the best way to do this?

  • 2
    Set a layerLimit variable to 3 - limit to how many layers can be turned on. 1) When the user toggles layer control, check to see how many layers are currently on. 2) if layers on is less than the layerLimit add it. 3) if layers on is >= layerLimit , notify the user only 3 can be turned on at a time. I will be a greater help if you provide a code example showing how you are attempting to solve this problem. – Owen J Lamb Feb 2 '17 at 16:51
  • If the WMS service belongs to you, you may be able to set a layer limit in the WMS (it's part of the WMS spec, but not sure if it is configurable in all software) – nmtoken Dec 5 '17 at 7:42
1

Possible implementation :

$('body').on('click', 'input.leaflet-control-layers-selector:checkbox', function (e){
    if (! $(this).is(':checked')){
        if ($('input.leaflet-control-layers-selector:checkbox:checked').length >= 3)){
            e.preventDefault();
            alert('no more than 3');
        }
    }
});
|improve this answer|||||

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.