Projet

Général

Profil

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

root / class / site_point.class.php @ 1aebc2ec

1
<?php
2
require_once(dirname(__FILE__).'/../constants.inc.php');
3
class site_point {
4
        /** Defines a point, with a panorama
5
         */
6
        private $base_dir;        // dir of tiles for that panorama
7
  private $name = false;
8
  private $prefix = false;
9
  private $params = false;
10
  private $zooms;
11

    
12
  public function __construct($dir) {
13
    // si $dir n'est pas un répertoire il ne s'agit pas d'un panorama.
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_store_params();
29
  }
30

    
31
  private function params_path() {
32
          return $this->base_dir.'/'.$this->prefix.'.params';
33
  }
34

    
35
  private function parse_and_store_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
          // the params are cached
43
          if (isset($this->params)) {
44
                  return $this->params;
45
          } else {
46
                  return parse_and_store_params();
47
          }
48
  }
49

    
50
  public function has_params(){
51
          $p = $this->get_params();
52
          return (isset($prm['latitude'], $prm['longitude'],
53
                        $prm['altitude'], $prm['titre']))
54
  }
55
   if ($oname != $name && ) {
56

    
57

    
58
  public function get_name() {
59
    return basename($this->base_dir);
60
  }
61

    
62
  public function get_prefix() {
63
    return $this->prefix;
64
  }
65

    
66
  public function get_magnifications() {
67
    $dir_fd = opendir($this->base_dir);
68
    while (false !== ($file = readdir($dir_fd))) {                // extraction des paramètres de grossissement par le serveur
69
       //echo $file;
70
       if (preg_match('/(.*)_([0-9]+)_([0-9]+)_([0-9]+)\.jpg$/', $file, $reg)) {
71
         $prefix = $reg[1];
72
         if ($prefix == $this->prefix) {
73
           $zoom = (int)$reg[2];
74
           $posx = (int)$reg[3]+1;
75
           $posy = (int)$reg[4]+1;
76
           if (!isset($zoom_array[$zoom]['nx']) || $zoom_array[$zoom]['nx'] < $posx) $zoom_array[$zoom]['nx'] = $posx;
77
           if (!isset($zoom_array[$zoom]['ny']) || $zoom_array[$zoom]['ny'] < $posy) $zoom_array[$zoom]['ny'] = $posy;
78
         }
79
       }
80
    }
81
    $this->zooms = $zoom_array;
82
    return $this->zooms;
83
  }
84

    
85
  public function coordsToCap($lat, $lon, $alt) {
86
    $params = $this->get_params();
87
    if (!isset($params['latitude']) || !isset($params['longitude'])) return false;
88
    $rt = 6371;  // Rayon de la terre
89
    $alt1 = isset($params['altitude']) ? $params['altitude'] : $alt;
90
    $lat1 = $params['latitude']*M_PI/180;
91
    $lon1 = $params['longitude']*M_PI/180;
92
    $alt2 = $alt;
93
    $lat2 = $lat * M_PI/180;
94
    $lon2 = $lon * M_PI/180;
95

    
96
    $dLat = $lat2-$lat1;
97
    $dLon = $lon2-$lon1;
98

    
99
    $a = sin($dLat/2) * sin($dLat/2) + sin($dLon/2) * sin($dLon/2) * cos($lat1) * cos($lat2);  //
100
    $angle = 2 * atan2(sqrt($a), sqrt(1-$a));
101
    $d = $angle * $rt;                    // distance du point en Kms
102

    
103
    $y = sin($dLon)*cos($lat2);
104
    $x = cos($lat1)*sin($lat2) - sin($lat1)*cos($lat2)*cos($dLon);
105
    $cap = atan2($y, $x);                 // cap pour atteindre le point en radians
106

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

    
112
  public function get_url() {
113
          return sprintf('panorama.php?dir=%s&amp;panorama=%s',
114
                         'tiles', $this->get_name());
115
  }
116

    
117
  public static function get($name) {
118
          /** Instantiate a site_point, given its name
119
           */
120
          $pano_dir = PANORAMA_PATH.'/'.$name;
121
          return new site_point($pano_dir);
122
  }
123

    
124
  public static function get_all() {
125
          $panos = array_diff(scandir(PANORAMA_PATH), array('..', '.'));
126
          $pano_instances = array();
127
          foreach ($panos as $pano_name) {
128
                  $pano_instances[] = site_point::get($pano_name);
129
          }
130
          return $pano_instances;
131
  }
132
}