socib / Leaflet.TimeDimension

Add time dimension capabilities on a Leaflet map.
MIT License
435 stars 139 forks source link

Leaflet.TimeDimension requests the same WMS layer multiple times from GeoServer #136

Open grassland-curing-cfa opened 6 years ago

grassland-curing-cfa commented 6 years ago

Thanks for creating this beautiful plugin to allow time-enabled WMS layers.

I have been testing and trialling the plugin with showing a few NetCDF files (in hourly interval) that were published to GeoServer with Time enabled.

var idv71122_vic_gfdi_wms_layer = L.tileLayer.wms(wmsUrl, {
    layers: 'fdi:IDV71122_VIC_GFDI_SFC',
    format: 'image/png',
    transparent: true,
    crs: L.CRS.EPSG4326,
    attribution: 'CFA | IDV71122_VIC_GFDI_SFC'
});

var idv71122_vic_gfdi_td_layer = L.timeDimension.layer.wms(idv71122_vic_gfdi_wms_layer, {
    updateTimeDimension: true,
    updateTimeDimensionMode: "replace"
});

L.control.layers({}, {"GFDI hourly": idv71122_vic_gfdi_td_layer}).addTo(map);

The layer was added to the map perfectly and the plugin worked beautifully. This was the only layer added to the base map (L.TileLayer type). What I have found interesting (and confusing) to me is it seems the plugin requested the same layer on GeoServer multiple times with different "time" params and the images were completely overlapping. I was trying to console.log all the layers of the L.TileLayers.WMS type on the map.

var layers = [];
map.eachLayer(function(layer) {
    if( layer instanceof L.TileLayer.WMS ) {
        layers.push(layer);
        console.log(layer);
    }
});
console.log(layers.length);

What was printed out on the browser's console was:

Object { _url: "../../geoserver/wms", options: {…}, wmsParams: {…}, _initHooksCalled: true, _events: {…}, onAdd: bound (), _leaflet_id: 375, _mapToAdd: {…}, _map: {…}, _zoomAnimated: true, … }

Object { _url: "../../geoserver/wms", options: {…}, wmsParams: {…}, _initHooksCalled: true, _events: {…}, onAdd: bound (), _leaflet_id: 432, _mapToAdd: {…}, _map: {…}, _zoomAnimated: true, … }

2

The two Objects actually have different "time" params which just have one hour in difference.

Is this how the plugin was designed?

jimjam-slam commented 6 years ago

I'm not the package author, but isn't this exactly what you would want for a plugin designed to show different time slices of the same layer? Each time slice for your layer is really a separate Leaflet layer underneath with a separate series requests to Geoserver (or whatever WMS provider); the plugin helps coordinate them so that it looks like a single layer to the user.