<?php
require_once(dirname(__FILE__).'/../constants.inc.php');
require_once(dirname(__FILE__).'/GeoPoint.class.php');
//
class RefPoint extends GeoPoint {
  static $all_ref_points_cache;
  public $name;
  public $lon;
  public $lat;
  public $ele;

  public function __construct($name, $values) {
    $this->name = $name;
    $this->lat = $values[0];
    $this->lon = $values[1];
    $this->ele = $values[2];
  }

  public function get_lat() {
    return $this->lat;
  }

  public function get_name() {
    return $this->name;
  }

  public function get_lon() {
    return $this->lon;
  }

  public static function load_if_needed() {
    if (!isset(self::$all_ref_points_cache)) {
      if (file_exists(REF_POINTS_PATH)) {
        require(REF_POINTS_PATH);
        self::$all_ref_points_cache = $ref_points;
        return $ref_points;
      } else {
        return array();
      }
    }
   return self::$all_ref_points_cache;
  }

  public static function get_all() {
    self::load_if_needed();
    $ref_points_objs = array();
    foreach (self::$all_ref_points_cache as $name => $vals) {
      $ref_points_objs[] = new RefPoint($name, $vals);
    }
    return $ref_points_objs;
  }

  public static function get($name) {
    self::load_if_needed();
    $values = self::$all_ref_points_cache[$name];
    return new RefPoint($name, $values);
  }

}
?>
