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

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.
This diff is collapsed.
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