Projet

Général

Profil

Paste
Télécharger (3,18 ko) Statistiques
| Branche: | Révision:

root / class / site_point.class.php @ 405ba17b

1
<?php
2
class site_point {
3
  private $base_dir;
4
  private $name = false;
5
  private $prefix = false;
6
  private $params = false;
7
  private $zooms;
8

    
9
  public function __construct($dir) {
10
    // si $dir n'est pas un répertoire il ne s'agit pas d'un panorama.
11
    if (!is_dir($dir)) return;
12
    $this->base_dir = $dir;
13
    $dir_fd = opendir($this->base_dir);
14

    
15
    while (false !== ($file = readdir($dir_fd))) {
16

    
17
       if (preg_match('/(.*)_[0-9]+_[0-9]+_[0-9]+\.jpg$/', $file, $reg)) {
18
         $this->prefix = $reg[1];
19

    
20
         break;
21
       }
22
    }
23
    closedir($dir_fd);
24
    if ($this->prefix === false) return false;
25
    $this->parse_and_store_params();
26
  }
27

    
28
  private function params_path() {
29
          return $this->base_dir.'/'.$this->prefix.'.params';
30
  }
31

    
32
  private function parse_and_store_params() {
33
    if (is_file($this->params_path())) {
34
            $this->params = @parse_ini_file($this->params_path());
35
    }
36
  }
37

    
38
  public function get_params() {
39
          // the params are cached
40
          if (isset($this->params)) {
41
                  return $this->params;
42
          } else {
43
                  return parse_and_store_params();
44
          }
45
  }
46

    
47
  public function get_name() {
48
    return basename($this->base_dir);
49
  }
50

    
51
  public function get_prefix() {
52
    return $this->prefix;
53
  }
54

    
55
  public function get_magnifications() {
56
    $dir_fd = opendir($this->base_dir);
57
    while (false !== ($file = readdir($dir_fd))) {                // extraction des paramètres de grossissement par le serveur
58
       //echo $file;
59
       if (preg_match('/(.*)_([0-9]+)_([0-9]+)_([0-9]+)\.jpg$/', $file, $reg)) {
60
         $prefix = $reg[1];
61
         if ($prefix == $this->prefix) {
62
           $zoom = (int)$reg[2];
63
           $posx = (int)$reg[3]+1;
64
           $posy = (int)$reg[4]+1;
65
           if (!isset($zoom_array[$zoom]['nx']) || $zoom_array[$zoom]['nx'] < $posx) $zoom_array[$zoom]['nx'] = $posx;
66
           if (!isset($zoom_array[$zoom]['ny']) || $zoom_array[$zoom]['ny'] < $posy) $zoom_array[$zoom]['ny'] = $posy;
67
         }
68
       }
69
    }
70
    $this->zooms = $zoom_array;
71
    return $this->zooms;
72
  }
73

    
74
  public function coordsToCap($lat, $lon, $alt) {
75
    $params = $this->get_params();
76
    if (!isset($params['latitude']) || !isset($params['longitude'])) return false;
77
    $rt = 6371;  // Rayon de la terre
78
    $alt1 = isset($params['altitude']) ? $params['altitude'] : $alt;
79
    $lat1 = $params['latitude']*M_PI/180;
80
    $lon1 = $params['longitude']*M_PI/180;
81
    $alt2 = $alt;
82
    $lat2 = $lat * M_PI/180;
83
    $lon2 = $lon * M_PI/180;
84

    
85
    $dLat = $lat2-$lat1;
86
    $dLon = $lon2-$lon1;
87

    
88
    $a = sin($dLat/2) * sin($dLat/2) + sin($dLon/2) * sin($dLon/2) * cos($lat1) * cos($lat2);  //
89
    $angle = 2 * atan2(sqrt($a), sqrt(1-$a));
90
    $d = $angle * $rt;                    // distance du point en Kms
91

    
92
    $y = sin($dLon)*cos($lat2);
93
    $x = cos($lat1)*sin($lat2) - sin($lat1)*cos($lat2)*cos($dLon);
94
    $cap = atan2($y, $x);                 // cap pour atteindre le point en radians
95

    
96
    $e = atan2(($alt2 - $alt1)/1000 - $d*$d/(2*$rt), $d);  // angle de l'élévation en radians
97
    //    printf("%s, %s, %s, %s\n",$lat1, $params['latitude'], $lat, $dLat);
98
    return array($d, $cap*180/M_PI, $e*180/M_PI);   // les résultats sont en degrés
99
  }
100

    
101
  public function get_url() {
102
          return sprintf('panorama.php?dir=%s&amp;panorama=%s',
103
                         'tiles', $this->get_name());
104
  }
105
}