Projet

Général

Profil

Paste
Télécharger (2,83 ko) Statistiques
| Branche: | Révision:

root / class / site_point.class.php @ ed5e83c5

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
    $pfname = $this->base_dir.'/'.$this->prefix.'.params';
26
    if (is_file($pfname)) {
27
      $this->params = @parse_ini_file($pfname);
28
    } 
29
  }
30
  
31
  public function get_params() {
32
    return $this->params;
33
  }
34
  
35
  public function get_name() {
36
    return basename($this->base_dir);
37
  }
38

    
39
  public function get_prefix() {
40
    return $this->prefix;
41
  }
42
  
43
  public function get_magnifications() {
44
    $dir_fd = opendir($this->base_dir);
45
    while (false !== ($file = readdir($dir_fd))) {                // extraction des paramètres de grossissement par le serveur
46
       //echo $file;
47
       if (preg_match('/(.*)_([0-9]+)_([0-9]+)_([0-9]+)\.jpg$/', $file, $reg)) {
48
         $prefix = $reg[1];
49
         if ($prefix == $this->prefix) {
50
           $zoom = (int)$reg[2];
51
           $posx = (int)$reg[3]+1;
52
           $posy = (int)$reg[4]+1;
53
           if (!isset($zoom_array[$zoom]['nx']) || $zoom_array[$zoom]['nx'] < $posx) $zoom_array[$zoom]['nx'] = $posx;
54
           if (!isset($zoom_array[$zoom]['ny']) || $zoom_array[$zoom]['ny'] < $posy) $zoom_array[$zoom]['ny'] = $posy;
55
         }
56
       }
57
    }
58
    $this->zooms = $zoom_array;
59
    return $this->zooms;
60
  }
61

    
62
  public function coordsToCap($lat, $lon, $alt) {
63
    if (!isset($this->params['latitude']) || !isset($this->params['longitude'])) return false;
64
    $rt = 6371;  // Rayon de la terre
65
    $alt1 = isset($this->params['altitude']) ? $this->params['altitude'] : $alt;
66
    $lat1 = $this->params['latitude']*M_PI/180;
67
    $lon1 = $this->params['longitude']*M_PI/180;
68
    $alt2 = $alt;
69
    $lat2 = $lat * M_PI/180;
70
    $lon2 = $lon * M_PI/180;
71

    
72
    $dLat = $lat2-$lat1;
73
    $dLon = $lon2-$lon1; 
74
    
75
    $a = sin($dLat/2) * sin($dLat/2) + sin($dLon/2) * sin($dLon/2) * cos($lat1) * cos($lat2);  // 
76
    $angle = 2 * atan2(sqrt($a), sqrt(1-$a));
77
    $d = $angle * $rt;                    // distance du point en Kms
78
    
79
    $y = sin($dLon)*cos($lat2);
80
    $x = cos($lat1)*sin($lat2) - sin($lat1)*cos($lat2)*cos($dLon);
81
    $cap = atan2($y, $x);                 // cap pour atteindre le point en radians
82
    
83
    $e = atan2(($alt2 - $alt1)/1000 - $d*$d/(2*$rt), $d);  // angle de l'élévation en radians
84
    //    printf("%s, %s, %s, %s\n",$lat1, $this->params['latitude'], $lat, $dLat);
85
    return array($d, $cap*180/M_PI, $e*180/M_PI);   // les résultats sont en degrés
86
  }
87
  
88
}