diff --git a/src/Provider/Photon/Model/PhotonAddress.php b/src/Provider/Photon/Model/PhotonAddress.php index 033008849..049b2c706 100644 --- a/src/Provider/Photon/Model/PhotonAddress.php +++ b/src/Provider/Photon/Model/PhotonAddress.php @@ -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 */ @@ -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; + } } diff --git a/src/Provider/Photon/Photon.php b/src/Provider/Photon/Photon.php index 564b8a36f..caed4ecab 100644 --- a/src/Provider/Photon/Photon.php +++ b/src/Provider/Photon/Photon.php @@ -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(), ]); @@ -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(), ]); @@ -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; } diff --git a/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_1452fda1b72428b0f5de90de04038275fd7f7e7e b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_1452fda1b72428b0f5de90de04038275fd7f7e7e new file mode 100644 index 000000000..bd0964e26 --- /dev/null +++ b/src/Provider/Photon/Tests/.cached_responses/photon.komoot.io_1452fda1b72428b0f5de90de04038275fd7f7e7e @@ -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"}"; \ No newline at end of file diff --git a/src/Provider/Photon/Tests/PhotonTest.php b/src/Provider/Photon/Tests/PhotonTest.php index 1148341d7..2ae88c655 100644 --- a/src/Provider/Photon/Tests/PhotonTest.php +++ b/src/Provider/Photon/Tests/PhotonTest.php @@ -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()); + } }