5 * Copyright 2018 Andy Street <andy@street.me.uk>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 use \DateTimeInterface;
32 * @see https://www.topografix.com/gpx.asp
34 * @author Andy Street <andy@street.me.uk>
36 class GPX implements Geographic
40 * The program that created the GPX file.
47 * The name of the GPX file.
54 * A description of the contents of the GPX file.
61 * The person or organization who created the GPX file.
68 * Copyright and license information governing use of the file.
75 * Links to other resources that describe this GPX file.
79 protected $links = [];
82 * The creation time of the file.
84 * @var DateTimeInterface
89 * A list of keywords classifying this GPX file.
93 protected $keywords = [];
96 * Fetch the name of the program that created the GPX file.
98 * @return string|null The creator or null if not set.
100 public function getCreator()
102 return $this->creator;
106 * Set the name of the program that created the GPX file.
108 * @param string|null $creator The program name or null to delete.
111 public function setCreator(string $creator = null)
113 $this->creator = $creator;
117 * Fetch the file name.
119 * @return string|null The name or null if not set.
121 public function getName()
127 * Set the name of the file.
129 * @param string|null $name The file name or null to delete.
132 public function setName(string $name = null)
138 * Fetch the description of the file.
140 * @return string|null The description or null if not set.
142 public function getDesc()
148 * Set the description of the file.
150 * @param string|null $desc The description or null to delete.
153 public function setDesc(string $desc = null)
159 * Fetch the author of the file.
161 * @return Person|null The author or null if not set.
163 public function getAuthor()
165 return $this->author;
169 * Set the author of the file.
171 * @param Person|null $author The author or null to delete.
174 public function setAuthor(Person $author = null)
176 $this->author = $author;
180 * Fetch the copyright details for the file.
182 * @return Copyright|null The copyright or null if not set.
184 public function getCopyright()
186 return $this->copyright;
190 * Set the copyright details for the file.
192 * @param Copyright|null $copyright The copyright detail or null to delete.
195 public function setCopyright(Copyright $copyright = null)
197 $this->copyright = $copyright;
201 * Fetch links to other resources.
205 public function getLinks()
211 * Add a link to an related resource.
213 * @param Link $link The link to add.
216 public function addLink(Link $link)
218 if (!in_array($link, $this->links, true))
219 $this->links[] = $link;
223 * Remove an existing link from the list.
225 * @param Link $link The link to remove.
228 public function removeLink(Link $link)
230 $key = array_search($link, $this->links, true);
232 unset($this->links[$key]);
236 * Fetch the time the GPX file was created.
238 * @return DateTimeInterface|null A timestamp or null if not set.
240 public function getTime()
246 * Set the time at which the file was created.
248 * @param DateTimeInterface $time The creation time or null to delete.
250 public function setTime(DateTimeInterface $time = null)
256 * Fetch a list of keywords for this GPX file.
258 * @return string[] The keywords
260 public function getKeywords()
262 return $this->keywords;
266 * Add a keyword for this GPX file.
268 * @param string $keyword The keyword to add.
271 public function addKeyword(string $keyword)
273 if (!in_array($keyword, $this->keywords))
274 $this->keywords[] = $keyword;
278 * Remove an existing keyword from the list.
280 * @param string $keyword The keyword to remove.
283 public function removeKeyword(string $keyword)
285 $key = array_search($keyword, $this->keywords);
287 unset($this->keywords[$key]);
291 * Fetch a bounding box that covers the feature.
293 * @return Bounds|null A bounding box covering the extent of the feature or
294 * null if not applicable.
296 public function getBounds()
298 //TODO: Implement this properly when waypoints, routes and tracks have