public function set_values_from_point(lat_lng $point)
 {
     $this->OS6 = geometry::lat_long_to_os($point, 6);
     $this->OS8 = geometry::lat_long_to_os($point, 8);
     $this->WGS84_lat = $point->lat();
     $this->WGS84_lng = $point->lng();
     $osgb36 = gps_datums::convert($point, 'WGS84', 'OSGB36');
     $this->OSGB36_lat = $osgb36->lat();
     $this->OSGB36_lng = $osgb36->lng();
 }
Example #2
0
 public function add_flight()
 {
     $this->do_retrieve_from_id([], $_REQUEST['cid']);
     $coords = json_decode($this->coords);
     $form = new igc_upload_form();
     $form->file = $_REQUEST['path'];
     $form->coords = implode(';', array_map(function ($coord) {
         $point = new lat_lng($coord->lat, $coord->lon);
         return geometry::lat_long_to_os($point);
     }, $coords));
     $form->do_submit();
     $form = new igc_form();
     $form->vis_info = 'Flown in comp: ' . $this->type . ' Round ' . $this->round . ' Task ' . $this->task;
     $pilot = new pilot();
     $parts = explode(' ', $_REQUEST['name']);
     if ($pilot->do_retrieve([], ['where_equals' => ['name' => $_REQUEST['name']]]) || $pilot->do_retrieve([], ['where_equals' => ['name' => implode(' ', array_reverse($parts))]])) {
         $form->pid = $pilot->get_primary_key();
         $flight = new flight();
         if ($flight->do_retrieve([], ['where_equals' => ['pid' => $pilot->get_primary_key()], 'order' => 'date DESC'])) {
             $form->gid = $flight->gid;
             $form->cid = $flight->cid;
         }
     }
     ajax::update(node::create('div#second_form', [], $form->get_html()));
 }
Example #3
0
 public function set_task($coordinates)
 {
     $points = explode(';', $coordinates);
     $task = new defined_task();
     /**
      * @var $waypoints \classes\lat_lng[]
      */
     $waypoints = [];
     foreach ($points as &$a) {
         $point = \classes\geometry::os_to_lat_long($a);
         $waypoints[] = $point;
     }
     if (count($waypoints) == 3 && $waypoints[0]->get_distance_to($waypoints[2]) < 800) {
         $task->type = 'or';
         $task->title = 'Defined Out & Return';
         $task->ftid = $task::TYPE_OUT_AND_RETURN;
     } else {
         if (count($waypoints) == 4 && $waypoints[0]->get_distance_to($waypoints[3]) < 800) {
             $task->type = 'tr';
             $task->title = 'Defined Triangle';
             $task->ftid = $task::TYPE_TRIANGLE;
         } else {
             $task->type = 'go';
             $task->title = 'Open distance';
             $task->ftid = $task::TYPE_OPEN_DISTANCE;
         }
     }
     for ($i = 0; $i < count($waypoints) - 1; $i++) {
         $task->distance += $waypoints[$i]->get_distance_to($waypoints[$i + 1]);
     }
     return $task;
 }