Open JackLidge opened 4 years ago
_requestTimeDimensionFromCapabilities
is asynchronous. You cannot get the times just after.
If you want, you can register for time changes events :
dLayer._requestTimeDimensionFromCapabilities();
timedimension.on('availabletimeschanged', (e)->{console.log(e)})
This only works if your layer has option updateTimeDimension
set to true
If you want to build your own player component, I suggest you to check Player Control code
I'm more interested in just getting a list of times from the WMS GetCapabilities doc than building a player component in at the moment. I did think it might be an asynchronous function which would explain the _availableTimes array not being maintained outside the function (although after calling _requestTimeDimensionFromCapabilities I can see the filled _availableTimes values, I just can't get them out into a variable).
Is the timedimension
you mentioned above invoked by calling L.timeDimension.on()
or is it applied directly to the time dimension layer? (In my example at the top tdLayer).
you need to get a reference to your timedimension instance. Either you create it yourself :
var timedimension = L.timeDimension({/*options*/});
timedimension.addTo(map);
// works with `timeDimension:false` in your map options
OR you use the one auto created with timeDimension:true
map.timeDimension.on('availabletimeschanged', function(event) {})
Thanks for the advice. I'm looking into it now, but I can't work out exaclty which bit of code is needed to update the displayed layer with its new time value?
I'm trying to take some of the functionality defined within the TimeDimension module to do my own time selection code in Leaflet. I've been looking through the source code, and if I run the following in a console on a map which is already initialised:
Then times is an array of data objects, taken from the time values in the WMS Capabilities layer. However, if I try to put this into a function to do this inside my javascript file for initialising the Leaflet site, like so:
This returns the default value for _availableTimes on initialisation of
[]
instead of a filled array of date objects. Checking this with console logging, it seems that tdLayer has been updated to show all of the times and _availableTimes in the layer is filled, but it is impossible to get _availableTimes out of the layer as a method.Is there something I'm missing here about getting the _availableTimes array out?