Commit 12d9af40 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸
Browse files

clear update

parent 09d044de
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.Picasso = 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.clear, this);
return {
moveend: clearCache,
zoomend: clearCache
}
},
clear : function() {
if (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];
}
},
_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.picasso = function(layer, options) {
return new L.TimeDimension.Layer.WMS.Picasso(layer, options);
};
\ No newline at end of file
{"version":3,"sources":["L.TimeDimension.layer.weather.js"],"names":["L","TimeDimension","Layer","Weather","extend","initialize","layer","validtimes","getLayerFn","options","prototype","call","this","_layers","_defaultTime","_timeCacheBackward","cacheBackward","cache","_timeCacheForward","cacheForward","_getLayerFn","_validtimes","_onLoadFn","onLoadFn","_baseLayer","on","setLoaded","fire","time","bind","getEvents","clearCache","clear","moveend","zoomend","_unvalidateCache","_timeDimension","getCurrentTime","prop","hasOwnProperty","cacheLayer","off","redraw","eachLayer","method","context","_onNewTimeLoading","ev","_getAvailableTime","_getLayerForTime","_map","hasLayer","addLayer","hide","getPlayerTimes","forcePlayerTimes","isReady","isLoaded","_update","_currentLayer","_showLayer","_evictCachedTimes","keepforward","keepbackward","times","_getLoadedTimes","strTime","String","_currentTime","index","indexOf","remove","objectsToRemove","splice","_removeLayers","length","setMinimumForwardCache","value","show","newLayer","moment","isLoading","onAdd","map","Object","getPrototypeOf","validtime","i","result","push","sort","l","removeLayer","timeDimension","weather","stores","source","WMS","Picasso","_refTime","_tileCoordsToKey","coords","x","y","z","Math","random","_getCapabilitiesUrl","url","getURL","wmsParams","layers","params","_getCapabilitiesParams","request","service","version","_wmsVersion","Util","getParamString","uppercase","_requestTimeDimensionFromCapabilities","_capabilitiesRequested","_proxy","encodeURIComponent","$","get","data","_getRefTimeFromCapabilities","_setDefaultTime","getAvailableTimes","timeString","_parseTimesFromCapabilities","timeperiods","split","timeperiod","startDate","endDate","hours","duration","diff","asHours","interval","j","date","add","valueOf","setAvailableTimes","setCurrentTime","_availableTimes","_updateTimeDimensionAvailableTimes","xml","find","layerName","layerNameElement","filter","text","refTime","parent","dimension","textContent","trim","extent","_getTimesFromLayerCapabilities","nearestTime","_getNearestTime","utc","format","DIM_REFTIME","constructor","wms","picasso"],"mappings":";;AAAAA,EAAEC,cAAcC,MAAMC,QAAUH,EAAEC,cAAcC,MAAME,QAElDC,WAAY,SAAUC,EAAOC,EAAYC,EAAYC,GACjDT,EAAEC,cAAcC,MAAMQ,UAAUL,WAAWM,KAAKC,KAAMN,EAAOG,GAC7DG,KAAKC,WACLD,KAAKE,aAAe,EACpBF,KAAKG,mBAAqBH,KAAKH,QAAQO,eAAiBJ,KAAKH,QAAQQ,OAAS,EAC9EL,K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AQhB,KAAKE,cAAwB,MAARc,GAAiC,GAAjBhB,KAAKuF,SAC/D,MAAOvF,MAAKY,UAEhB,IAAIZ,KAAKC,QAAQ0B,eAAeX,GAC5B,MAAOhB,MAAKC,QAAQe,EAExB,IAAIwI,GAAcxJ,KAAKyJ,gBAAgBzI,EACvC,IAAIhB,KAAKC,QAAQ0B,eAAe6H,GAC5B,MAAOxJ,MAAKC,QAAQuJ,EAGxB,IAAItD,GAAYlG,KAAKY,WAAWf,OAChCqG,GAAUlF,KAAOoD,OAAOoF,GAAaE,MAAMC,OAAO,0BAClDzD,EAAU0D,YAAcxF,OAAOpE,KAAKuF,UAAUmE,MAAMC,OAAO,yBAC3D,IAAIxF,GAAW,GAAInE,MAAKY,WAAWiJ,YAAY7J,KAAKY,WAAWqF,SAAUC,EA0BzE,OAxBAlG,MAAKC,QAAQe,GAAQmD,EAErBA,EAAStD,GAAG,OAAQ,SAAUnB,EAAOsB,GACjCtB,EAAMoB,WAAU,GAGXd,KAAKC,QAAQe,KACdhB,KAAKC,QAAQe,GAAQtB,GAErBM,KAAKwB,gBAAkBR,GAAQhB,KAAKwB,eAAeC,mBAAqBzB,KAAKwB,eAAe6C,aAC5FrE,KAAKgD,WAAWtD,EAAOsB,GAG3BhB,KAAKe,KAAK,YACNC,KAAMA,KAEXC,KAAKjB,KAAMmE,EAAUnD,IAIxBmD,EAASG,MAAQ,SAAUC,GACvBC,OAAOC,eAAezE,MAAMsE,MAAMvE,KAAKC,KAAMuE,GAC7CvE,KAAKyC,QACNxB,KAAKkD,GACDA,KAKf/E,EAAE6F,cAAcvF,MAAMoK,IAAIC,QAAU,SAASrK,EAAOG,GAChD,MAAO,IAAIT,GAAEC,cAAcC,MAAM+F,IAAIC,QAAQ5F,EAAOG","file":"L.TimeDimension.layer.weather.min.js"}
\ No newline at end of file
/*! L.TimeDimension.layer.weather 2017-05-29 */
L.TimeDimension.Layer.Weather=L.TimeDimension.Layer.extend({initialize:function(a,b,c,d){L.TimeDimension.Layer.prototype.initialize.call(this,a,d),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=c,this._validtimes=b,this._onLoadFn=this.options.onLoadFn,this._baseLayer.on("load",function(){this._baseLayer.setLoaded(!0),this.fire("timeload",{time:this._defaultTime})}.bind(this))},getEvents:function(){var a=L.bind(this.clear,this);return{moveend:a,zoomend:a}},_unvalidateCache:function(){var a=this._timeDimension.getCurrentTime();for(var b in this._layers)if(a!=b&&this._layers.hasOwnProperty(b)){var c=this._layers[b];c.setLoaded(!1);var d=function(a,b){a.setLoaded(!0),c.off("load",d)}.bind(this,c,a);c.on("load",d),c.redraw()}},clear:function(){for(var a in this._layers)delete this._layers[a]},eachLayer:function(a,b){for(var c in this._layers)this._layers.hasOwnProperty(c)&&a.call(b,this._layers[c]);return L.TimeDimension.Layer.prototype.eachLayer.call(this,a,b)},_onNewTimeLoading:function(a){var b=a.time;b=this._getAvailableTime(b);var c=this._getLayerForTime(b);this._map.hasLayer(c)||(this._map.addLayer(c),c.hide())},getPlayerTimes:function(){return this._validtimes},forcePlayerTimes:function(){return!1},isReady:function(a){return a=this._getAvailableTime(a),this._getLayerForTime(a).isLoaded()},_update:function(){if(this._map){var a=this._timeDimension.getCurrentTime();a=this._getAvailableTime(a);var b=this._getLayerForTime(a);null==this._currentLayer&&(this._currentLayer=b),this._map.hasLayer(b)?this._showLayer(b,a):this._map.addLayer(b)}},_evictCachedTimes:function(a,b){var c=this._getLoadedTimes(),d=String(this._currentTime),e=c.indexOf(d),f=[];if(b>-1){var g=e-b;g>0&&(f=c.splice(0,g),this._removeLayers(f))}if(a>-1){e=c.indexOf(d);var g=c.length-e-a-1;g>0&&(f=c.splice(e+a+1,g),this._removeLayers(f))}},setMinimumForwardCache:function(a){a>this._timeCacheForward&&(this._timeCacheForward=a)},_showLayer:function(a,b){this._currentLayer&&this._currentLayer!==a&&this._currentLayer.hide(),a.show(),this._currentLayer&&this._currentLayer===a||(this._currentLayer=a,this._currentTime=b,this._evictCachedTimes(this._timeCacheForward,this._timeCacheBackward))},_getLayerForTime:function(a){if(0==a||a==this._defaultTime)return this._baseLayer;if(this._layers.hasOwnProperty(a))return this._layers[a];var b=this._getLayerFn(moment(a));this._layers[a]=b;var c=function(a,d){a.setLoaded(!0),this._timeDimension&&d==this._timeDimension.getCurrentTime()&&!this._timeDimension.isLoading()&&this._showLayer(a,d),this._onLoadFn&&this._onLoadFn(),this.fire("timeload",{time:d}),b.off("load",c)}.bind(this,b,a);return b.on("load",c),b.onAdd=function(a){Object.getPrototypeOf(this).onAdd.call(this,a),this.hide()}.bind(b),b},_getAvailableTime:function(a){if(this._validtimes[0]>a||a>this._validtimes[this._validtimes.length-1])return a;for(var b=this._validtimes[0],c=0;c<this._validtimes.length;c++)a>=this._validtimes[c]&&(b=this._validtimes[c]);return b},_getLoadedTimes:function(){var a=[];for(var b in this._layers)this._layers.hasOwnProperty(b)&&a.push(b);return a.sort()},_removeLayers:function(a){for(var b=0,c=a.length;b<c;b++)this._map.removeLayer(this._layers[a[b]]),delete this._layers[a[b]]}}),L.timeDimension.layer.weather=function(a,b,c,d,e){return new L.TimeDimension.Layer.Weather(a,b,c,d,e)},L.TimeDimension.Layer.WMS.Picasso=L.TimeDimension.Layer.WMS.extend({initialize:function(a,b){L.TimeDimension.Layer.WMS.prototype.initialize.call(this,a,b),this._refTime=0,a._tileCoordsToKey=function(a){return a.x+":"+a.y+":"+a.z+":"+Math.random()}},_getCapabilitiesUrl:function(){var a=this._baseLayer.getURL();this._baseLayer.wmsParams.layers&&(a+=this._baseLayer.wmsParams.layers);var b=L.extend({},this._getCapabilitiesParams,{request:"GetCapabilities",service:"WMS",version:this._wmsVersion});return a+=L.Util.getParamString(b,a,b.uppercase)},_requestTimeDimensionFromCapabilities:function(){if(!this._capabilitiesRequested){this._capabilitiesRequested=!0;var a=this._getCapabilitiesUrl();this._proxy&&(a=this._proxy+"?url="+encodeURIComponent(a)),$.get(a,function(a){this._defaultTime=0,this._refTime=this._getRefTimeFromCapabilities(a),this._setDefaultTime=this._setDefaultTime||this._timeDimension&&0==this._timeDimension.getAvailableTimes().length;for(var b=this._parseTimesFromCapabilities(a),c=b.split(","),d=[],e=0;e<c.length;e++){var f=c[e].split("/"),g=moment(f[0]),h=moment(f[1]),i=moment.duration(h.diff(g)).asHours()+1,j=moment.duration(f[2]).asHours();0==j&&(j=1);for(var k=0;k<i;k+=j){var l=moment(g).add(k,"hours").valueOf();d.push(l)}}this.setAvailableTimes(d),this._setDefaultTime&&this._timeDimension&&this._timeDimension.setCurrentTime(this._defaultTime),d.length>0&&this.fire("metadataload")}.bind(this))}},setAvailableTimes:function(a){this._availableTimes=a,this._updateTimeDimensionAvailableTimes()},getPlayerTimes:function(){return this._availableTimes},forcePlayerTimes:function(){return!1},_getRefTimeFromCapabilities:function(a){var b=$(a).find('Layer[queryable="0"]'),c=this._baseLayer.wmsParams.layers,d=b.find("Name").filter(function(a){return $(this).text()===c}),e="";if(d){var f=d.parent(),g=f.find("Dimension[name='reftime']");if(g&&g.length&&g[0].textContent.length)e=g[0].textContent.trim();else{var h=f.find("Extent[name='reftime']");h&&h.length&&h[0].textContent.length&&(e=h[0].textContent.trim())}}return e},_parseTimesFromCapabilities:function(a){var b=$(a).find('Layer[queryable="0"]'),c=this._baseLayer.wmsParams.layers,d=b.find("Name").filter(function(a){return $(this).text()===c}),e=null;if(d){var f=d.parent();e=this._getTimesFromLayerCapabilities(f),e||(e=this._getTimesFromLayerCapabilities(f.parent()))}return e},_getTimesFromLayerCapabilities:function(a){var b=null,c=a.find("Dimension[name='time']");if(c&&c.length&&c[0].textContent.length)b=c[0].textContent.trim();else{var d=a.find("Extent[name='time']");d&&d.length&&d[0].textContent.length&&(b=d[0].textContent.trim())}return b},getEvents:function(){var a=L.bind(this.clear,this);return{moveend:a,zoomend:a}},clear:function(){this._map.hasLayer(this._baseLayer)&&this._map.removeLayer(this._baseLayer);for(var a in this._layers)this._map.removeLayer(this._layers[a]),delete this._layers[a]},_getLayerForTime:function(a){if(0==a||a==this._defaultTime||null==a||0==this._refTime)return this._baseLayer;if(this._layers.hasOwnProperty(a))return this._layers[a];var b=this._getNearestTime(a);if(this._layers.hasOwnProperty(b))return this._layers[b];var c=this._baseLayer.options;c.time=moment(b).utc().format("YYYY-MM-DDTHH:mm:ss[Z]"),c.DIM_REFTIME=moment(this._refTime).utc().format("YYYY-MM-DDTHH:mm:ss[Z]");var d=new this._baseLayer.constructor(this._baseLayer.getURL(),c);return this._layers[a]=d,d.on("load",function(a,b){a.setLoaded(!0),this._layers[b]||(this._layers[b]=a),this._timeDimension&&b==this._timeDimension.getCurrentTime()&&!this._timeDimension.isLoading()&&this._showLayer(a,b),this.fire("timeload",{time:b})}.bind(this,d,a)),d.onAdd=function(a){Object.getPrototypeOf(this).onAdd.call(this,a),this.hide()}.bind(d),d}}),L.timeDimension.layer.wms.picasso=function(a,b){return new L.TimeDimension.Layer.WMS.Picasso(a,b)};
//# sourceMappingURL=L.TimeDimension.layer.weather.map
\ No newline at end of file
......@@ -132,7 +132,11 @@ L.TimeDimension.Layer.WMS.Picasso = L.TimeDimension.Layer.WMS.extend({
}
},
clear : function() {
if (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];
}
},
......
Supports Markdown
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