Projet

Général

Profil

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

root / class / site_point.class.php @ 7f9aab46

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
    $this->base_dir = $dir;
11
    $dir_fd = opendir($this->base_dir);
12
  
13
    while (false !== ($file = readdir($dir_fd))) {
14
            
15
       if (preg_match('/(.*)_[0-9]+_[0-9]+_[0-9]+\.jpg$/', $file, $reg)) {
16
         $this->prefix = $reg[1];
17
         
18
         break;
19
       }
20
    }
21
    closedir($dir_fd);
22
    if ($this->prefix === false) return false;
23
    $pfname = $this->base_dir.'/'.$this->prefix.'.params';
24
    if (is_file($pfname)) {
25
      $this->params = @parse_ini_file($pfname);
26
    } 
27
  }
28
  
29
  public function get_params() {
30
    return $this->params;
31
  }
32
  
33
  public function get_name() {
34
    return basename($this->base_dir);
35
  }
36

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

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

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