[Mapbender-commits] r9597 - trunk/mapbender/http/php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Sep 19 08:21:40 PDT 2016
Author: armin11
Date: 2016-09-19 08:21:40 -0700 (Mon, 19 Sep 2016)
New Revision: 9597
Modified:
trunk/mapbender/http/php/mod_transformTimeDimension.php
Log:
New possibility to handle big discrete wms time dimension extent values
Modified: trunk/mapbender/http/php/mod_transformTimeDimension.php
===================================================================
--- trunk/mapbender/http/php/mod_transformTimeDimension.php 2016-09-15 10:55:31 UTC (rev 9596)
+++ trunk/mapbender/http/php/mod_transformTimeDimension.php 2016-09-19 15:21:40 UTC (rev 9597)
@@ -104,6 +104,87 @@
$extent = $testMatch;
$testMatch = NULL;
}
+
+
+//function to find the nearest interval of array elements to a given array value
+//returns a value, if one special element is found or returns the smallest interval
+//from the ordered array elements in which element lies in
+function quicksearch($element, $searchArray) {
+ $numberOfValues = count($searchArray);
+ if ($numberOfValues == 2) {
+ return $searchArray;
+ }
+ while ($numberOfValues > 2) {
+ if ($element == $searchArray[ceil($numberOfValues / 2) - 1]) {
+ return $element; //return value is no array!
+ } else {
+ if ($element >= $searchArray[ceil($numberOfValues / 2) - 1]) {
+ $numberOfValues = count($searchArray);
+ if ($numberOfValues == 2) {
+ return $searchArrayNew;
+ }
+ $searchArrayNew = quicksearch($element, array_slice($searchArray, ceil($numberOfValues / 2) - 1));
+ } else {
+ $numberOfValues = count($searchArray);
+ if ($numberOfValues == 2) {
+ return $searchArray;
+ }
+ $searchArrayNew = quicksearch($element, array_slice($searchArray, 0, ceil($numberOfValues / 2)));
+ }
+ $numberOfValues = count($searchArrayNew);
+ if ($numberOfValues == 2) {
+ return $searchArrayNew;
+ }
+ }
+ }
+ return $searchArrayNew;
+}
+
+function getNearestValue($userValue, $discreteValues) {
+ $discreteDateTimes = array();
+ $numberOfValues = count($discreteValues);
+ $userValueDateTime = new DateTime($userValue);
+ //transform discrete strings to time
+ foreach ($discreteValues as $discreteValue) {
+ $discreteDateTimes[] = new DateTime($discreteValue);
+ }
+ //do quicksearch
+ //check if current value is less than first entry
+ if ($userValueDateTime <= $discreteDateTimes[0]) {
+ return ($discreteDateTimes[0]);
+ } else {
+ if ($userValueDateTime >= $discreteDateTimes[$numberOfValues-1]) {
+ return ($discreteDateTimes[$numberOfValues-1]);
+ } else {
+ //do a quicksearch in array
+ $result = quicksearch($userValueDateTime, $discreteDateTimes);
+ if (is_array($result) && count($result) == 2) {
+ //test the length of the interval
+ $diffTime1 = abs(interval2Seconds($result[0]->diff($userValueDateTime)));
+ $diffTime2 = abs(interval2Seconds($result[1]->diff($userValueDateTime)));
+ if ($diffTime1 > $diffTime2) {
+ return $result[1];
+ } else {
+ return $result[0];
+ }
+ } else {
+ //return value itself
+ return $result;
+ }
+ }
+ }
+}
+
+//function to convert a php datetime intervall to seconds
+function interval2Seconds($duration) {
+ 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);
+ }
+ return $seconds;
+}
+
//Variable for result object
$result->data = array();
//define default timezone:
@@ -112,50 +193,72 @@
$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:
- //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'));
- if ($fullYearExtent == true) {
- $result->data[0]->value = $newTime->format('Y');
+ //check for discrete values - if they exists - call a function to find next value - like quicksearch
+ if (strpos($extent,'/') === false) { //no intervall found in extent
+ $discreteValues = explode(',',$extent);
+ 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";
+ }
+ //ordered??? - define discrete values to be ordered !!
+ $newValue = getNearestValue($userValue, $discreteValues);
+ //$e = new mb_exception("newtime: ".$newTime->format('c'));
+ if ($fullYearExtent == true) {
+ $result->data[0]->value = $newValue->format('Y');
+ } else {
+ $result->data[0]->value = $newValue->format('c');
+ }
+ $result->result->error = false;
+ $result->result->message = "All done";
} else {
- $result->data[0]->value = $newTime->format('c');
+ $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:
+ //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'));
+ 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";
}
- $result->result->error = false;
- $result->result->message = "All done";
} else {
switch ($kindOfExtent) {
case "intervalWithDuration":
@@ -215,8 +318,9 @@
//$result->options->timeAxis->scale = 'minute';
//$result->options->timeAxis->step = 5;
//better do snapping in callback function!
- } else {
- //nothing
+ } else {
+ //set options to make a moving of value possible
+ $result->options->editable->updateTime = true;
}
} else {
$result->data[0]->id = 0;
@@ -252,7 +356,39 @@
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."!");
+ $extentArray = explode(',',$extent);
+ //abort("Number of discrete values: ".count(explode(',',$extent))." exeeds max allowed number for visualization of timeline: ".$maxEntries."!");
+ //todo
+ //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;
+ 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;
+ }
+ }
+ //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 {
+ //set options to make a moving of value possible
+ $result->options->editable->updateTime = true;
+ }
} else {
$extentArray = explode(',',$extent);
for ($i=0; $i < count($extentArray); $i++) {
@@ -260,11 +396,12 @@
$result->data[$i]->content = $extentArray[$i];
$result->data[$i]->start = $extentArray[$i];
}
+ $result->options->editable = false;
}
//use first and last entry as borders
$result->options->min = $extentArray[0];
$result->options->max = $extentArray[count($extentArray) - 1];
- $result->options->editable = false;
+ //$result->options->editable = false;
$result->result->error = false;
$result->result->message = "All done";
break;
More information about the Mapbender_commits
mailing list