Commit 159e28db authored by Soeren Laursen's avatar Soeren Laursen

First commit - very nasty.

Lots of debug code.
parent 257844fa
L.TimeDimension.Layer.WMS.FCOO = L.TimeDimension.Layer.WMS.extend({
initialize: function(layer, options) {
L.TimeDimension.Layer.WMS.prototype.initialize.call(this, layer, options);
this._refTime = 0;
layer._tileCoordsToKey = function (coords) {
return coords.x + ':' + coords.y + ':' + coords.z + ':' + Math.random();
};
},
_getCapabilitiesUrl: function() {
var url = this._baseLayer.getURL();
if (this._baseLayer.wmsParams.layers) url += "?layers="+this._baseLayer.wmsParams.layers;
var params = L.extend({}, this._getCapabilitiesParams, {
'request': 'GetCapabilities',
'service': 'WMS',
'version': this._wmsVersion
});
url = url + L.Util.getParamString(params, url, params.uppercase);
return url;
},
_requestTimeDimensionFromCapabilities: function() {
if (this._capabilitiesRequested) {
return;
}
this._capabilitiesRequested = true;
var url = this._getCapabilitiesUrl();
//if (this._proxy) {
// url = this._proxy + '?url=' + encodeURIComponent(url);
// }
$.get(url, (function(data) {
this._defaultTime = 0;
this._refTime = this._getRefTimeFromCapabilities(data);
this._setDefaultTime = this._setDefaultTime || (this._timeDimension && this._timeDimension.getAvailableTimes().length == 0);
var timeString = this._parseTimesFromCapabilities(data);
console.log("slnslnslsn");
var timeperiods = timeString.split(',');
var times = [];
// for (var i = 0; i < timeperiods.length;i++) {
// var timeperiod = timeperiods[i].split('/');
timeperiods[0] = timeperiods[0]+ "Z";
timeperiods[timeperiods.length-1] = timeperiods[timeperiods.length-1] + "Z"
var startDate = moment(timeperiods[0], 'YYYY-MM-DDTHH:mm:SSZ');
var endDate = moment(timeperiods[timeperiods.length-1], 'YYYY-MM-DDTHH:mm:SSZ');
var hours = moment.duration(endDate.diff(startDate)).asHours()+1;
// var interval = moment.duration(timeperiod[2]).asHours();
//if (interval == 0) interval = 1;
interval= 1;
for (var j = 0; j < hours; j+=interval) {
var date = moment(startDate).add(j,"hours").valueOf();
times.push(date);
}
this.setAvailableTimes(times);
if (this._setDefaultTime && this._timeDimension) {
this._timeDimension.setCurrentTime(this._defaultTime);
}
if (times.length > 0) {
this.fire('metadataload');
}
}).bind(this));
},
setAvailableTimes: function(times) {
this._availableTimes = times;
this._updateTimeDimensionAvailableTimes();
},
// Player specific function: get available times to be used in player
getPlayerTimes: function() {
return this._availableTimes;
},
// Player specific function: should this layer available times be forced over other layers available times in player
forcePlayerTimes: function() {
return false;
},
_getRefTimeFromCapabilities: function(xml) {
var layers = $(xml).find('Layer[queryable="0"]');
var layers = $(xml).find('Layer');
var layerName = this._baseLayer.wmsParams.layers;
var layerNameElement = layers.find("Name").filter(function(index) {
return $(this).text() === layerName;
});
var refTime ='';
if (layerNameElement) {
var layer = layerNameElement.parent();
var dimension = layer.find("Dimension[name='reftime']");
if (dimension && dimension.length && dimension[0].textContent.length) {
refTime = dimension[0].textContent.trim();
} else {
var extent = layer.find("Extent[name='reftime']");
if (extent && extent.length && extent[0].textContent.length) {
refTime = extent[0].textContent.trim();
}
}
}
return refTime;
},
_parseTimesFromCapabilities: function(xml) {
var layers = $(xml).find('Layer[queryable="0"]');
var layers = $(xml).find('Layer');
console.log("sds" + layers );
var layerName= this._baseLayer.wmsParams.layers;
console.log("lllllll " + layerName);
var layerNameElement = layers.find("Name").filter(function(index) {
return $(this).text() === layerName;
});
var times = null;
if (layerNameElement) {
var layer = layerNameElement.parent();
times = this._getTimesFromLayerCapabilities(layer);
if (!times) {
times = this._getTimesFromLayerCapabilities(layer.parent());
}
}
console.log( times );
return times;
},
_getTimesFromLayerCapabilities: function(layer) {
var times = null;
console.log(layer);
var dimension = layer.find("Dimension[name='time']");
if (dimension && dimension.length && dimension[0].textContent.length) {
times = dimension[0].textContent.trim();
} else {
var extent = layer.find("Extent[name='time']");
if (extent && extent.length && extent[0].textContent.length) {
times = extent[0].textContent.trim();
}
}
return times;
},
_getLayerForTime: function(time) {
if (time == 0 || time == this._defaultTime || time == null || this._refTime == 0) {
return this._baseLayer;
}
if (this._layers.hasOwnProperty(time)) {
return this._layers[time];
}
var nearestTime = this._getNearestTime(time);
if (this._layers.hasOwnProperty(nearestTime)) {
return this._layers[nearestTime];
}
var wmsParams = this._baseLayer.options;
wmsParams.time = moment(nearestTime).utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
wmsParams.DIM_REFTIME = moment(this._refTime).utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
var newLayer = new this._baseLayer.constructor(this._baseLayer.getURL(), wmsParams);
this._layers[time] = newLayer;
newLayer.on('load', (function(layer, time) {
layer.setLoaded(true);
// this time entry should exists inside _layers
// but it might be deleted by cache management
if (!this._layers[time]) {
this._layers[time] = layer;
}
if (this._timeDimension && time == this._timeDimension.getCurrentTime() && !this._timeDimension.isLoading()) {
this._showLayer(layer, time);
}
// console.log('Loaded layer ' + layer.wmsParams.layers + ' with time: ' + new Date(time).toISOString());
this.fire('timeload', {
time: time
});
}).bind(this, newLayer, time));
// Hack to hide the layer when added to the map.
// It will be shown when timeload event is fired from the map (after all layers are loaded)
newLayer.onAdd = (function(map) {
Object.getPrototypeOf(this).onAdd.call(this, map);
this.hide();
}).bind(newLayer);
return newLayer;
},
});
L.timeDimension.layer.wms.FCOO = function(layer, options) {
return new L.TimeDimension.Layer.WMS.FCOO(layer, options);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment