Révision 7096d2f9
Ajouté par Jocelyn Dealande il y a environ 10 ans
class/site_point.class.php | ||
---|---|---|
2 | 2 |
require_once(dirname(__FILE__).'/../constants.inc.php'); |
3 | 3 |
require_once(dirname(__FILE__).'/utils.class.php'); |
4 | 4 |
require_once(dirname(__FILE__).'/GeoPoint.class.php'); |
5 |
require_once(dirname(__FILE__).'/Tile.class.php'); |
|
6 |
|
|
5 | 7 |
// |
6 | 8 |
class PanoramaFormatException extends Exception { |
7 | 9 |
/** If the files organization is not correct for a panorama, we can't let it go... |
... | ... | |
25 | 27 |
} |
26 | 28 |
|
27 | 29 |
public function params_path() { |
28 |
return $this->base_dir.'/'.$this->prefix.'.params'; |
|
30 |
return $this->base_dir.'/site.params'; |
|
31 |
} |
|
32 |
|
|
33 |
/** Look for a *.params file in the base_dir |
|
34 |
* |
|
35 |
* Tries first the site.params, then a globbing *.params. |
|
36 |
* |
|
37 |
* May be deprecated at a certain time (if we consider all files should be |
|
38 |
* named site.params) |
|
39 |
* |
|
40 |
* @returns false if not found, an abs path else. |
|
41 |
*/ |
|
42 |
private function look_for_params() { |
|
43 |
if (is_file($this->params_path())) { |
|
44 |
return $this->params_path(); |
|
45 |
} |
|
46 |
$matches = glob($this->base_dir.'/*.params'); |
|
47 |
if ($matches and count($matches) > 0) { |
|
48 |
return $matches[0]; |
|
49 |
} else { |
|
50 |
return false; |
|
51 |
} |
|
29 | 52 |
} |
30 | 53 |
|
31 | 54 |
public function tiles_url_prefix() { |
32 |
return PANORAMA_FOLDER.'/'.$this->prefix;
|
|
55 |
return PANORAMA_FOLDER; |
|
33 | 56 |
} |
34 | 57 |
|
35 | 58 |
public function tiles_path() { |
36 | 59 |
return $this->base_dir; |
37 | 60 |
} |
38 | 61 |
|
39 |
public function tiles_prefix() { |
|
40 |
return $this->base_dir.'/'.$this->get_prefix(); |
|
41 |
} |
|
42 |
|
|
43 | 62 |
private function parse_and_cache_params() { |
44 |
if (is_file($this->params_path())) { |
|
45 |
$params = parse_ini_file($this->params_path()); |
|
63 |
$params_path = $this->look_for_params(); |
|
64 |
|
|
65 |
if ($params_path) { |
|
66 |
$params = parse_ini_file($params_path); |
|
46 | 67 |
if ($params) { |
47 | 68 |
$this->params = $params; |
48 | 69 |
if (isset($params[self::$REF_KEY])) { |
... | ... | |
133 | 154 |
} |
134 | 155 |
|
135 | 156 |
public function get_magnifications() { |
136 |
$dir_fd = opendir($this->base_dir); |
|
157 |
//$dir_fd = opendir($this->base_dir);
|
|
137 | 158 |
$zoom_array = array(); |
138 |
while (false !== ($file = readdir($dir_fd))) { // extraction des paramètres de grossissement par le serveur |
|
139 |
//echo $file; |
|
140 |
if (preg_match('/(.*)_([0-9]+)_([0-9]+)_([0-9]+)\.jpg$/', $file, $reg)) { |
|
141 |
$prefix = $reg[1]; |
|
142 |
if ($prefix == $this->prefix) { |
|
143 |
$zoom = (int)$reg[2]; |
|
144 |
$posx = (int)$reg[3]+1; |
|
145 |
$posy = (int)$reg[4]+1; |
|
146 |
if (!isset($zoom_array[$zoom]['nx']) || $zoom_array[$zoom]['nx'] < $posx) $zoom_array[$zoom]['nx'] = $posx; |
|
147 |
if (!isset($zoom_array[$zoom]['ny']) || $zoom_array[$zoom]['ny'] < $posy) $zoom_array[$zoom]['ny'] = $posy; |
|
148 |
} |
|
149 |
} |
|
150 |
} |
|
159 |
|
|
160 |
// extraction des paramètres de grossissement par le serveur |
|
161 |
$stop = false; |
|
162 |
$zoom_level = 0; |
|
163 |
|
|
164 |
while (! $stop) { |
|
165 |
$files = glob(sprintf('%s/%03d_*.jpg', $this->base_dir, $zoom_level)); |
|
166 |
sort($files); |
|
167 |
$last_file = end($files); |
|
168 |
if ($last_file) { |
|
169 |
$last_tile = Tile::from_file($last_file, $this); |
|
170 |
$zoom_array[$zoom_level] = array('nx' => $last_tile->x + 1, |
|
171 |
'ny' => $last_tile->y + 1); |
|
172 |
$zoom_level++; |
|
173 |
} else { |
|
174 |
$stop = true; |
|
175 |
} |
|
176 |
} |
|
151 | 177 |
$this->zooms = $zoom_array; |
152 | 178 |
return $this->zooms; |
153 | 179 |
} |
Formats disponibles : Unified diff
Refacto of Tiles handling and simplified a bit file naming for tiles/params.
By the way, fixes #297
THIS COMMIT BREAKS FILE LAYOUT AND REQUIRES MIGRATION (SEE BELLOW).
To migrate data :
cd tiles
find . '*.jpg' -exec rename 's/[^\/]*_(([0-9]{3}_){2}([0-9]{3}))/$1/' {} \;
rename 's/(.*\/).*\.params/$1site.params/' */*.params