# Load wms when the clock reaches a certain time

**URL:** <https://community.cesium.com/t/load-wms-when-the-clock-reaches-a-certain-time/10594>\
**Category:** CesiumJS\
**Created:** [August 15, 2020, 1:15pm UTC](https://community.cesium.com/t/load-wms-when-the-clock-reaches-a-certain-time/10594 "2020-08-15T13:15:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robin\_hong](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/robin_hong/32/2814_2.png) [@Robin\_hong](https://community.cesium.com/u/Robin_hong)\
**Post date:** [August 15, 2020, 1:15pm UTC](https://community.cesium.com/t/load-wms-when-the-clock-reaches-a-certain-time/10594/1 "2020-08-15T13:15:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [August 16, 2020, 1:05pm UTC](https://community.cesium.com/t/load-wms-when-the-clock-reaches-a-certain-time/10594/2 "2020-08-16T13:05:10Z")

</div>

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](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](https://sandcastle.cesium.com/index.html?src=Web%20Map%20Tile%20Service%20with%20Time.html)

---

<div class="post-metadata">

**Author:** ![Scott\_Reynolds](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/scott_reynolds/32/2014_2.png) [@Scott\_Reynolds](https://community.cesium.com/u/Scott_Reynolds)\
**Post date:** [August 16, 2020, 1:14pm UTC](https://community.cesium.com/t/load-wms-when-the-clock-reaches-a-certain-time/10594/3 "2020-08-16T13:14:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robin\_hong](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/robin_hong/32/2814_2.png) [@Robin\_hong](https://community.cesium.com/u/Robin_hong)\
**Post date:** [August 19, 2020, 8:56am UTC](https://community.cesium.com/t/load-wms-when-the-clock-reaches-a-certain-time/10594/4 "2020-08-19T08:56:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robin\_hong](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/robin_hong/32/2814_2.png) [@Robin\_hong](https://community.cesium.com/u/Robin_hong)\
**Post date:** [August 19, 2020, 9:02am UTC](https://community.cesium.com/t/load-wms-when-the-clock-reaches-a-certain-time/10594/5 "2020-08-19T09:02:08Z")

</div>

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.
