Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Provider/Photon/Model/PhotonAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ final class PhotonAddress extends Address
*/
private $district;

/**
* @var string|null
*/
private $type;

public function getLocality(): ?string
{
$locality = parent::getLocality();
if (null === $locality && 'city' === $this->type && null !== $this->name) {
$locality = $this->name;
}

return $locality;
}

/**
* @return string|null
*/
Expand Down Expand Up @@ -173,4 +188,17 @@ public function withDistrict(?string $district = null): self

return $new;
}

public function getType(): ?string
{
return $this->type;
}

public function withType(?string $type = null): self
{
$new = clone $this;
$new->type = $type;

return $new;
}
}
6 changes: 5 additions & 1 deletion src/Provider/Photon/Photon.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection
.'/api?'
.http_build_query([
'q' => $address,
'layer' => $query->getData('layer'),
'limit' => $query->getLimit(),
'lang' => $query->getLocale(),
]);
Expand Down Expand Up @@ -102,6 +103,8 @@ public function reverseQuery(ReverseQuery $query): Collection
.http_build_query([
'lat' => $latitude,
'lon' => $longitude,
'layer' => $query->getData('layer'),
'radius' => $query->getData('radius'),
'limit' => $query->getLimit(),
'lang' => $query->getLocale(),
]);
Expand Down Expand Up @@ -157,7 +160,8 @@ private function featureToAddress(\stdClass $feature): Location
->withName($properties->name ?? null)
->withState($properties->state ?? null)
->withCounty($properties->county ?? null)
->withDistrict($properties->district ?? null);
->withDistrict($properties->district ?? null)
->withType($properties->type ?? null);

return $address;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
s:334:"{"features":[{"geometry":{"coordinates":[13.3989367,52.510885],"type":"Point"},"type":"Feature","properties":{"osm_type":"R","osm_id":62422,"extent":[13.088345,52.6755087,13.7611609,52.3382448],"country":"Deutschland","osm_key":"place","countrycode":"DE","osm_value":"city","name":"Berlin","type":"city"}}],"type":"FeatureCollection"}";
14 changes: 14 additions & 0 deletions src/Provider/Photon/Tests/PhotonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,18 @@ public function testReverseQueryWithOsmTagFilter(): void
$this->assertEquals('pharmacy', $result->getOSMTag()->value);
}
}

public function testReverseQueryWithLayerCityAndRadiusFilter(): void
{
$provider = Photon::withKomootServer($this->getHttpClient());
$reverseQuery = ReverseQuery::fromCoordinates(52.51644, 13.38890)
->withData('layer', 'city')
->withData('radius', 20)
->withLimit(1);
$result = $provider->reverseQuery($reverseQuery)->first();

$this->assertInstanceOf(PhotonAddress::class, $result);
$this->assertEquals('city', $result->getType());
$this->assertEquals('Berlin', $result->getLocality());
}
}