Ejemplo n.º 1
0
 /**
  * Load data of search
  * 
  * Loads route data from overpass api.
  */
 public function getData()
 {
     // add GET to variables
     $this->variables = $_GET;
     //array of keys that should be requested
     $keys = array("ref", "network", "operator", "to", "from");
     // build link
     $query = '<query type="relation">';
     foreach ($keys as $key) {
         if (isset($this->variables[$key]) && $this->variables[$key]) {
             $query .= '<has-kv case="ignore" k="' . $key . '" regv="' . htmlspecialchars($this->variables[$key]) . '"/>';
         }
     }
     $query .= '<has-kv k="type" v="route"/><has-kv k="route" regv="train|tram|light_rail|subway"/></query><print/>';
     if (Overpass::sendRequest($query)) {
         $this->content = Overpass::$result;
         return true;
     } else {
         $this->error = Overpass::$error;
         return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * function to send request
  * @param String $query query for overpass api
  * @return boolean true when request successful
  */
 static function sendRequest($query)
 {
     $link = "http://overpass-api.de/api/interpreter?data=" . urlencode($query);
     // get data from overpass api
     $content = @file_get_contents($link);
     // explanation about status codes of the overpass api can be found here: http://overpass-api.de/command_line.html
     if (isset($http_response_header[0])) {
         $status_code = self::getStatusCode($http_response_header[0]);
         if ($status_code != 200) {
             if ($status_code == 400) {
                 self::$error = Lang::l_("Invalid Overpass API query.");
                 //log error to send a correct query next time:
                 $msg = "Invalid Overpass API request. Query: " . $query;
                 log_error($msg);
             } elseif ($status_code == 429) {
                 self::$error = Lang::l_("Too many requests to Overpass API at the same time.");
             } elseif ($status_code == 504) {
                 self::$error = Lang::l_("Overpass API currently overcrowded.");
             } else {
                 self::$error = Lang::l_("Unknown Error.");
                 //log error to show a proper error message next time:
                 $msg = "Unknown Error when requesting overpass api: " . $http_response_header[0] . " | URI: " . $link;
                 log_error($msg);
             }
             return false;
         }
     } else {
         self::$error = Lang::l_("Connection failed.");
         return false;
     }
     if (!$content) {
         self::$error = Lang::l_("Empty result.");
         return false;
     }
     self::$result = $content;
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Load data of route
  * 
  * Loads route data from overpass api, when not available yet.
  */
 public function getData()
 {
     if (isset($_POST["id"])) {
         $_GET["id"] = $_POST["id"];
         if (isset($_POST["train"])) {
             $_GET["train"] = $_POST["train"];
         }
     }
     // no id set
     if (!isset($_GET["id"])) {
         // show error
         return_error("no_id", "full");
         die;
     }
     // get route id
     $get_id = $_GET["id"];
     // id is not a valid number
     if (!is_numeric($get_id) || round($get_id) != $get_id) {
         // exception for user routes of the scheme 12345_0
         if (preg_match("/^[0-9]+[_][0-9]+\$/", $get_id)) {
             $file = "./osmdata/user" . $get_id . ".osm";
             if (file_exists($file)) {
                 $spl = preg_split("[_]", $get_id);
                 $this->id = $spl[0];
                 $this->filexml = $file;
                 $this->custom = true;
                 $this->custom_id = $get_id;
                 return;
             } else {
                 return_error("invalid_id", "full");
                 die;
             }
         }
         // show error
         return_error("invalid_id", "full");
         die;
     }
     // save id
     $this->id = $get_id;
     if (isset($_FILES["osmfile"])) {
         $uploaddir = './osmdata/';
         $uploadfile = $uploaddir . "user" . $this->id . "_";
         $i = 0;
         while (file_exists($uploadfile . $i . ".osm")) {
             $i++;
         }
         $uploadfile .= $i . ".osm";
         // try uploading file
         if (move_uploaded_file($_FILES['osmfile']['tmp_name'], $uploadfile)) {
             if (!@simplexml_load_file($uploadfile)) {
                 return_error("invalid_xml_file", "full");
                 unlink($uploadfile);
                 die;
             }
         } else {
             return_error("upload_error", "full");
             print_r($_FILES);
             log_error("File upload error:" . print_r($_FILES["osmfile"]["error"]));
             die;
         }
         $this->filexml = $uploadfile;
         $this->custom = true;
         $this->custom_id = $get_id . "_" . $i;
     } else {
         // build file name
         $file_name = "osmdata/data" . $this->id . ".osm";
         // check if data needs to be refreshed
         $refresh = true;
         // default value
         // relation was already loaded
         if (file_exists($file_name)) {
             // check age of data
             $this->filemtime = filemtime($file_name);
             // data is younger than 7 days
             if ($this->filemtime > time() - 7 * 24 * 60 * 60) {
                 $refresh = false;
             }
         }
         // forced refresh
         if (isset($_GET["rf"]) && $_GET["rf"] == "1") {
             $refresh = true;
         }
         if (isset($_GET["maxspeed"]) && $_GET["maxspeed"] > 0) {
             $this->vmz = $_GET["maxspeed"];
         }
         // get data from overpass-api when needed
         if ($refresh) {
             // build link to overpass api
             $overpass_query = "[out:xml];(relation(" . $get_id . ");rel(br););out;(relation(" . $get_id . ");>>;);out;";
             if (Overpass::sendRequest($overpass_query)) {
                 $this->refresh_success = true;
                 file_put_contents($file_name, Overpass::$result);
                 $this->filemtime = time();
             } else {
                 $this->refresh_success = false;
             }
         }
         $this->filexml = $file_name;
     }
 }
Ejemplo n.º 4
0
             // ami eléggé hanyag dolog,
             // mert lehet hogy nincs mind bent
             if ($element['type'] != 'node') {
                 continue;
             }
             if (!$osm->inBBOX($element['lat'], $element['lon'])) {
                 continue;
             }
             $id = $element['type'] . '#' . $element['id'];
             $display[$id] = true;
         }
     }
 }
 // friss adatokat töltünk le a befoglaló téglalapból
 if (!isset($params['noosm'])) {
     $overpass = Overpass::query($osm->bbox);
     $data = json_decode($overpass, true);
     if (is_array($data['elements'])) {
         $elements = array_merge($elements, $data['elements']);
     }
     // ezeket mind megjelenítjük majd
     foreach ($data['elements'] as $element) {
         $id = $element['type'] . '#' . $element['id'];
         $display[$id] = true;
     }
 }
 $osmsites = array();
 foreach ($elements as $element) {
     $id = $element['type'] . '#' . $element['id'];
     $osmsites[$id] = $element;
     $tags = $element['tags'];