|
|
@ -2,50 +2,53 @@ |
|
|
|
|
|
|
|
namespace OSM\Element; |
|
|
|
|
|
|
|
use OSM\Element\Element; |
|
|
|
use OSM\Element\Member\Way; |
|
|
|
use OSM\Point; |
|
|
|
|
|
|
|
class Relation extends Element { |
|
|
|
|
|
|
|
public function getOuterWays(): array { |
|
|
|
class Relation extends Element |
|
|
|
{ |
|
|
|
public function getOuterWays(): array |
|
|
|
{ |
|
|
|
return array_filter($this->members, function ($member) { |
|
|
|
return ( |
|
|
|
($member instanceof \OSM\Element\Member\Way) |
|
|
|
and ($member->role === 'outer') |
|
|
|
); |
|
|
|
return |
|
|
|
($member instanceof Way) |
|
|
|
and ('outer' === $member->role) |
|
|
|
; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public function getOuterWaysStartingWith(Point $point, ?Way $exclude = null): array { |
|
|
|
public function getOuterWaysStartingWith(Point $point, ?Way $exclude = null): array |
|
|
|
{ |
|
|
|
return array_filter($this->members, function ($member) use ($point, $exclude) { |
|
|
|
return ( |
|
|
|
($member instanceof \OSM\Element\Member\Way) |
|
|
|
and ($member->role === 'outer') |
|
|
|
and ($point->isSame($member->getFirstPoint())) |
|
|
|
return |
|
|
|
($member instanceof Way) |
|
|
|
and ('outer' === $member->role) |
|
|
|
and $point->isSame($member->getFirstPoint()) |
|
|
|
and ( |
|
|
|
is_null($exclude) |
|
|
|
or !$member->isSame($exclude) |
|
|
|
) |
|
|
|
); |
|
|
|
; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public function getOuterWaysStopingWith(Point $point, ?Way $exclude = null): array { |
|
|
|
public function getOuterWaysStopingWith(Point $point, ?Way $exclude = null): array |
|
|
|
{ |
|
|
|
return array_filter($this->members, function ($member) use ($point, $exclude) { |
|
|
|
return ( |
|
|
|
($member instanceof \OSM\Element\Member\Way) |
|
|
|
and ($member->role === 'outer') |
|
|
|
and ($point->isSame($member->getLastPoint())) |
|
|
|
return |
|
|
|
($member instanceof Way) |
|
|
|
and ('outer' === $member->role) |
|
|
|
and $point->isSame($member->getLastPoint()) |
|
|
|
and ( |
|
|
|
is_null($exclude) |
|
|
|
or !$member->isSame($exclude) |
|
|
|
) |
|
|
|
); |
|
|
|
; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public function getOrderedOuterWays(): array { |
|
|
|
public function getOrderedOuterWays(): array |
|
|
|
{ |
|
|
|
$orderedWays = []; |
|
|
|
$ways = $this->getOuterWays(); |
|
|
|
|
|
|
@ -53,10 +56,10 @@ class Relation extends Element { |
|
|
|
$veryFirstPoint = $currentWay->getFirstPoint(); |
|
|
|
$isDone = false; |
|
|
|
while (!$isDone) { |
|
|
|
$orderedWays[] = $currentWay; |
|
|
|
$orderedWays[] = $currentWay; |
|
|
|
$nextWays = $this->getOuterWaysStartingWith($currentWay->getLastPoint(), $currentWay); |
|
|
|
assert(count($nextWays) <= 1); |
|
|
|
if (count($nextWays) === 1) { |
|
|
|
if (1 === count($nextWays)) { |
|
|
|
$nextWay = reset($nextWays); |
|
|
|
if ($veryFirstPoint->isSame($nextWay->getFirstPoint())) { |
|
|
|
break; |
|
|
@ -64,9 +67,9 @@ class Relation extends Element { |
|
|
|
$currentWay = $nextWay; |
|
|
|
continue; |
|
|
|
} else { |
|
|
|
$nextWays = $this->getOuterWaysStopingWith($currentWay->getLastPoint(), $currentWay); |
|
|
|
$nextWays = $this->getOuterWaysStopingWith($currentWay->getLastPoint(), $currentWay); |
|
|
|
assert(count($nextWays) <= 1); |
|
|
|
if (count($nextWays) === 1) { |
|
|
|
if (1 === count($nextWays)) { |
|
|
|
$nextWay = reset($nextWays); |
|
|
|
$nextWay->reversePoints(); |
|
|
|
if ($veryFirstPoint->isSame($nextWay->getFirstPoint())) { |
|
|
@ -82,5 +85,4 @@ class Relation extends Element { |
|
|
|
|
|
|
|
return $orderedWays; |
|
|
|
} |
|
|
|
|
|
|
|
} |