socib / Leaflet.TimeDimension

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

Call player functions from outside using WMS tiles #200

Closed julste closed 3 years ago

julste commented 3 years ago

Hi there, I'm using a WMS tile layer and added it to my map like this:

var map = L.map('map',{
    minZoom: 5,
    maxZoom: 8,
    timeDimension: true,
    timeDimensionOptions:{
        timeInterval: "PT2H/" + fDate.toISOString(),
        period: "PT5M",
        currentTime: fDate
    },
    timeDimensionControl: false,
    timeDimensionControlOptions: {
        autoPlay: false,
        playerOptions: {
            buffer: 10,
            transitionTime: 500,
            loop: true,
        }
  },

var radarWMS = L.tileLayer.wms('url', {
    layers: "name",
    transparent: true,
    format: "image/png",
    opacity: 1,
    zIndex:2
});

var testTimeLayer = L.timeDimension.layer.wms(radarWMS, {
    updateTimeDimension: false,
    wmsVersion: '1.3.0',
    cache: 24,
});

testTimeLayer.addTo(map);

Then added also a custom player like this: var player = new L.TimeDimension.Player({}, map.timeDimension);

Unfortunately it is not possible to call the start, stop functions from the player object: player.start()

Using a custom time dimension instead works well:

var timeDimensionControl = new L.Control.TimeDimensionCustom({
  autoPlay: false,
  playerOptions: {
      buffer: 100,
      transitionTime: 500,
      loop: true,
  }
});
map.addControl(this.timeDimensionControl);

My question is: Is it possible to call the player functions from outside using a WMS tile layer?

Thanks in advance!

r1m commented 3 years ago

You need to add the player to your control.

var timeDimensionControl = new L.Control.TimeDimensionCustom({
  autoPlay: false,
  player: player
});
julste commented 3 years ago

Thanks for the fast reply!

It works now :)

But how can I hide the player control then?

julste commented 3 years ago

Never mind, I had just to comment out the timeDimensionControl.

Thank you very much