Projet

Général

Profil

Révision ffebe856

Ajouté par Jocelyn Dealande il y a environ 10 ans

do not display ref_points and panorama further than 25km from the current one (tunable in constant)

Voir les différences:

class/GeoPoint.class.php
1
<?php
2
require_once(dirname(__FILE__).'/utils.class.php');
3

  
4
interface LatLon {
5
  public function get_lat();
6
  public function get_lon();
7
}
8

  
9
interface Collection {
10
  public static function get_all();
11
}
12

  
13
abstract class GeoPoint implements LatLon, Collection {
14
  /**  distance, by Vincenty formula
15
       see http://stackoverflow.com/a/10054282
16
   */
17
  public function distance($other_point) {
18
    $earthRadius = 6371;
19

  
20
	// convert from degrees to radians
21
	$latFrom = deg2rad($this->get_lat());
22
	$lonFrom = deg2rad($this->get_lon());
23
	$latTo = deg2rad($other_point->get_lat());
24
	$lonTo = deg2rad($other_point->get_lon());
25

  
26
	$lonDelta = $lonTo - $lonFrom;
27
	$a = pow(cos($latTo) * sin($lonDelta), 2) +
28
	  pow(cos($latFrom) * sin($latTo) -
29
      sin($latFrom) * cos($latTo) * cos($lonDelta), 2);
30
	$b = sin($latFrom) * sin($latTo) +
31
      cos($latFrom) * cos($latTo) * cos($lonDelta);
32

  
33
	$angle = atan2(sqrt($a), $b);
34
	return $angle * $earthRadius;
35
  }
36

  
37
  /** Gets only the points in a circle of $distance km arround $opint
38

  
39
     @param $target a LatLon
40
   */
41
  public static function near_points($target, $distance) {
42
    $near_points = array();
43
    foreach (static::get_all() as $point) {
44
      if ($point->distance($target) < $distance) {
45
        $near_points[] = $point;
46
      }
47
    }
48
    return $near_points;
49
  }
50
}
51
?>
class/RefPoint.class.php
1 1
<?php
2 2
require_once(dirname(__FILE__).'/../constants.inc.php');
3

  
3
require_once(dirname(__FILE__).'/GeoPoint.class.php');
4 4
//
5
class RefPoint {
5
class RefPoint extends GeoPoint {
6 6
  static $all_ref_points_cache;
7 7
  public $name;
8 8
  public $lon;
......
16 16
    $this->ele = $values[2];
17 17
  }
18 18

  
19
  public function get_lat() {
20
    return $this->lat;
21
  }
22

  
23
  public function get_lon() {
24
    return $this->lon;
25
  }
26

  
19 27
  public static function load_if_needed() {
20 28
    if (!isset(self::$all_ref_points_cache)) {
21 29
      if (file_exists(REF_POINTS_PATH)) {
class/site_point.class.php
1 1
<?php
2 2
require_once(dirname(__FILE__).'/../constants.inc.php');
3 3
require_once(dirname(__FILE__).'/utils.class.php');
4
require_once(dirname(__FILE__).'/GeoPoint.class.php');
4 5
//
5 6
class PanoramaFormatException extends Exception {
6 7
	/** If the files organization is not correct for a panorama, we can't let it go...
7 8
	 */
8 9
}
9 10

  
10
class site_point {
11
class site_point extends GeoPoint {
11 12
  /** Defines a point, with a panorama
12 13
  */
13 14
  private $base_dir;        // dir of tiles for that panorama
......
121 122
    return $this->prefix;
122 123
  }
123 124

  
125
  public function get_lat() {
126
	$p = $this->get_params();
127
	return $p['latitude'];
128
  }
129

  
130
  public function get_lon() {
131
	$p = $this->get_params();
132
	return $p['longitude'];
133
  }
134

  
124 135
  public function get_magnifications() {
125 136
    $dir_fd = opendir($this->base_dir);
126 137
    $zoom_array = array();
......
288 299
  }
289 300

  
290 301

  
291
  public static function get_all($only_with_params=false) {
302
  public static function get_all($only_with_params=true) {
292 303
	  /**
293 304
	   * @param $only_with_params : filters out the panoramas which
294 305
	   *        are not parametrized
class/utils.class.php
90 90
    header("Location: http://$host$uri/$extra");
91 91
  }
92 92
}
93

  
94 93
?>
constants.inc.php
3 3
define('PANORAMA_FOLDER', 'tiles' );
4 4
define('PANORAMA_PATH', CELUTZ_PATH.'/'.PANORAMA_FOLDER );
5 5
define('UPLOAD_PATH', CELUTZ_PATH.'/upload' );
6
// Do not display points further than that (in kms)
7
define('MAX_SEEING_DISTANCE', 25);
6 8
define('REF_POINTS_PATH', CELUTZ_PATH.'/'.'ref_points.local.php');
7 9
?>
index.php
24 24

  
25 25
$dir = new sites_dir($base_dir);
26 26
try {
27
  $sites_list = site_point::get_all();
27
  $sites_list = site_point::get_all(false);
28 28

  
29 29
  echo "<ul id=\"pano-list\">\n";
30 30

  
panorama.php
12 12
    'to_ele'     => array('numeric'),
13 13
    'to_zoom'     => array('numeric')
14 14
  );
15
  
15

  
16 16
  $validator = new FormValidator($fields_spec);
17 17
  $is_valid = $validator->validate($_GET);
18
  
18

  
19 19
  if ($is_valid) {
20 20
    $input = $validator->sane_values();
21 21
  } else {
22 22
    $validator->print_errors();
23 23
    die();//fixme, could be cleaner
24 24
  }
25
  
25

  
26 26
   $form_extpoint = file_get_contents('html/form_extpoint.html');
27 27

  
28 28
   $form_param = file_get_contents('html/form_param.html');
......
57 57
     printf ("var img_prefix = '%s/%s';\n", $base_dir, $prefix);
58 58
     if (is_array($params)) $opt_vals = array_merge($params, $opt_vals);
59 59
     foreach(array('to_cap', 'to_ele', 'to_zoom', 'image_loop') as $val) {
60
        if (isset($opt_vals[$val])) 
60
        if (isset($opt_vals[$val]))
61 61
        printf ('var '.$val.' = '.utils::php2ini($opt_vals[$val]).";\n"); // correction du décalage angulaire par rapport au Nord
62 62
     }
63 63
  ?>
......
83 83
   $dir_list = new sites_dir($dir);
84 84

  
85 85
   $ipt = 0;
86
  foreach(site_point::get_all() as $opt) {
86
   foreach(site_point::near_points($pt, MAX_SEEING_DISTANCE) as $opt) {
87 87
     $prm = $opt->get_params();
88 88
     $oname = $opt->get_name();
89 89
     if (($oname != $name) && $opt->has_params()) {
......
94 94
     }
95 95
   }
96 96

  
97
   $ref_points = RefPoint::get_all();
98 97
   $extra_names = array();
99 98
   $ref_names = array();
100
   foreach ($ref_points as $ref) {
99
   foreach (RefPoint::near_points($pt, MAX_SEEING_DISTANCE) as $ref) {
101 100
     $extra_names[] = $ref->name;
102 101
     list($dist, $cap, $ele) = $pt->coordsToCap($ref->lon, $ref->lat,
103 102
                                                $ref->ele);

Formats disponibles : Unified diff