Skip to content

Commit

Permalink
🐛 Catch missing polylines (#1984)
Browse files Browse the repository at this point in the history
  • Loading branch information
HerrLevin authored Oct 15, 2023
1 parent ff85ea4 commit 08fe60f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/Http/Controllers/Backend/BrouterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,14 @@ public static function checkPolyline(HafasTrip $hafasTrip): void {
}

private static function checkIfPolylineHasMissingParts(HafasTrip $hafasTrip): bool {
if (is_null($hafasTrip->polyline)) {
Log::debug('Missing route found. No polyline available.');
return true;
}
$geoJson = json_decode($hafasTrip->polyline->polyline);
$features = $geoJson->features;
$lastStopOver = null; // To detect whether as the crow flies or real routing
foreach ($features as $key => $data) {
foreach ($features as $data) {
if (!isset($data->properties->id)) {
$lastStopOver = null;
} else {
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/Backend/Support/LocationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function calculateLivePosition(): ?LivePointDto {
$hafasTrip = $this->hafasTrip;
$newStopovers = $this->filterStopoversFromStatus();

if (!$newStopovers) {
if (!$newStopovers || !isset($hafasTrip->polyline->polyline)) {
return null;
}
if (count($newStopovers) === 1) {
Expand Down Expand Up @@ -144,7 +144,10 @@ private function getDistanceFromGeoJson(stdClass $geoJson): int {
* @throws JsonException
*/
private function getPolylineWithTimestamps(): stdClass {
$geoJsonObj = json_decode($this->hafasTrip->polyline->polyline, false, 512, JSON_THROW_ON_ERROR);
$geoJsonObj = json_decode('{"type":"FeatureCollection","features":[]}', false, 512, JSON_THROW_ON_ERROR);
if (isset($this->hafasTrip->polyline)) {
$geoJsonObj = json_decode($this->hafasTrip->polyline->polyline, false, 512, JSON_THROW_ON_ERROR);
}
$stopovers = $this->hafasTrip->stopovers;

$stopovers = $stopovers->map(function ($stopover) {
Expand Down

0 comments on commit 08fe60f

Please sign in to comment.