Revision c5f89cd9
ID | c5f89cd96d5b4c01edb3c7213fa490b6fa3d7c1a |
Parent | e68abb6a |
Child | ea08a2a7 |
webservice to reference ref_points is ready
Files
- added
- modified
- copied
- renamed
- deleted
Changesets
ajax/add_reference.php | ||
---|---|---|
6 | 6 |
$fields_spec = array('x' => array('required', 'numeric', 'positive'), |
7 | 7 |
'y' => array('required', 'numeric', 'positive'), |
8 | 8 |
'panorama' => array('required'), |
9 |
'ref_point' => array('required')); |
|
9 |
'ref_point' => array('required'), |
|
10 |
); |
|
10 | 11 |
|
11 | 12 |
|
12 | 13 |
$validator = new FormValidator($fields_spec); |
... | ... | |
14 | 15 |
$vals = $validator->sane_values(); |
15 | 16 |
|
16 | 17 |
// temp test code |
17 |
echo '<h1>pano !</h1>'; |
|
18 | 18 |
$pano = site_point::get($vals['panorama']); |
19 |
var_dump($pano->get_params()); |
|
20 | 19 |
|
21 |
echo '<h1>ref point !</h1>'; |
|
22 | 20 |
$ref_point_name = urldecode($vals['ref_point']); |
23 |
var_dump(RefPoint::get($ref_point_name)); |
|
21 |
$ref_point = RefPoint::get($ref_point_name); |
|
22 |
|
|
23 |
$pano->set_reference($ref_point, $vals['x'], $vals['y']); |
|
24 |
$pano->save_params(); |
|
24 | 25 |
|
25 | 26 |
} else { |
27 |
// Set our response code |
|
28 |
http_response_code(400); |
|
26 | 29 |
echo var_dump($validator->errors()); |
27 | 30 |
} |
28 | 31 |
|
class/RefPoint.class.php | ||
---|---|---|
4 | 4 |
// |
5 | 5 |
class RefPoint { |
6 | 6 |
static $all_ref_points_cache; |
7 |
public $name; |
|
8 |
public $lon; |
|
9 |
public $lat; |
|
10 |
public $ele; |
|
11 |
|
|
12 |
public function __construct($name, $values) { |
|
13 |
$this->name = $name; |
|
14 |
$this->lon = $values[0]; |
|
15 |
$this->lat = $values[1]; |
|
16 |
$this->ele = $values[2]; |
|
17 |
} |
|
7 | 18 |
|
8 | 19 |
public static function load_if_needed() { |
9 | 20 |
if (!isset(self::$all_ref_points_cache)) { |
... | ... | |
21 | 32 |
|
22 | 33 |
public static function get($name) { |
23 | 34 |
self::load_if_needed(); |
24 |
return self::$all_ref_points_cache[$name]; |
|
35 |
$values = self::$all_ref_points_cache[$name]; |
|
36 |
return new RefPoint($name, $values); |
|
25 | 37 |
} |
26 | 38 |
|
27 | 39 |
} |
class/site_point.class.php | ||
---|---|---|
16 | 16 |
private $params = false; |
17 | 17 |
private $zooms; |
18 | 18 |
|
19 |
public static $REF_KEY = 'reference'; |
|
20 |
|
|
19 | 21 |
public function __construct($dir) { |
20 | 22 |
$this->base_dir = $dir; |
21 | 23 |
$this->prefix = basename($dir); |
... | ... | |
57 | 59 |
$o = ''; |
58 | 60 |
$p = $this->get_params(); |
59 | 61 |
foreach ($this->get_params() as $k => $v) { |
60 |
$o.= "$k = $v\n"; |
|
62 |
if ($k == self::$REF_KEY) { |
|
63 |
foreach ($v as $refk => $refv) { |
|
64 |
$o.= sprintf("%s[\"%s\"] = %.5f,%.5f\n", |
|
65 |
self::$REF_KEY, $refk, |
|
66 |
$refv[0], $refv[1]); |
|
67 |
} |
|
68 |
} else { |
|
69 |
$o.= "$k = $v\n"; |
|
70 |
} |
|
61 | 71 |
} |
62 | 72 |
file_put_contents($this->params_path(), $o); |
63 | 73 |
} |
... | ... | |
140 | 150 |
return $o; |
141 | 151 |
} |
142 | 152 |
|
153 |
public function set_reference($ref_point, $x, $y) { |
|
154 |
/** |
|
155 |
* Registers (for saving) the position of a reference point within a |
|
156 |
* panorama. It sets or overwrite a reference. |
|
157 |
* |
|
158 |
* @param $ref_point a RefPoint instance |
|
159 |
* @param $x the relative x position of the RefPoint |
|
160 |
* @param $x the relative y position of the RefPoint |
|
161 |
*/ |
|
162 |
$p = $this->get_params(); |
|
163 |
|
|
164 |
if (!isset($this->params[self::$REF_KEY]) || |
|
165 |
!is_array($this->params[self::$REF_KEY])) { |
|
166 |
$this->params[self::$REF_KEY] = array(); |
|
167 |
} |
|
168 |
$ref_name = $ref_point->name; |
|
169 |
$dict = $this->params[self::$REF_KEY]; |
|
170 |
//$dddd = $this->params[self::$REF_KEY][$ref_name]; |
|
171 |
$this->params[self::$REF_KEY][$ref_name] = array($x, $y); |
|
172 |
} |
|
173 |
|
|
143 | 174 |
public static function get($name) { |
144 | 175 |
/** Instantiate a site_point, given its name |
145 | 176 |
*/ |