[Mapbender-commits] r9590 - trunk/mapbender/http/php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Sep 9 02:05:14 PDT 2016
Author: armin11
Date: 2016-09-09 02:05:14 -0700 (Fri, 09 Sep 2016)
New Revision: 9590
Modified:
trunk/mapbender/http/php/mod_transformTimeDimension.php
Log:
Bugfix for full year ranges in layer time dimension
Modified: trunk/mapbender/http/php/mod_transformTimeDimension.php
===================================================================
--- trunk/mapbender/http/php/mod_transformTimeDimension.php 2016-09-09 09:02:04 UTC (rev 9589)
+++ trunk/mapbender/http/php/mod_transformTimeDimension.php 2016-09-09 09:05:14 UTC (rev 9590)
@@ -38,6 +38,7 @@
die();
}
$iso8601Pattern = '/^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?$/i';
+$singleYearPattern = '/^\d{4}$/';
//$iso8601Pattern = '/^(?:[1-9]\d{3}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1\d|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[1-9]\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)-02-29)T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:Z|[+-][01]\d:[0-5]\d)$/i';
if (isset($_REQUEST["default"]) & $_REQUEST["default"] != "") {
$testMatch = urldecode($_REQUEST["default"]);
@@ -108,10 +109,19 @@
//define default timezone:
date_default_timezone_set('UTC');
//what do we need further for timeline:
+$fullYearExtent = false;
//min, max, if point is slideable, if some point is already selected -> userValue
if ($operation == 'snapToGrid') {
$interval = explode('/',$extent);
$startTime = new DateTime($interval[0]);
+ //check full year extent for snapping
+ if (preg_match($singleYearPattern,$interval[0])) {
+ $fullYearExtent = true;
+ //$e = new mb_exception("single year pattern for snapping");
+ //set to middle of the year
+ $interval[0] = $interval[0]."-07-02";
+ //$interval[1] = $interval[1]."-07-02";
+ }
//$e = new mb_exception("default timezone: ".date_default_timezone_get());
$timezone = $startTime->getTimezone();
//timezone from starttime:
@@ -121,7 +131,7 @@
$defaultTimeZone = timezone_open('UTC');
//$e = new mb_exception("timezone from starttime: ".date_default_timezone_get($timezone));
//problem - if no timezone is set use default GMT!!
- $endTime = new DateTime($interval[1]);
+ //$endTime = new DateTime($interval[1]);
$duration = new DateInterval($interval[2]);
$userValueDateTime = new DateTime($userValue);
$diffTime = $startTime->diff($userValueDateTime); //creates php datetime interval object
@@ -139,7 +149,11 @@
//$newTime = $newTime->setTimezone($timezone);
$newTime = $newTime->setTimezone($defaultTimeZone);
//$e = new mb_exception("newtime: ".$newTime->format('c'));
- $result->data[0]->value = $newTime->format('c');
+ if ($fullYearExtent == true) {
+ $result->data[0]->value = $newTime->format('Y');
+ } else {
+ $result->data[0]->value = $newTime->format('c');
+ }
$result->result->error = false;
$result->result->message = "All done";
} else {
@@ -147,7 +161,18 @@
case "intervalWithDuration":
//calculate discrete points
$interval = explode('/',$extent);
+ //check extent for single year entries
+ if (preg_match($singleYearPattern,$interval[0]) && preg_match($singleYearPattern,$interval[1])) {
+ $fullYearExtent = true;
+ $e = new mb_exception("single year pattern");
+ //set to middle of the year
+ $interval[0] = $interval[0]."-07-02";
+ $interval[1] = $interval[1]."-07-02";
+ }
+ //parse one single year as date of the
+ //$e = new mb_exception("extent representation of starttime: ".$interval[0]);
$startTime = new DateTime($interval[0]);
+ //$e = new mb_exception("date representation of starttime: ".$startTime->format('c'));
$endTime = new DateTime($interval[1]);
$duration = new DateInterval($interval[2]);
$timezone = $startTime->getTimezone();
@@ -155,7 +180,12 @@
$diffTime = $startTime->diff($endTime); //creates php datetime interval object
$diffTimeSeconds = $diffTime->s + $diffTime->i * 60 + $diffTime->h * 3600 + $diffTime->days * (3600*24);
//Problem: DateInterval cannot be directly converted into seconds - only days are possible
- $seconds = $duration->s + $duration->i * 60 + $duration->h * 3600 + $duration->days * (3600*24);
+ //days are only given, if interval has more than some days - if not given, use d attribute
+ if ($duration->days == false) {
+ $seconds = $duration->s + $duration->i * 60 + $duration->h * 3600 + $duration->d * (3600*24) + $duration->m * (30.436875*3600*24) + $duration->y * (365*3600*24) ;
+ } else {
+ $seconds = $duration->s + $duration->i * 60 + $duration->h * 3600 + $duration->days * (3600*24);
+ }
$numberOfDiscreteValues = $diffTimeSeconds / $seconds;
if ($numberOfDiscreteValues > $maxEntries) {
//abort("Number of possible discrete values: ".$numberOfDiscreteValues." exeeds max allowed number for visualization of timeline: ".$maxEntries."!");
@@ -170,6 +200,11 @@
$result->data[0]->content = $default;
if ($default == 'current') {
$result->data[0]->start = $endTime->format('c');
+ if ($fullYearExtent == true) {
+ $result->data[0]->content = $endTime->format('Y');
+ } else {
+ $result->data[0]->content = $endTime->format('c');
+ }
} else {
$result->data[0]->start = $default;
}
@@ -185,14 +220,23 @@
}
} else {
$result->data[0]->id = 0;
- $result->data[0]->content = $startTime->format('c');
+ if ($fullYearExtent == true) {
+ $result->data[0]->content = $startTime->format('Y');
+ } else {
+ $result->data[0]->content = $startTime->format('c');
+ }
$result->data[0]->start = $startTime->format('c');
for ($i=1; $i < $numberOfDiscreteValues+1; $i++) {
$time = $startTime->add($duration);
//$time->setTimezone($timezone);
$result->data[$i]->id = $i;
- $result->data[$i]->content = $time->format('c');
- $result->data[$i]->start = $time->format('c');
+ if ($fullYearExtent == true) {
+ $result->data[$i]->content = $time->format('Y');
+ $result->data[$i]->start = $time->format('c');
+ } else {
+ $result->data[$i]->content = $time->format('c');
+ $result->data[$i]->start = $time->format('c');
+ }
}
//$result->options->editable->updateTime = false;
//$result->options->editable->updateTime = false;
@@ -206,6 +250,7 @@
$result->result->message = "All done";
break;
case "discreteValues":
+ //$e = new mb_exception("discrete values");
if (count(explode(',',$extent)) > $maxEntries) {
abort("Number of discrete values: ".count(explode(',',$extent))." exeeds max allowed number for visualization of timeline: ".$maxEntries."!");
} else {
More information about the Mapbender_commits
mailing list