Skip to content

Commit

Permalink
Re add OSM ID for Addis Ababa, now filtering out those with subareas
Browse files Browse the repository at this point in the history
  • Loading branch information
amenk committed Nov 11, 2023
1 parent c1eec51 commit f0d2dd6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
5 changes: 2 additions & 3 deletions app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,14 @@ public function typePage(string $areaSlug, string $typeSlug)
*/
public function area(string $slug)
{
$types = $this->repository->listTypes($slug);
$types = $this->repository->listTypes();

$area = $this->repository->getAreaInfo($slug);

return view('page.area')
->with('area', $area)
->with('types', $types)
->with('color', $area->color);

}

/**
Expand All @@ -150,7 +149,7 @@ public function area(string $slug)
*/
private function fetchOsmInfo(array $places): array
{
return (new Overpass())->fetchOsmInfo($places, Repository::getInstance()->listAreas());
return (new Overpass())->fetchOsmInfo($places, Repository::getInstance()->listLeafAreas());
}

public function tripleZoomMap($lat, $lon, Request $request)
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Area.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public function __construct(
readonly public string $slug,
readonly public array $names,
readonly public array $descriptions,
readonly public string $color
readonly public string $color,
readonly public array $subAreas
)
{

Expand Down
2 changes: 1 addition & 1 deletion app/Services/Overpass.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ protected function buildQuery(string $objectQuerys, array $areas = null): string
(
$areasQuery
);
out ids 1;
out ids;
);
OVERPASS;

Expand Down
12 changes: 10 additions & 2 deletions app/Services/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getAreaInfo(string $areaSlug, bool $canEnrich = true)
$yamlSource = file_get_contents($this->getAreaFileName($areaSlug));

$parsed = Yaml::parse($yamlSource);
$osmId = isset($parsed['osm']) ? new OsmId($parsed['osm']['type'], $parsed['osm']['id'], ) : null;
$osmId = isset($parsed['osm']) ? new OsmId($parsed['osm']['type'], $parsed['osm']['id']) : null;

if ($canEnrich && $osmId !== null) {
$area = $this->resolveArea($osmId->getAreaId());
Expand All @@ -104,7 +104,7 @@ public function getAreaInfo(string $areaSlug, bool $canEnrich = true)
}
}

return new Area($this, $osmId, $areaSlug, $parsed['name'] ?? [], $parsed['description'] ?? [], $parsed['color'] ?? 'gray');
return new Area($this, $osmId, $areaSlug, $parsed['name'] ?? [], $parsed['description'] ?? [], $parsed['color'] ?? 'gray', $parsed['sub_areas'] ?? []);
}

public function listTypes(): array
Expand Down Expand Up @@ -196,6 +196,14 @@ public function listAreas()
});
}

public function listLeafAreas()
{
$leafAreas = array_filter($this->listAreas(), function(Area $area) {
return count($area->subAreas) === 0;
});
return $leafAreas;
}

private function listAreasUncached()
{
$areaFiles = glob($this->getAreaFileName('*'));
Expand Down
2 changes: 1 addition & 1 deletion resources/views/page/place.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<section id="{{ $branch->idInfo->getKey() }}">
<h3>{{ Fallback::field($branch->tags, 'name') }}</h3>
<strong>{{ ucfirst(Fallback::resolve($type->name)) }}</strong>
@if($branch->area)
@if($branch->area !== null)
in <strong><a href="<?php echo $branch->area->getUrl() ?>">{{ $branch->area->getFullName() }}</a></strong>
@endif
<img class="shadow-lg"
Expand Down
2 changes: 1 addition & 1 deletion tests/Services/OverpassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testOsmInfoMany()
{
$place1 = new OsmId('node', 3959878839);
$place2 = new OsmId('way', 798092378);
$osmInfo = $this->getInstance()->fetchOsmInfo([ $place1, $place2 ], Repository::getInstance()->listAreas());
$osmInfo = $this->getInstance()->fetchOsmInfo([ $place1, $place2 ], Repository::getInstance()->listLeafAreas());

self::assertInstanceOf(OsmInfo::class, $osmInfo[0]);
self::assertEquals('Zemen Bank', $osmInfo[0]->tags->name);
Expand Down

0 comments on commit f0d2dd6

Please sign in to comment.