Commit 0fcd44f2 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

new strat

parent 2a89c5f2
/node_modules/
**/node_modules/
/bower_components/
\ No newline at end of file
......@@ -14,7 +14,9 @@
"url": "git@git.smhi.se:stw/L.TimeDimension.layer.weather.git"
},
"dependencies": {
"leaflet": "https://github.com/Leaflet/Leaflet.git#v1.0.0-beta.2"
"leaflet": "https://github.com/Leaflet/Leaflet.git#v1.0.0-beta.2",
"leaflet-timedimension" : "https://github.com/socib/Leaflet.TimeDimension.git#v1.0.2",
"leaflet-tilelayer-wms-picasso": "https://git.smhi.se/stw/leaflet-tilelayer-wms-picasso.git"
},
"devDependencies": {},
"license": "MIT",
......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="da" style="font-size: 100%">
<head>
<title>L.TimeDimension.layer.weather - Demo</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta http-equiv='x-dns-prefetch-control' content='on'>
<meta name='copyright' content='STW'>
<meta name='owner' content='STW'>
<link href="../bower_components/leaflet/dist/leaflet.css" rel="stylesheet">
<link href="../bower_components/leaflet-timedimension/dist/leaflet.timedimension.control.min.css" rel="stylesheet">
</head>
<body>
<div id="map" style="width: 800px; height: 600px"></div>
<script src="../bower_components/leaflet/dist/leaflet-src.js"></script>
<script src="../bower_components/jquery/dist/jquery.js"></script>
<script src="../bower_components/moment/min/moment.min.js"></script>
<script src="../bower_components/iso8601-js-period/iso8601.min.js"></script>
<script src="../bower_components/leaflet-timedimension/dist/leaflet.timedimension.src.withlog.js"></script>
<script src="../bower_components/leaflet-tilelayer-wms-picasso/src/leaflet-tilelayer-wms-picasso.js"></script>
<script src="../src/L.TimeDimension.layer.wms.picasso.js"></script>
<script>
var map = L.map('map', {
timeDimension: true,
timeDimensionControl: true
}).setView([ 58.5, 19.0 ], 5);
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 wmsLayer = L.tileLayer.wms('http://wts.smhi.se/tile/', {
layers: "hiromb-BS01:oceancurrent-arrows_n-europe_4326_",
transparent: true,
crs: L.CRS.EPSG900913,
format: 'image/png',
attribution: 'Current forecasts from <a href="http://www.smhi.se" alt="Swedish Meteorological Hydrological Institute">SMHI</a>'
});
var weatherLayer = L.timeDimension.layer.wms.picasso(wmsLayer, {
proxy: 'proxy',
cache: 10
});
map.addLayer(weatherLayer);
</script>
</body>
</html>
{
"name": "noderest",
"description": "Demo REST API with Node",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "4.x",
"path": "latest",
"request" : "latest"
}
}
\ No newline at end of file
var express = require('express');
var path = require('path');
var request = require('request');
var app = express();
app.get('/demo/proxy', function (req, res) {
request(req.query.url, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.send(body);
}
})
});
// app.use(express.static(__dirname + '/../bower_components'));
//console.log(__dirname + '/../bower_components');
app.use('/bower_components', express.static(path.join(__dirname, '../bower_components')));
app.use('/src', express.static(path.join(__dirname, '../src')));
app.use('/demo', express.static(__dirname));
app.listen(8080);
console.log('Server started on http://localhost:8080...');
\ No newline at end of file
L.TimeDimension.Layer.WMS.Picasso = L.TimeDimension.Layer.WMS.extend({
_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);
}
}).bind(this));
},
setAvailableTimes: function(times) {
this._availableTimes = times;
this._updateTimeDimensionAvailableTimes();
},
_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.picasso = function(layer, options) {
return new L.TimeDimension.Layer.WMS.Picasso(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