Skip to content

Commit

Permalink
Added new animation function
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenlterpstra committed Dec 20, 2017
1 parent 74c04f9 commit 048c13e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
9 changes: 5 additions & 4 deletions webmapjs/WMJSDimension.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ function WMJSDimension (config) {
}
return nextValue;
};
this.getClosestValue = function (newValue) {
this.getClosestValue = function (newValue, evenWhenOutsideRange) {
evenWhenOutsideRange = typeof evenWhenOutsideRange !== 'undefined' ? evenWhenOutsideRange : false;
var index = -1;
var _value = WMJSDateOutSideRange;
try {
Expand All @@ -132,9 +133,9 @@ function WMJSDimension (config) {

if (newValue == 'current' || newValue == 'default' || newValue == '') {
_value = this.defaultValue;
} else if (newValue == 'latest') {
_value = this.getValueForIndex(dim.size() - 1);
} else if (newValue == 'earliest') {
} else if (newValue == 'latest' || (evenWhenOutsideRange && _value === WMJSDateTooLateString)) {
_value = this.getValueForIndex(this.size() - 1);
} else if (newValue == 'earliest' || (evenWhenOutsideRange && _value === WMJSDateTooEarlyString)) {
_value = this.getValueForIndex(0);
} else if (newValue == 'middle') {
var middleIndex = (this.size() / 2) - 1;
Expand Down
4 changes: 2 additions & 2 deletions webmapjs/WMJSTimeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ var RelativeSlider = function (config) {
var absoluteValue = 0;
var previousRelValue = 50;

var sliderChangeRelative = function (relativeValue) {
absoluteValue += relativeValue;
var sliderChangeRelative = function (relativeValue)
{ absoluteValue += relativeValue;
if (absoluteValue > maxValue - 1)absoluteValue = maxValue - 1;
if (absoluteValue < 0)absoluteValue = 0;
if (isDefined(config.change)) {
Expand Down
26 changes: 26 additions & 0 deletions webmapjs/WebMapJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,32 @@ function WMJSMap (_element, _xml2jsonrequestURL) {

var zoomBeforeLoadBBOX;
var srsBeforeLoadBBOX;
// Animate between last point and point up to `n` time-units ago of the active layer
// E.g. Draw the last three hours of a layer
this.drawLastTimes = function (hoursAgo, timeUnit) {
if (!timeUnit) {
timeUnit = 'hours';
}
if (layers.length === 0) return;
var layer = this.getActiveLayer();
if (!layer) {
return;
}
var timeDimension = layer.getDimension('time');
if (!timeDimension) {
return;
}
var lastIndex = timeDimension.size() - 1;
var drawDates = [];
var lastTime = moment.utc(timeDimension.getValueForIndex(lastIndex));
var begin = lastTime.subtract(hoursAgo, timeUnit);
while (lastIndex > 0) {
lastTime = timeDimension.getValueForIndex(lastIndex--);
if (!lastTime || lastTime === WMJSDateTooEarlyString || begin.isAfter(moment.utc(lastTime))) break;
drawDates.unshift({ name: 'time', value: lastTime });
}
this.draw(drawDates);
}
// Animate between start and end dates with the smallest available resolution
this.drawAutomatic = function (start, end) {
if (layers.length === 0) {
Expand Down

0 comments on commit 048c13e

Please sign in to comment.