Load wms when the clock reaches a certain time

Hi ,
I want to load a wms when the clock reaches acertain time . In order to come true Timing visualization of images.
Below is my code,but it could not load.

 var viewer = new Cesium.Viewer('cesiumContainer');

    var start = Cesium.JulianDate.fromIso8601('2015-08-01T16:00:00Z');

    var end = Cesium.JulianDate.fromIso8601('2015-08-02T16:00:00Z');

    var time_1 = Cesium.JulianDate.fromIso8601('2015-08-01T17:00:00Z');

    var clock = viewer.clock;

    viewer.timeline.zoomTo(start, end);

    clock.startTime = start;

    clock.endTime = end;

    clock.currentTime = start;

    clock.clockRange = Cesium.ClockRange.CLAMPED; 
    clock.multiplier = 900;

var provider_1 = new Cesium.WebMapServiceImageryProvider({

        url: 'http://localhost:8080/geoserver/nurc/wms', 

        layers: 'nurc:Img_Sample', 

        parameters: {

            service: 'WMS',

            format: 'image/png',

            transparent: true,
        }
    })

var myListener = function (clock) {

         if (clock.currentTime.equals('2015-08-01T18:00:00Z')) {

             viewer.imageryLayers.addImageryProvider(provider_1);

        }

     }

     viewer.clock.onTick.addEventListener(myListener);

It not work,i don’t know why.Or you have other ways to realize the image changes as time goes on
Thanks in advance.

One issue could be that equals must take a JulianDate, not a string, see: https://cesium.com/docs/cesiumjs-ref-doc/JulianDate.html?classFilter=Julia#equals.

Is this the kind of effect you’re looking for? https://sandcastle.cesium.com/index.html?src=Web%20Map%20Tile%20Service%20with%20Time.html

And since equality is unlikely you might need something like this:

var layerAdded = false;
var targetTime = Cesium.JulianDate.fromIso8601('2015-08-01T18:00:00Z');

var myListener = function (clock) {
    if (Cesium.JulianDate.greaterThanOrEquals(clock.currentTime, targetTime) && !layerAdded) {
        console.log(viewer.clock.currentTime);
        viewer.imageryLayers.addImageryProvider(provider_1);
        layerAdded = true;
    }
};

Moving backward in time could be another issue to consider.

Scott

1 Like

Thanks omar,
this sandcastle is almost what I want, but there is a difference.This gave me a lot of inspiration.

Thanks Scott,
With your help, my work could load now.
And as you said,moving backward in time could be another issue to consider. Next, I will consider this issue.