diff --git a/app/Http/Controllers/DetailRedirectController.php b/app/Http/Controllers/DetailRedirectController.php new file mode 100644 index 0000000..e371e0f --- /dev/null +++ b/app/Http/Controllers/DetailRedirectController.php @@ -0,0 +1,25 @@ + $osmId, 'osmTypeLetter' => 'n'])); + } + + public function way(string $osmId) + { + return redirect(route('osmPlace.en', ['osmId' => $osmId, 'osmTypeLetter' => 'w'])); + } + + public function relation(string $osmId) + { + return redirect(route('osmPlace.en', ['osmId' => $osmId, 'osmTypeLetter' => 'r'])); + } +} diff --git a/app/Services/Repository.php b/app/Services/Repository.php index 863603d..e95696c 100644 --- a/app/Services/Repository.php +++ b/app/Services/Repository.php @@ -108,10 +108,18 @@ public function getAreaInfo(string $areaSlug, bool $canEnrich = true) } public function listTypes(): array + { + $types = $this->listTypesIncludingFallback(); + unset($types['~fallback_type']); + return $types; + } + + public function listTypesIncludingFallback(): array { return Cache::remember('types', function() { return $this->listTypesUncached(); }); + } private function listTypesUncached(): array @@ -120,7 +128,7 @@ private function listTypesUncached(): array $result = []; foreach($typeFiles as $filename) { $slug = basename(dirname($filename)); - $result[] = $this->getTypeInfo($slug); + $result[$slug] = $this->getTypeInfo($slug); } return $result; @@ -129,7 +137,7 @@ private function listTypesUncached(): array public function resolveType(OsmInfo $osmInfo): ?PoiType { - $types = $this->listTypes(); + $types = $this->listTypesIncludingFallback(); // FIXME: sort by priority foreach($types as $type) diff --git a/routes/web.php b/routes/web.php index d32d970..71f95ec 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ group(function() use ($routes) { $routes(config('app.locale')); }); + +Route::get('/detail/node/{osmId}', [DetailRedirectController::class, 'node']) + ->where('osmId', '[0-9]*'); +Route::get('/detail/way/{osmId}', [DetailRedirectController::class, 'way']) + ->where('osmId', '[0-9]*'); +Route::get('/detail/relation/{osmId}', [DetailRedirectController::class, 'relation']) + ->where('osmId', '[0-9]*');