1
|
<?php
|
2
|
require_once(dirname(__FILE__).'/../constants.inc.php');
|
3
|
class site_point {
|
4
|
|
5
|
|
6
|
private $base_dir;
|
7
|
private $name = false;
|
8
|
private $prefix = false;
|
9
|
private $params = false;
|
10
|
private $zooms;
|
11
|
|
12
|
public function __construct($dir) {
|
13
|
|
14
|
if (!is_dir($dir)) return;
|
15
|
$this->base_dir = $dir;
|
16
|
$dir_fd = opendir($this->base_dir);
|
17
|
|
18
|
while (false !== ($file = readdir($dir_fd))) {
|
19
|
|
20
|
if (preg_match('/(.*)_[0-9]+_[0-9]+_[0-9]+\.jpg$/', $file, $reg)) {
|
21
|
$this->prefix = $reg[1];
|
22
|
|
23
|
break;
|
24
|
}
|
25
|
}
|
26
|
closedir($dir_fd);
|
27
|
if ($this->prefix === false) return false;
|
28
|
$this->parse_and_cache_params();
|
29
|
}
|
30
|
|
31
|
public function params_path() {
|
32
|
return $this->base_dir.'/'.$this->prefix.'.params';
|
33
|
}
|
34
|
|
35
|
private function parse_and_cache_params() {
|
36
|
if (is_file($this->params_path())) {
|
37
|
$this->params = @parse_ini_file($this->params_path());
|
38
|
}
|
39
|
}
|
40
|
|
41
|
public function get_params() {
|
42
|
|
43
|
if (isset($this->params)) {
|
44
|
return $this->params;
|
45
|
} else {
|
46
|
return parse_and_cache_params();
|
47
|
}
|
48
|
}
|
49
|
|
50
|
public function save_params() {
|
51
|
$o = '';
|
52
|
$p = $this->get_params();
|
53
|
foreach ($this->get_params() as $k => $v) {
|
54
|
$o.= "$k = $v\n";
|
55
|
}
|
56
|
file_put_contents($this->params_path(), $o);
|
57
|
}
|
58
|
|
59
|
public function set_param($key, $value) {
|
60
|
$p = $this->get_params();
|
61
|
$this->params[$key] = $value;
|
62
|
if ($key == 'titre') {
|
63
|
$this->name = $value;
|
64
|
}
|
65
|
}
|
66
|
|
67
|
public function has_params(){
|
68
|
$p = $this->get_params();
|
69
|
return (isset($p['latitude'], $p['longitude'],
|
70
|
$p['altitude'], $p['titre']));
|
71
|
}
|
72
|
|
73
|
public function get_name() {
|
74
|
return basename($this->base_dir);
|
75
|
}
|
76
|
|
77
|
public function get_prefix() {
|
78
|
return $this->prefix;
|
79
|
}
|
80
|
|
81
|
public function get_magnifications() {
|
82
|
$dir_fd = opendir($this->base_dir);
|
83
|
while (false !== ($file = readdir($dir_fd))) {
|
84
|
|
85
|
if (preg_match('/(.*)_([0-9]+)_([0-9]+)_([0-9]+)\.jpg$/', $file, $reg)) {
|
86
|
$prefix = $reg[1];
|
87
|
if ($prefix == $this->prefix) {
|
88
|
$zoom = (int)$reg[2];
|
89
|
$posx = (int)$reg[3]+1;
|
90
|
$posy = (int)$reg[4]+1;
|
91
|
if (!isset($zoom_array[$zoom]['nx']) || $zoom_array[$zoom]['nx'] < $posx) $zoom_array[$zoom]['nx'] = $posx;
|
92
|
if (!isset($zoom_array[$zoom]['ny']) || $zoom_array[$zoom]['ny'] < $posy) $zoom_array[$zoom]['ny'] = $posy;
|
93
|
}
|
94
|
}
|
95
|
}
|
96
|
$this->zooms = $zoom_array;
|
97
|
return $this->zooms;
|
98
|
}
|
99
|
|
100
|
public function coordsToCap($lat, $lon, $alt) {
|
101
|
$params = $this->get_params();
|
102
|
if (!isset($params['latitude']) || !isset($params['longitude'])) return false;
|
103
|
$rt = 6371;
|
104
|
$alt1 = isset($params['altitude']) ? $params['altitude'] : $alt;
|
105
|
$lat1 = $params['latitude']*M_PI/180;
|
106
|
$lon1 = $params['longitude']*M_PI/180;
|
107
|
$alt2 = $alt;
|
108
|
$lat2 = $lat * M_PI/180;
|
109
|
$lon2 = $lon * M_PI/180;
|
110
|
|
111
|
$dLat = $lat2-$lat1;
|
112
|
$dLon = $lon2-$lon1;
|
113
|
|
114
|
$a = sin($dLat/2) * sin($dLat/2) + sin($dLon/2) * sin($dLon/2) * cos($lat1) * cos($lat2);
|
115
|
$angle = 2 * atan2(sqrt($a), sqrt(1-$a));
|
116
|
$d = $angle * $rt;
|
117
|
|
118
|
$y = sin($dLon)*cos($lat2);
|
119
|
$x = cos($lat1)*sin($lat2) - sin($lat1)*cos($lat2)*cos($dLon);
|
120
|
$cap = atan2($y, $x);
|
121
|
|
122
|
$e = atan2(($alt2 - $alt1)/1000 - $d*$d/(2*$rt), $d);
|
123
|
|
124
|
return array($d, $cap*180/M_PI, $e*180/M_PI);
|
125
|
}
|
126
|
|
127
|
public function get_url($cap=false, $ele=false) {
|
128
|
$o = sprintf('panorama.php?dir=%s&panorama=%s',
|
129
|
PANORAMA_FOLDER, $this->get_name());
|
130
|
if ($cap && $ele) {
|
131
|
$o .= sprintf("&to_cap=%.3f&to_ele=%.3f", $cap, $ele);
|
132
|
}
|
133
|
return $o;
|
134
|
}
|
135
|
|
136
|
public static function get($name) {
|
137
|
|
138
|
|
139
|
$pano_dir = PANORAMA_PATH.'/'.$name;
|
140
|
return new site_point($pano_dir);
|
141
|
}
|
142
|
|
143
|
public static function get_all() {
|
144
|
$panos = array_diff(scandir(PANORAMA_PATH), array('..', '.'));
|
145
|
$pano_instances = array();
|
146
|
foreach ($panos as $pano_name) {
|
147
|
$pano_instances[] = site_point::get($pano_name);
|
148
|
}
|
149
|
return $pano_instances;
|
150
|
}
|
151
|
}
|