socib / Leaflet.TimeDimension

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

Set Current time is not working in initial state #231

Closed abhishek73magar closed 1 month ago

abhishek73magar commented 2 months ago

set current time is not working. in initial state if any one resolve this issue please let me know and help me.

if(!map.timeDimension){
      // set timedimension layers
      const dimensionOptions = {
        currentTime: new Date(forecastDate[activeIndx]).getTime(),
        cache: true
      }
      const period = getPeriod(forecastDate[0], forecastDate[1])
      if(!useCapabilites) { 
        Object.assign(dimensionOptions, { period, timeInterval: `${forecastDate[0]}/${forecastDate[maxRange]}` }) 
      } 
      console.log(dimensionOptions, activeIndx)
      map.timeDimension = new L.timeDimension(dimensionOptions)
      console.log(map.timeDimension)
      // map.timeDimension.setCurrentTimeIndex(activeIndx)
      // map.timeDimension.setAvailableTimes(forecastDate.join(","), period)

      if(!map.timeDimension.player){
        map.timeDimension.player = new  L.TimeDimension.Player({
          buffer: 10,
          transitionTime: 500, // ms
          loop: true,
          startOver: true,
        }, map.timeDimension)
      }
    }  
    const wmsOptions = {
      ...wmsConfig,
      format: "image/png",
      transparent: true,
      time: '',
      opacity: opacity,

    };

    if(wmsLayerRef.current) map.removeLayer(wmsLayerRef.current);
    const wmsLayer = L.tileLayer.wms(`${GEO_SERVER}${url}`, wmsOptions).setZIndex(10);
    wmsLayerRef.current =  new L.timeDimension.layer.wms(wmsLayer, { 
      updateTimeDimension: true,
      requestTimeFromCapabilities: useCapabilites,
      setDefaultTime: true,
      cache: 10, // Eable caching with a limit of 10 tiles
    });

    map.addLayer(wmsLayerRef.current);

except this like set index or current time using buttons are working