[Mapbender-commits] r9577 - trunk/mapbender/http/php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Sep 7 05:42:19 PDT 2016
Author: armin11
Date: 2016-09-07 05:42:19 -0700 (Wed, 07 Sep 2016)
New Revision: 9577
Modified:
trunk/mapbender/http/php/mod_transformTimeDimension.php
Log:
Further functions to allow support of wms time dimension
Modified: trunk/mapbender/http/php/mod_transformTimeDimension.php
===================================================================
--- trunk/mapbender/http/php/mod_transformTimeDimension.php 2016-09-07 12:41:30 UTC (rev 9576)
+++ trunk/mapbender/http/php/mod_transformTimeDimension.php 2016-09-07 12:42:19 UTC (rev 9577)
@@ -22,9 +22,10 @@
require_once(dirname(__FILE__)."/../../core/globalSettings.php");
$objDateTime = new DateTime('NOW');
-$maxEntries = 10;
+$maxEntries = 15;
$default = false;
$userValue = false;
+$operation = "configureTimeline";
$kindOfExtent = "singleValue"; //interval, discreteValues, intervalWithDuration
$extent = $objDateTime->format($objDateTime::ATOM);
//http://stackoverflow.com/questions/21686539/regular-expression-for-full-iso-8601-date-syntax
@@ -37,23 +38,31 @@
die();
}
$iso8601Pattern = '/^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?$/i';
-//test default value
+//$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 = $_REQUEST["default"];
+ $testMatch = urldecode($_REQUEST["default"]);
if (!preg_match($iso8601Pattern,$testMatch)){
abort("The value for the default parameter is not a valid iso8601 dateTime string.");
}
$default = $testMatch;
}
+if (isset($_REQUEST["operation"]) & $_REQUEST["operation"] != "") {
+ $testMatch = urldecode($_REQUEST["operation"]);
+ if (!$testMatch == 'snapToGrid' && !$testMatch == 'configureTimeline'){
+ echo 'Parameter <b>operation</b> is not valid (snapToGrid,configureTimeline).<br/>';
+ die();
+ }
+ $operation = $testMatch;
+}
if (isset($_REQUEST["userValue"]) & $_REQUEST["userValue"] != "") {
- $testMatch = $_REQUEST["userValue"];
+ $testMatch = urldecode($_REQUEST["userValue"]);
if (!preg_match($iso8601Pattern,$testMatch)){
abort("The value for the userValue parameter is not a valid iso8601 dateTime string.");
}
$userValue = $testMatch;
}
if (isset($_REQUEST["extent"]) & $_REQUEST["extent"] != "") {
- $testMatch = $_REQUEST["extent"];
+ $testMatch = urldecode($_REQUEST["extent"]);
//search for comma
if (strpos($testMatch,',') !== false) {
//found single discrete values
@@ -96,83 +105,126 @@
}
//Variable for result object
$result->data = array();
+//define default timezone:
+date_default_timezone_set('UTC');
//what do we need further for timeline:
//min, max, if point is slideable, if some point is already selected -> userValue
-switch ($kindOfExtent) {
- case "intervalWithDuration":
- //calculate discrete points
- $interval = explode('/',$extent);
- $startTime = new DateTime($interval[0]);
- $endTime = new DateTime($interval[1]);
- $duration = new DateInterval($interval[2]);
- $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
- //echo $startTime->add($duration)->format('c');
- //die();
- $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."!");
- //use the default value or the userValue if given
- if ($userValue !== false || $default !== false) {
- if ($userValue !== false) {
- $result->data[0]->id = 0;
- $result->data[0]->content = $userValue;
- $result->data[0]->start = $userValue;
+if ($operation == 'snapToGrid') {
+ $interval = explode('/',$extent);
+ $startTime = new DateTime($interval[0]);
+ //$e = new mb_exception("default timezone: ".date_default_timezone_get());
+ $timezone = $startTime->getTimezone();
+ //timezone from starttime:
+ //test if timezone was found in starttime:
+ //$e = new mb_exception("timezone found in starttime: ".$timezone->getName());
+ //$e = new mb_exception("start timezone: ".$startTime->getTimezone());
+ $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]);
+ $duration = new DateInterval($interval[2]);
+ $userValueDateTime = new DateTime($userValue);
+ $diffTime = $startTime->diff($userValueDateTime); //creates php datetime interval object
+ $diffTimeSeconds = $diffTime->s + $diffTime->i * 60 + $diffTime->h * 3600 + $diffTime->days * (3600*24);
+ //$e = new mb_exception("days: ".$diffTime->days);
+ $seconds = $duration->s + $duration->i * 60 + $duration->h * 3600 + $duration->d * (3600*24) + $duration->m * (30.436875*3600*24) + $duration->y * (365*3600*24);
+ //$e = new mb_exception("durationdays: ".$duration->d);
+ $fullDiffInSteps = round($diffTimeSeconds / $seconds);
+ /*$e = new mb_exception("start: ".$interval[0]);
+ $e = new mb_exception("wish to select: ".$userValue);
+ $e = new mb_exception("steps: ".$fullDiffInSteps);
+ $e = new mb_exception("seconds: ".$seconds);*/
+ $dateIntervalNew = new DateInterval('PT'.$fullDiffInSteps * $seconds.'S');
+ $newTime = $startTime->add($dateIntervalNew);
+ //$newTime = $newTime->setTimezone($timezone);
+ $newTime = $newTime->setTimezone($defaultTimeZone);
+ //$e = new mb_exception("newtime: ".$newTime->format('c'));
+ $result->data[0]->value = $newTime->format('c');
+ $result->result->error = false;
+ $result->result->message = "All done";
+} else {
+ switch ($kindOfExtent) {
+ case "intervalWithDuration":
+ //calculate discrete points
+ $interval = explode('/',$extent);
+ $startTime = new DateTime($interval[0]);
+ $endTime = new DateTime($interval[1]);
+ $duration = new DateInterval($interval[2]);
+ $timezone = $startTime->getTimezone();
+ //$e = new mb_exception("timezone of starttime: ".$timezone->getName());
+ $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);
+ $numberOfDiscreteValues = $diffTimeSeconds / $seconds;
+ if ($numberOfDiscreteValues > $maxEntries) {
+ //abort("Number of possible discrete values: ".$numberOfDiscreteValues." exeeds max allowed number for visualization of timeline: ".$maxEntries."!");
+ //use the default value or the userValue if given
+ if ($userValue !== false || $default !== false) {
+ if ($userValue !== false) {
+ $result->data[0]->id = 0;
+ $result->data[0]->content = $userValue;
+ $result->data[0]->start = $userValue;
+ } else {
+ $result->data[0]->id = 0;
+ $result->data[0]->content = $default;
+ $result->data[0]->start = $default;
+ }
+ //set options to make a moving of value possible
+ $result->options->editable->updateTime = true;
+ //$result->options->configure = true;
+ //$result->options->timeAxis->scale = 'minute';
+ //$result->options->timeAxis->step = 5;
+ //better do snapping in callback function!
} else {
- $result->data[0]->id = 0;
- $result->data[0]->content = $default;
- $result->data[0]->start = $default;
+ //nothing
}
- //set options to make a moving of value possible
- $result->options->editable->updateTime = true;
- //$result->options->configure = true;
- //$result->options->timeAxis->scale = 'minute';
- //$result->options->timeAxis->step = 5;
- //better do snapping in callback function!
- //$result->options->onMove = "function (item,callback) {alert('test')}";
} else {
+ $result->data[0]->id = 0;
+ $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');
+ }
+ //$result->options->editable->updateTime = false;
+ //$result->options->editable->updateTime = false;
+ $result->options->editable = false;
+ }
+ //re-initialize starttime because in case of a interval the time is incremented in the else loop before
+ $oldStartTime = new DateTime($interval[0]);
+ $result->options->min = $oldStartTime->format('c');
+ $result->options->max = $endTime->format('c');
+ $result->result->error = false;
+ $result->result->message = "All done";
+ break;
+ case "discreteValues":
+ if (count(explode(',',$extent)) > $maxEntries) {
+ abort("Number of discrete values: ".count(explode(',',$extent))." exeeds max allowed number for visualization of timeline: ".$maxEntries."!");
+ } else {
+ $extentArray = explode(',',$extent);
+ for ($i=0; $i < count($extentArray); $i++) {
+ $result->data[$i]->id = $i;
+ $result->data[$i]->content = $extentArray[$i];
+ $result->data[$i]->start = $extentArray[$i];
+ }
+ }
+ //use first and last entry as borders
+ $result->options->min = $extentArray[0];
+ $result->options->max = $extentArray[count($extentArray) - 1];
+ $result->result->error = false;
+ $result->result->message = "All done";
+ break;
+ case "singleValue":
+ //push json values
+ echo $extent;
+ break;
+ }
+}
- }
- } else {
- $result->data[0]->id = 0;
- $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)->format('c');
- $result->data[$i]->id = $i;
- $result->data[$i]->content = $time;
- $result->data[$i]->start = $time;
- }
- }
- $result->options->min = $interval[0];
- $result->options->max = $interval[1];
- $result->result->error = false;
- $result->result->message = "All done";
- break;
- case "discreteValues":
- if (count(explode(',',$extent)) > $maxEntries) {
- abort("Number of discrete values: ".count(explode(',',$extent))." exeeds max allowed number for visualization of timeline: ".$maxEntries."!");
- } else {
- $extentArray = explode(',',$extent);
- for ($i=0; $i < count($extentArray); $i++) {
- $result->data[$i]->id = $i;
- $result->data[$i]->content = $extentArray[$i];
- $result->data[$i]->start = $extentArray[$i];
- }
- }
- //use first and last entry as borders
- $result->options->min = $extentArray[0];
- $result->options->max = $extentArray[count($extentArray) - 1];
- $result->result->error = false;
- $result->result->message = "All done";
- break;
- case "singleValue":
- //push json values
- echo $extent;
- break;
-}
header('Content-Type: application/json');
echo json_encode($result);
?>
More information about the Mapbender_commits
mailing list