How to switch layers[] in esri leaflet dynamiclayer

438 views Asked by At

I have a single MapService with multiple layers. I'd like to utilize layer group for changing layers with radio buttons, but want to use it with the layers[] array option rather that creating a single L.esri.dynamicMapLayer etc... for each layer.

Here is a sample snippet:

  var msndfd = "https://nowcoast.noaa.gov/arcgis/rest/services/nowcoast/forecast_meteoceanhydro_sfc_ndfd_time/MapServer";

            var minTemp = L.esri.dynamicMapLayer({
                url: msndfd,
                layers: [8],
                opacity: .7
            });

How do we switch layers based on that layers array # such as [4,8,12,16] while using the L.control.layers(baseMaps, overlayMaps)? So each of the overlayMaps would essentially be a layer# not another dynamicMapLayer variable such as minTemp in my example above.

1

There are 1 answers

0
john gravois On

the way Leaflet's layers control is currently written is to add/remove layers from the map in reaction to user interaction with the checkboxes and radio buttons.

if you'd like to organize things so that choosing a different radio ensures that L.esri.dynamicMapLayer.setLayers() is called instead, you'd have to customize the control to lay out its UI differently (referencing a single base layer and an array of sublayers to toggle) and ensure that the appropriate action occurs when a new radio is selected.

existing logic for laying out the list - Control.Layers.js#L313-L322

existing logic for responding to user interaction - Control.Layers.js#L382-L387

my gut reaction is that you'd probably be better off accepting how the control is already designed, but i'm sure you have your reasons.