From 367c343f43f854fcad99573de0be74e3cc8609fe Mon Sep 17 00:00:00 2001 From: Holly Date: Fri, 29 Mar 2024 16:28:28 +0800 Subject: [PATCH] Add support for custom properties in toFeatureCollectionJson method --- src/Objects/Geometry.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Objects/Geometry.php b/src/Objects/Geometry.php index 864b8a8..0ef92a2 100644 --- a/src/Objects/Geometry.php +++ b/src/Objects/Geometry.php @@ -155,7 +155,7 @@ public function toArray(): array /** * @throws JsonException */ - public function toFeatureCollectionJson(): string + public function toFeatureCollectionJson(array $properties = []): string { if (static::class === GeometryCollection::class) { /** @var GeometryCollection $this */ @@ -164,10 +164,10 @@ public function toFeatureCollectionJson(): string $geometries = collect([$this]); } - $features = $geometries->map(static function (self $geometry): array { + $features = $geometries->map(static function (self $geometry, $index) use ($properties) { return [ 'type' => 'Feature', - 'properties' => [], + 'properties' => $properties[$index] ?? [], 'geometry' => $geometry->toArray(), ]; });