Cesium 案例(二)Web MapTile Service with Time

发布时间 2023-04-05 19:07:54作者: gis_BlackCaat
使用官方github包,部分解释来源于http://cesium.xin/cesium/cn/Documentation1.95/index.html
 

 

Cesium.Ion.defaultAccessToken =token;
      constviewer = newCesium.Viewer("cesiumContainer", {
        shouldAnimate: true,
        //时钟应该默认尝试提前模拟时间,则为 true,否则为 false 。
      });
      functiondataCallback(interval, index) {
        lettime;
        if (index === 0) {
          time = Cesium.JulianDate.toIso8601(interval.stop);
          // JulianDate 表示天文儒略日期
          //  toIso 创建所提供日期的 ISO8601 表示。
        } else {
          time = Cesium.JulianDate.toIso8601(interval.start);
        }
        return {
          Time: time,
        };
      }
      consttimes = Cesium.TimeIntervalCollection.fromIso8601({
        //从 ISO 8601 时间间隔(开始/结束/持续时间)创建一个新实例
        iso8601: "2015-07-30/2017-06-16/P1D",
        //  ISO 8601 间隔。
        leadingInterval: true,
        // isStartIncluded:true,
        // true 开始时间包含在间隔中
        trailingInterval: true,
        //要添加从停止时间到 Iso8601.MAXIMUM_VALUE 的间隔,
        //则为 true,否则为 false 。
        isStopIncluded: false,
        //true 结束时间包含在间隔中
        dataCallback: dataCallback,
      });
      constprovider = newCesium.WebMapTileServiceImageryProvider({
        //提供由 Web 地图服务 (WMS) 服务器托管的平铺图像。
        url: "https://gibs.earthdata.nasa.gov/wmts/epsg4326/best
/MODIS_Terra_CorrectedReflectance_TrueColor/default/{Time}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.jpg",
        layer: "MODIS_Terra_CorrectedReflectance_TrueColor",
        //  要包含的层,用逗号分隔。
        style: "default",
        tileMatrixSetID: "250m",
        maximumLevel: 5,
        //图像提供者支持的最大细节级别,
        //如果没有限制,则未定义。如果未指定,则没有限制。
        format: "image/jpeg",
        clock:viewer.clock,
        //在确定时间维度的值时使用的 Clock 实例。指定 `times` 时需要
        times: times,
        //  TimeIntervalCollection
        //及其数据属性是一个包含时间动态维度及其值的对象。
        credit: "NASA Global Imagery Browse Services for EOSDIS",
      });
      constlayer = newCesium.ImageryLayer(provider);
      //一个图像层,它在 Globe 上显示来自单个图像提供者的平铺图像数据
      layer.alpha = 0.5; //透明度
      viewer.imageryLayers.add(layer);

      conststart = Cesium.JulianDate.fromIso8601("2015-07-30");
      conststop = Cesium.JulianDate.fromIso8601("2017-06-17");
      viewer.timeline.zoomTo(start, stop);
      //将视图设置为提供的时间。
      constclock =viewer.clock; //获取时钟
      clock.startTime = start;
      clock.stopTime = stop;
      clock.currentTime = start; //当前时间
      clock.clockRange = Cesium.ClockRange.LOOP_STOP;
      //确定达到 Clock#startTime 或 Clock#stopTime 时时钟的行为方式
      //unbounded不变方向 单向流逝
      //clamped  到地方就停止(start or stop/time)
      //loop_stop循环
      clock.multiplier = 7200;//默认倍率
      //确定调用 Clock#tick 时提前多少时间,负值允许向后推进。
 
 
运行结果图