socib / Leaflet.TimeDimension

Add time dimension capabilities on a Leaflet map.
MIT License
433 stars 138 forks source link

Time Control doesn't sync when switching layers #204

Closed robertdcurrier closed 3 years ago

robertdcurrier commented 3 years ago

I have a set of four layers using Time Controls. They are defined as follows: var rs_CI_TimeLayer = L.timeDimension.layer.wms(rs_CI, { updateTimeDimension: true, requestTimeFromCapabilities: true }); var rs_turbidity_TimeLayer = L.timeDimension.layer.wms(rs_turbidity, { updateTimeDimension: true, requestTimeFromCapabilities: true });

I have an extensive layers menu that allows users to select different models and remote sensing images. The layers are controlled via radio buttons as such: // RS CI $("#rs-ci" ).click(function() { clearLayers(); rs_CI_TimeLayer.addTo(haloMap); $(".leaflet-control-timecontrol").show(); // Get rs-turbidity legend; var new_img = ''; $('#wmsLegend').html(new_img); $('#wmsLegend').show(); })

// ROMS CHL-A $("#roms-chl" ).click(function() { clearLayers(); console.log('ROMS CHL-A') roms_CHL_TimeLayer.addTo(haloMap); $(".leaflet-control-timecontrol").show(); // Get roms_chl legend; var new_img = ''; $('#wmsLegend').html(new_img); $('#wmsLegend').show(); })

My problem is that on first click, everything loads fine. But when I cycle between, say, ROMS-CHL and RS-CI nothing happens unless I click RS-CI again. Then, and only then, does the time slider synch with the new dates from ncWMS. This is consistent and always requires two clicks. I tried defining the layers in a Leaflet layer control but had the exact same results. Two click were always required. I've tried adding callbacks and other means of waiting but still no joy. Any thoughts?

robertdcurrier commented 3 years ago

Fixed the problem. The setting for the updateDimensionMode needed to be changed from the default to this: var rs_turbidity_TimeLayer = L.timeDimension.layer.wms(rs_turbidity, { updateTimeDimension: true, requestTimeFromCapabilities: true, updateTimeDimensionMode: "replace". <---- THIS WAS THE KEY });
Now everything works correctly.