Projet

Général

Profil

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

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

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

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

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

    
67
    $dLat = $lat2-$lat1;
68
    $dLon = $lon2-$lon1;
69
    
70
    $a = sin($dLat/2) * sin($dLat/2) + sin($dLon/2) * sin($dLon/2) * cos($lat1) * cos($lat2); 
71
    $angle = 2 * atan2(sqrt($a), sqrt(1-$a));
72
    $d = $angle * $rt;                    // distance du point en Kms
73
    
74
    $y = sin($dLon)*cos($lat2);
75
    $x = cos($lat1)*sin($lat2) - sin($lat1)*cos($lat2)*cos($dLon);
76
    $cap = atan2($y, $x);                 // cap pour atteindre le point en radians
77

    
78
    $e = atan2(($alt2 - $alt1)/1000 - $d*$d/(2*$rt), $d);  // angle de l'élévation en radians
79
    //    printf("%s, %s, %s, %s\n",$lat1, $this->params['latitude'], $lat, $dLat);
80

    
81
    return array($d, $cap*180/M_PI, $e*180/M_PI);   // les résultats sont en degrés
82
  }
83
  
84
}