Commit fe60e011 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

removed unused files

parent f1b50c38
L.TimeDimension.Layer.Weather = L.TimeDimension.Layer.extend({
initialize: function( layer, validtimes, getLayerFn, options) {
L.TimeDimension.Layer.prototype.initialize.call(this, layer, options);
this._layers = {};
this._defaultTime = 0;
this._timeCacheBackward = this.options.cacheBackward || this.options.cache || 0;
this._timeCacheForward = this.options.cacheForward || this.options.cache || 0;
this._getLayerFn = getLayerFn;
this._validtimes = validtimes;
this._onLoadFn = this.options.onLoadFn;
this._baseLayer.on('load', (function() {
this._baseLayer.setLoaded(true);
this.fire('timeload', {
time: this._defaultTime
});
}).bind(this));
},
getEvents : function(){
var clearCache = L.bind(this.clear, this);
return {
moveend: clearCache,
zoomend: clearCache
}
},
// currently not used. Seems to get stuck when redraw map.
_unvalidateCache : function(){
var time = this._timeDimension.getCurrentTime();
for (var prop in this._layers) {
if (time != prop && this._layers.hasOwnProperty(prop)) {
var cacheLayer = this._layers[prop];
cacheLayer.setLoaded(false); // mark it as unloaded
var onLoadFn =(function(layer, time) {
layer.setLoaded(true);
cacheLayer.off('load', onLoadFn);
}).bind(this, cacheLayer, time);
cacheLayer.on('load', onLoadFn);
cacheLayer.redraw();
}
}
},
clear : function() {
for (var prop in this._layers) {
delete this._layers[prop];
}
},
eachLayer: function(method, context) {
for (var prop in this._layers) {
if (this._layers.hasOwnProperty(prop)) {
method.call(context, this._layers[prop]);
}
}
return L.TimeDimension.Layer.prototype.eachLayer.call(this, method, context);
},
_onNewTimeLoading: function(ev) {
var time = ev.time;
time = this._getAvailableTime(time);
var layer = this._getLayerForTime(time);
if (!this._map.hasLayer(layer)) {
this._map.addLayer(layer);
layer.hide();
}
},
// Player specific function: get available times to be used in player
getPlayerTimes: function() {
return this._validtimes;
},
// Player specific function: should this layer available times be forced over other layers available times in player
forcePlayerTimes: function() {
return false;
},
isReady: function(time) {
time = this._getAvailableTime(time);
var layer = this._getLayerForTime(time);
return layer.isLoaded();
},
_update: function() {
if (!this._map)
return;
var time = this._timeDimension.getCurrentTime();
time = this._getAvailableTime(time);
var layer = this._getLayerForTime(time);
if (this._currentLayer == null) {
this._currentLayer = layer;
}
if (!this._map.hasLayer(layer)) {
this._map.addLayer(layer);
} else {
this._showLayer(layer, time);
}
},
_evictCachedTimes : function(keepforward, keepbackward){
// Cache management
var times = this._getLoadedTimes();
var strTime = String(this._currentTime);
var index = times.indexOf(strTime);
var remove = [];
// remove times before current time
if (keepbackward > -1) {
var objectsToRemove = index - keepbackward;
if (objectsToRemove > 0) {
remove = times.splice(0, objectsToRemove);
this._removeLayers(remove);
}
}
if (keepforward > -1) {
index = times.indexOf(strTime);
var objectsToRemove = times.length - index - keepforward - 1;
if (objectsToRemove > 0) {
remove = times.splice(index + keepforward + 1, objectsToRemove);
this._removeLayers(remove);
}
}
},
setMinimumForwardCache: function(value) {
if (value > this._timeCacheForward) {
this._timeCacheForward = value;
}
},
_showLayer: function(layer, time) {
if (this._currentLayer && this._currentLayer !== layer) {
this._currentLayer.hide();
}
layer.show();
if (this._currentLayer && this._currentLayer === layer) {
return;
}
this._currentLayer = layer;
this._currentTime = time;
this._evictCachedTimes(this._timeCacheForward, this._timeCacheBackward);
},
_getLayerForTime: function(time) {
if (time == 0 || time == this._defaultTime) {
return this._baseLayer;
}
if (this._layers.hasOwnProperty(time)) {
return this._layers[time];
}
var newLayer = this._getLayerFn(moment(time));
this._layers[time] = newLayer;
var onLoadFn =(function(layer, time) {
layer.setLoaded(true);
if (this._timeDimension && time == this._timeDimension.getCurrentTime() && !this._timeDimension.isLoading()) {
this._showLayer(layer, time);
}
if (this._onLoadFn) this._onLoadFn();
this.fire('timeload', {
time: time
});
newLayer.off('load', onLoadFn);
}).bind(this, newLayer, time);
newLayer.on('load', onLoadFn);
// 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;
},
_getAvailableTime: function(time) {
if (this._validtimes[0] > time || time > this._validtimes[this._validtimes.length-1]) {
return time; // time is out of valid time range
}
var validtime = this._validtimes[0];
for (var i = 0; i < this._validtimes.length; i++) {
if (time >= this._validtimes[i]) {
validtime = this._validtimes[i];
}
}
return validtime;
},
_getLoadedTimes: function() {
var result = [];
for (var prop in this._layers) {
if (this._layers.hasOwnProperty(prop)) {
result.push(prop);
}
}
return result.sort();
},
_removeLayers: function(times) {
for (var i = 0, l = times.length; i < l; i++) {
this._map.removeLayer(this._layers[times[i]]);
delete this._layers[times[i]];
}
},
});
L.timeDimension.layer.weather = function(stores, source, layer, validtimes, options) {
return new L.TimeDimension.Layer.Weather(stores, source, layer, validtimes, options);
};
L.TimeDimension.Layer.WMS.TESTPicasso = 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 += 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);
var timeperiods = timeString.split(',');
var times = [];
for (var i = 0; i < timeperiods.length;i++) {
var timeperiod = timeperiods[i].split('/');
var startDate = moment(timeperiod[0]);
var endDate = moment(timeperiod[1]);
var hours = moment.duration(endDate.diff(startDate)).asHours()+1;
var interval = moment.duration(timeperiod[2]).asHours();
if (interval == 0) 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 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 layerName = this._baseLayer.wmsParams.layers;
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());
}
}
return times;
},
_getTimesFromLayerCapabilities: function(layer) {
var times = null;
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;
},
getEvents : function(){
var clearCache = L.bind(this.clearMoveZoom, this);
return {
moveend: clearCache,
zoomend: clearCache
}
},
clear : function() {
if (this._map && this._map.hasLayer(this._baseLayer)) {
this._map.removeLayer(this._baseLayer);
}
for (var prop in this._layers) {
this._map.removeLayer(this._layers[prop]);
delete this._layers[prop];
}
},
clearMoveZoom : function() {
for (var prop in this._layers) {
delete this._layers[prop];
}
},
_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.testpicasso = function(layer, options) {
return new L.TimeDimension.Layer.WMS.TESTPicasso(layer, options);
};
\ No newline at end of file
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