Commit 71619d94 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸
Browse files

testing fixes

parent 02ae3804
......@@ -41,12 +41,11 @@ module.exports = function(grunt) {
includeSelf: true,
src: ['demo/index.html'],
overrides : {
"uikit": {
"main" : [
"js/uikit.js",
"css/uikit.almost-flat.min.css"
]
}
"L.TimeDimension.layer.weather" : {
"main" : [
"src/L.TimeDimension.layer.wms.smhipicasso.js", "src/L.TimeDimension.layer.wms.picasso.js"
]
}
}
}
},
......
......@@ -7,15 +7,16 @@
],
"description": "TimeDimension layer for displaying L.TileLayers with time dimension. Syncs with leaflet-player-control",
"main": [
"src/L.TimeDimension.layer.wms.picasso.js"
"src/L.TimeDimension.layer.wms.smhipicasso.js"
],
"repository": {
"type": "git",
"url": "git@git.smhi.se:stw/L.TimeDimension.layer.weather.git"
},
"dependencies": {
"jquery": "latest",
"leaflet": "https://github.com/Leaflet/Leaflet.git#v1.0.3",
"leaflet-timedimension" : "https://github.com/socib/Leaflet.TimeDimension.git#v1.0.2",
"leaflet-timedimension" : "https://github.com/socib/Leaflet.TimeDimension.git#v1.1.0",
"reqwest" : "https://github.com/ded/reqwest.git",
"moment": "latest"
},
......
......@@ -20,12 +20,13 @@
<div id="map" style="width: 800px; height: 600px"></div>
<!-- bower:js -->
<script src="../bower_components/jquery/dist/jquery.js"></script>
<script src="../bower_components/leaflet/dist/leaflet-src.js"></script>
<script src="../bower_components/iso8601-js-period/iso8601.min.js"></script>
<script src="../bower_components/jquery/dist/jquery.js"></script>
<script src="../bower_components/leaflet-timedimension/dist/leaflet.timedimension.src.js"></script>
<script src="../bower_components/reqwest/reqwest.js"></script>
<script src="../bower_components/moment/moment.js"></script>
<script src="../src/L.TimeDimension.layer.wms.smhipicasso.js"></script>
<script src="../src/L.TimeDimension.layer.wms.picasso.js"></script>
<!-- endbower -->
......@@ -36,13 +37,19 @@
timeDimension: true,
timeDimensionControl: true
}).setView([ 58.5, 19.0 ], 5);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
var osm = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom : 18,
attribution : '&copy; <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors</a>'
}).addTo(map);
var baseLayers = {
"Open Street Map": osm
};
var wmsLayer = L.tileLayer.wms('http://wts.smhi.se/tile/', {
layers: "NEMO:NS02_oceancurrentarrows_neurope_",
layers: "NEMO:NS02_oceancurrentspeed_arrows_neurope_",
transparent: true,
crs: L.CRS.EPSG900913,
format: 'image/png',
......@@ -50,12 +57,16 @@
});
var weatherLayer = L.timeDimension.layer.wms.picasso(wmsLayer, {
var weatherLayer = L.timeDimension.layer.wms.smhipicasso(wmsLayer, {
proxy: 'proxy',
cache: 10
});
map.addLayer(weatherLayer);
var overlays = {
"Current arrows with speed": weatherLayer
};
L.control.layers(baseLayers, overlays).addTo(map);
reqwest({
url: "meta",
......
......@@ -410,4 +410,135 @@ L.TimeDimension.Layer.WMS.Picasso = L.TimeDimension.Layer.WMS.extend({
L.timeDimension.layer.wms.picasso = function(layer, options) {
return new L.TimeDimension.Layer.WMS.Picasso(layer, options);
};
L.TimeDimension.Layer.WMS.SMHIPicasso = 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;
}
});
L.timeDimension.layer.wms.smhipicasso = function(layer, options) {
return new L.TimeDimension.Layer.WMS.SMHIPicasso(layer, options);
};
\ No newline at end of file
This diff is collapsed.
/*! L.TimeDimension.layer.weather 2017-05-30 */
/*! L.TimeDimension.layer.weather 2017-10-26 */
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.clearMoveZoom,this);return{moveend:a,zoomend:a}},clear:function(){this._map&&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]},clearMoveZoom:function(){for(var a in this._layers)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)};
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.clearMoveZoom,this);return{moveend:a,zoomend:a}},clear:function(){this._map&&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]},clearMoveZoom:function(){for(var a in this._layers)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)},L.TimeDimension.Layer.WMS.SMHIPicasso=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}}),L.timeDimension.layer.wms.smhipicasso=function(a,b){return new L.TimeDimension.Layer.WMS.SMHIPicasso(a,b)};
//# sourceMappingURL=L.TimeDimension.layer.weather.map
\ No newline at end of file
L.TimeDimension.Layer.WMS.SMHIPicasso = 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;
},
_getLayerForTime: function(time) {
if (time == 0 || time == this._defaultTime || time == null) {
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.smhipicasso = function(layer, options) {
return new L.TimeDimension.Layer.WMS.SMHIPicasso(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