You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
827 B

  1. <?php
  2. namespace OSM\Element\Member;
  3. use OSM\Element\Member\Member;
  4. use OSM\Point;
  5. class Way extends Member {
  6. public array $points = [];
  7. public function completeFromArray(array $array): static
  8. {
  9. $hasGeometry = isset($array['geometry']);
  10. if ($hasGeometry) {
  11. $items = $array['geometry'];
  12. foreach ($items as $item) {
  13. $point = Point::createFromArray($item);
  14. $this->points[] = $point;
  15. }
  16. }
  17. return $this;
  18. }
  19. public function getFirstPoint(): Point {
  20. return reset($this->points);
  21. }
  22. public function getLastPoint(): Point {
  23. return end($this->points);
  24. }
  25. public function reversePoints(): static {
  26. $this->points = array_reverse($this->points);
  27. return $this;
  28. }
  29. }