diff --git a/src/Map/CHANGELOG.md b/src/Map/CHANGELOG.md
index 75f708211bd..493b1c01b91 100644
--- a/src/Map/CHANGELOG.md
+++ b/src/Map/CHANGELOG.md
@@ -7,6 +7,10 @@
- Add `DistanceCalculatorInterface` interface and three implementations:
`HaversineDistanceCalculator`, `SphericalCosineDistanceCalculator` and `VincentyDistanceCalculator`.
- Add `CoordinateUtils` helper, to convert decimal coordinates (`43.2109`) in DMS (`56° 78' 90"`)
+- Add parameter `id` to `Marker`, `Polygon` and `Polyline` constructors
+- Add method `Map::removeMarker(string|Marker $markerOrId)`
+- Add method `Map::removePolygon(string|Polygon $polygonOrId)`
+- Add method `Map::removePolyline(string|Polyline $polylineOrId)`
## 2.22
diff --git a/src/Map/doc/index.rst b/src/Map/doc/index.rst
index 855b6fa7e62..b97955f2cee 100644
--- a/src/Map/doc/index.rst
+++ b/src/Map/doc/index.rst
@@ -136,6 +136,34 @@ You can add markers to a map using the ``addMarker()`` method::
))
;
+Remove elements from Map
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+It is possible to remove elements like ``Marker``, ``Polygon`` and ``Polyline`` instances by using ``Map::remove*()`` methods::
+
+ // Add elements
+ $map->addMarker($marker = new Marker(/* ... */));
+ $map->addPolygon($polygon = new Polygon(/* ... */));
+ $map->addPolyline($polyline = new Polyline(/* ... */));
+
+ // And later, remove those elements
+ $map->removeMarker($marker);
+ $map->removePolygon($polygon);
+ $map->removePolyline($polyline);
+
+If unfortunately you were unable to store an element instance, you can still remove them by passing the identifier string::
+
+ $map = new Map(/* ... */);
+ // Add elements
+ $map->addMarker(new Marker(id: 'my-marker', /* ... */));
+ $map->addPolygon(new Polygon(id: 'my-polygon', /* ... */));
+ $map->addPolyline(new Polyline(id: 'my-marker', /* ... */));
+
+ // And later, remove those elements
+ $map->removeMarker('my-marker');
+ $map->removePolygon('my-polygon');
+ $map->removePolyline('my-marker');
+
Add Polygons
~~~~~~~~~~~~
diff --git a/src/Map/src/Bridge/Google/tests/GoogleRendererTest.php b/src/Map/src/Bridge/Google/tests/GoogleRendererTest.php
index d8695096141..dda259fec56 100644
--- a/src/Map/src/Bridge/Google/tests/GoogleRendererTest.php
+++ b/src/Map/src/Bridge/Google/tests/GoogleRendererTest.php
@@ -29,6 +29,9 @@ public function provideTestRenderMap(): iterable
$map = (new Map())
->center(new Point(48.8566, 2.3522))
->zoom(12);
+ $marker1 = new Marker(position: new Point(48.8566, 2.3522), title: 'Paris', id: 'marker1');
+ $marker2 = new Marker(position: new Point(48.8566, 2.3522), title: 'Lyon', infoWindow: new InfoWindow(content: 'Lyon'), id: 'marker2');
+ $marker3 = new Marker(position: new Point(45.8566, 2.3522), title: 'Dijon', id: 'marker3');
yield 'simple map, with minimum options' => [
'expected_render' => '
',
@@ -50,25 +53,55 @@ public function provideTestRenderMap(): iterable
];
yield 'with markers and infoWindows' => [
- 'expected_render' => '',
+ 'expected_render' => '',
'renderer' => new GoogleRenderer(new StimulusHelper(null), apiKey: 'api_key'),
- 'map' => (clone $map)
- ->addMarker(new Marker(new Point(48.8566, 2.3522), 'Paris'))
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
+ ->addMarker(new Marker(position: new Point(48.8566, 2.3522), title: 'Paris', id: 'marker1'))
->addMarker(new Marker(new Point(48.8566, 2.3522), 'Lyon', infoWindow: new InfoWindow(content: 'Lyon'))),
];
+ yield 'with all markers removed' => [
+ 'expected_render' => '',
+ 'renderer' => new GoogleRenderer(new StimulusHelper(null), apiKey: 'api_key'),
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
+ ->addMarker($marker1)
+ ->addMarker($marker2)
+ ->removeMarker($marker1)
+ ->removeMarker($marker2),
+ ];
+
+ yield 'with marker remove and new ones added' => [
+ 'expected_render' => '',
+ 'renderer' => new GoogleRenderer(new StimulusHelper(null), apiKey: 'api_key'),
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
+ ->addMarker($marker3)
+ ->removeMarker($marker3)
+ ->addMarker($marker1)
+ ->addMarker($marker2),
+ ];
+
yield 'with polygons and infoWindows' => [
- 'expected_render' => '',
+ 'expected_render' => '',
'renderer' => new GoogleRenderer(new StimulusHelper(null), apiKey: 'api_key'),
- 'map' => (clone $map)
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
->addPolygon(new Polygon(points: [new Point(48.8566, 2.3522), new Point(48.8566, 2.3522), new Point(48.8566, 2.3522)]))
->addPolygon(new Polygon(points: [new Point(1.1, 2.2), new Point(3.3, 4.4), new Point(5.5, 6.6)], infoWindow: new InfoWindow(content: 'Polygon'))),
];
yield 'with polylines and infoWindows' => [
- 'expected_render' => '',
+ 'expected_render' => '',
'renderer' => new GoogleRenderer(new StimulusHelper(null), apiKey: 'api_key'),
- 'map' => (clone $map)
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
->addPolyline(new Polyline(points: [new Point(48.8566, 2.3522), new Point(48.8566, 2.3522), new Point(48.8566, 2.3522)]))
->addPolyline(new Polyline(points: [new Point(1.1, 2.2), new Point(3.3, 4.4), new Point(5.5, 6.6)], infoWindow: new InfoWindow(content: 'Polygon'))),
];
@@ -76,7 +109,9 @@ public function provideTestRenderMap(): iterable
yield 'with controls enabled' => [
'expected_render' => '',
'renderer' => new GoogleRenderer(new StimulusHelper(null), apiKey: 'api_key'),
- 'map' => (clone $map)
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
->options(new GoogleOptions(
zoomControl: true,
mapTypeControl: true,
@@ -88,7 +123,9 @@ public function provideTestRenderMap(): iterable
yield 'without controls enabled' => [
'expected_render' => '',
'renderer' => new GoogleRenderer(new StimulusHelper(null), apiKey: 'api_key'),
- 'map' => (clone $map)
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
->options(new GoogleOptions(
zoomControl: false,
mapTypeControl: false,
@@ -100,18 +137,24 @@ public function provideTestRenderMap(): iterable
yield 'with default map id' => [
'expected_renderer' => '',
'renderer' => new GoogleRenderer(new StimulusHelper(null), 'my_api_key', defaultMapId: 'DefaultMapId'),
- 'map' => (clone $map),
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12),
];
yield 'with default map id, when passing options (except the "mapId")' => [
'expected_renderer' => '',
'renderer' => new GoogleRenderer(new StimulusHelper(null), 'my_api_key', defaultMapId: 'DefaultMapId'),
- 'map' => (clone $map)
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
->options(new GoogleOptions()),
];
yield 'with default map id overridden by option "mapId"' => [
'expected_renderer' => '',
'renderer' => new GoogleRenderer(new StimulusHelper(null), 'my_api_key', defaultMapId: 'DefaultMapId'),
- 'map' => (clone $map)
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
->options(new GoogleOptions(mapId: 'CustomMapId')),
];
}
diff --git a/src/Map/src/Bridge/Leaflet/tests/LeafletRendererTest.php b/src/Map/src/Bridge/Leaflet/tests/LeafletRendererTest.php
index 81d5316079f..e9f8cec5354 100644
--- a/src/Map/src/Bridge/Leaflet/tests/LeafletRendererTest.php
+++ b/src/Map/src/Bridge/Leaflet/tests/LeafletRendererTest.php
@@ -29,41 +29,74 @@ public function provideTestRenderMap(): iterable
->center(new Point(48.8566, 2.3522))
->zoom(12);
+ $marker1 = new Marker(position: new Point(48.8566, 2.3522), title: 'Paris', id: 'marker1');
+ $marker2 = new Marker(position: new Point(48.8566, 2.3522), title: 'Lyon', infoWindow: new InfoWindow(content: 'Lyon'), id: 'marker2');
+ $marker3 = new Marker(position: new Point(45.8566, 2.3522), title: 'Dijon', id: 'marker3');
+
yield 'simple map' => [
'expected_render' => '',
'renderer' => new LeafletRenderer(new StimulusHelper(null)),
- 'map' => $map,
+ 'map' => (clone $map),
];
yield 'with custom attributes' => [
'expected_render' => '',
'renderer' => new LeafletRenderer(new StimulusHelper(null)),
- 'map' => $map,
+ 'map' => (clone $map),
'attributes' => ['data-controller' => 'my-custom-controller', 'class' => 'map'],
];
-
yield 'with markers and infoWindows' => [
- 'expected_render' => '',
+ 'expected_render' => '',
+ 'renderer' => new LeafletRenderer(new StimulusHelper(null)),
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
+ ->addMarker($marker1)
+ ->addMarker(new Marker(position: new Point(48.8566, 2.3522), title: 'Lyon', infoWindow: new InfoWindow(content: 'Lyon'))),
+ ];
+
+ yield 'with all markers removed' => [
+ 'expected_render' => '',
+ 'renderer' => new LeafletRenderer(new StimulusHelper(null)),
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
+ ->addMarker($marker1)
+ ->addMarker($marker2)
+ ->removeMarker($marker1)
+ ->removeMarker($marker2),
+ ];
+
+ yield 'with marker remove and new ones added' => [
+ 'expected_render' => '',
'renderer' => new LeafletRenderer(new StimulusHelper(null)),
- 'map' => (clone $map)
- ->addMarker(new Marker(new Point(48.8566, 2.3522), 'Paris'))
- ->addMarker(new Marker(new Point(48.8566, 2.3522), 'Lyon', infoWindow: new InfoWindow(content: 'Lyon'))),
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
+ ->addMarker($marker3)
+ ->removeMarker($marker3)
+ ->addMarker($marker1)
+ ->addMarker($marker2),
];
yield 'with polygons and infoWindows' => [
- 'expected_render' => '',
+ 'expected_render' => '',
'renderer' => new LeafletRenderer(new StimulusHelper(null)),
- 'map' => (clone $map)
- ->addPolygon(new Polygon(points: [new Point(48.8566, 2.3522), new Point(48.8566, 2.3522), new Point(48.8566, 2.3522)]))
- ->addPolygon(new Polygon(points: [new Point(1.1, 2.2), new Point(3.3, 4.4), new Point(5.5, 6.6)], infoWindow: new InfoWindow(content: 'Polygon'))),
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
+ ->addPolygon(new Polygon(points: [new Point(48.8566, 2.3522), new Point(48.8566, 2.3522), new Point(48.8566, 2.3522)], id: 'polygon1'))
+ ->addPolygon(new Polygon(points: [new Point(1.1, 2.2), new Point(3.3, 4.4), new Point(5.5, 6.6)], infoWindow: new InfoWindow(content: 'Polygon'), id: 'polygon2')),
];
yield 'with polylines and infoWindows' => [
- 'expected_render' => '',
+ 'expected_render' => '',
'renderer' => new LeafletRenderer(new StimulusHelper(null)),
- 'map' => (clone $map)
- ->addPolyline(new Polyline(points: [new Point(48.8566, 2.3522), new Point(48.8566, 2.3522), new Point(48.8566, 2.3522)]))
- ->addPolyline(new Polyline(points: [new Point(1.1, 2.2), new Point(3.3, 4.4), new Point(5.5, 6.6)], infoWindow: new InfoWindow(content: 'Polygon'))),
+ 'map' => (new Map())
+ ->center(new Point(48.8566, 2.3522))
+ ->zoom(12)
+ ->addPolyline(new Polyline(points: [new Point(48.8566, 2.3522), new Point(48.8566, 2.3522), new Point(48.8566, 2.3522)], id: 'polyline1'))
+ ->addPolyline(new Polyline(points: [new Point(1.1, 2.2), new Point(3.3, 4.4), new Point(5.5, 6.6)], infoWindow: new InfoWindow(content: 'Polyline'), id: 'polyline2')),
];
}
}
diff --git a/src/Map/src/Element.php b/src/Map/src/Element.php
new file mode 100644
index 00000000000..c7f752ea8ec
--- /dev/null
+++ b/src/Map/src/Element.php
@@ -0,0 +1,21 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\UX\Map;
+
+/**
+ * @author Sylvain Blondeau
+ *
+ * @internal
+ */
+interface Element
+{
+}
diff --git a/src/Map/src/Elements.php b/src/Map/src/Elements.php
new file mode 100644
index 00000000000..6dee1939f13
--- /dev/null
+++ b/src/Map/src/Elements.php
@@ -0,0 +1,79 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\UX\Map;
+
+/**
+ * Represents a collection of map elements.
+ *
+ * @author Sylvain Blondeau
+ *
+ * @internal
+ */
+abstract class Elements
+{
+ private \SplObjectStorage $elements;
+
+ public function __construct(
+ array $elements,
+ ) {
+ $this->elements = new \SplObjectStorage();
+ foreach ($elements as $element) {
+ $this->elements->attach($element);
+ }
+ }
+
+ public function add(Element $element): static
+ {
+ $this->elements->attach($element, $element->id ?? $this->elements->getHash($element));
+
+ return $this;
+ }
+
+ private function getElement(string $id): ?Element
+ {
+ foreach ($this->elements as $element) {
+ if ($element->id === $id) {
+ return $element;
+ }
+ }
+
+ return null;
+ }
+
+ public function remove(Element|string $elementOrId): static
+ {
+ if (\is_string($elementOrId)) {
+ $elementOrId = $this->getElement($elementOrId);
+ }
+
+ if (null === $elementOrId) {
+ return $this;
+ }
+
+ if ($this->elements->contains($elementOrId)) {
+ $this->elements->detach($elementOrId);
+ }
+
+ return $this;
+ }
+
+ public function toArray(): array
+ {
+ foreach ($this->elements as $element) {
+ $elements[] = $element->toArray();
+ }
+
+ return $elements ?? [];
+ }
+
+ abstract public static function fromArray(array $elements): self;
+}
diff --git a/src/Map/src/Map.php b/src/Map/src/Map.php
index 529f8af8c41..f0d49c60f06 100644
--- a/src/Map/src/Map.php
+++ b/src/Map/src/Map.php
@@ -20,27 +20,28 @@
*/
final class Map
{
+ private Markers $markers;
+ private Polygons $polygons;
+ private Polylines $polylines;
+
+ /**
+ * @param Marker[] $markers
+ * @param Polygon[] $polygons
+ * @param Polyline[] $polylines
+ */
public function __construct(
private readonly ?string $rendererName = null,
private ?MapOptionsInterface $options = null,
private ?Point $center = null,
private ?float $zoom = null,
private bool $fitBoundsToMarkers = false,
- /**
- * @var array
- */
- private array $markers = [],
-
- /**
- * @var array
- */
- private array $polygons = [],
-
- /**
- * @var array
- */
- private array $polylines = [],
+ array $markers = [],
+ array $polygons = [],
+ array $polylines = [],
) {
+ $this->markers = new Markers($markers);
+ $this->polygons = new Polygons($polygons);
+ $this->polylines = new Polylines($polylines);
}
public function getRendererName(): ?string
@@ -88,21 +89,42 @@ public function hasOptions(): bool
public function addMarker(Marker $marker): self
{
- $this->markers[] = $marker;
+ $this->markers->add($marker);
+
+ return $this;
+ }
+
+ public function removeMarker(Marker|string $markerOrId): self
+ {
+ $this->markers->remove($markerOrId);
return $this;
}
public function addPolygon(Polygon $polygon): self
{
- $this->polygons[] = $polygon;
+ $this->polygons->add($polygon);
+
+ return $this;
+ }
+
+ public function removePolygon(Polygon|string $polygonOrId): self
+ {
+ $this->polygons->remove($polygonOrId);
return $this;
}
public function addPolyline(Polyline $polyline): self
{
- $this->polylines[] = $polyline;
+ $this->polylines->add($polyline);
+
+ return $this;
+ }
+
+ public function removePolyline(Polyline|string $polylineOrId): self
+ {
+ $this->polylines->remove($polylineOrId);
return $this;
}
@@ -124,9 +146,9 @@ public function toArray(): array
'zoom' => $this->zoom,
'fitBoundsToMarkers' => $this->fitBoundsToMarkers,
'options' => $this->options ? MapOptionsNormalizer::normalize($this->options) : [],
- 'markers' => array_map(static fn (Marker $marker) => $marker->toArray(), $this->markers),
- 'polygons' => array_map(static fn (Polygon $polygon) => $polygon->toArray(), $this->polygons),
- 'polylines' => array_map(static fn (Polyline $polyline) => $polyline->toArray(), $this->polylines),
+ 'markers' => $this->markers->toArray(),
+ 'polygons' => $this->polygons->toArray(),
+ 'polylines' => $this->polylines->toArray(),
];
}
diff --git a/src/Map/src/Marker.php b/src/Map/src/Marker.php
index 54d61ebefc8..0310834a14f 100644
--- a/src/Map/src/Marker.php
+++ b/src/Map/src/Marker.php
@@ -18,17 +18,18 @@
*
* @author Hugo Alliaume
*/
-final readonly class Marker
+final readonly class Marker implements Element
{
/**
* @param array $extra Extra data, can be used by the developer to store additional information and
* use them later JavaScript side
*/
public function __construct(
- private Point $position,
- private ?string $title = null,
- private ?InfoWindow $infoWindow = null,
- private array $extra = [],
+ public Point $position,
+ public ?string $title = null,
+ public ?InfoWindow $infoWindow = null,
+ public array $extra = [],
+ public ?string $id = null,
) {
}
@@ -38,6 +39,7 @@ public function __construct(
* title: string|null,
* infoWindow: array|null,
* extra: array,
+ * id: string|null
* }
*/
public function toArray(): array
@@ -47,6 +49,7 @@ public function toArray(): array
'title' => $this->title,
'infoWindow' => $this->infoWindow?->toArray(),
'extra' => $this->extra,
+ 'id' => $this->id,
];
}
@@ -56,6 +59,7 @@ public function toArray(): array
* title: string|null,
* infoWindow: array|null,
* extra: array,
+ * id: string|null
* } $marker
*
* @internal
diff --git a/src/Map/src/Markers.php b/src/Map/src/Markers.php
new file mode 100644
index 00000000000..b82e3cf05a6
--- /dev/null
+++ b/src/Map/src/Markers.php
@@ -0,0 +1,33 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\UX\Map;
+
+/**
+ * Represents a Marker collection.
+ *
+ * @author Sylvain Blondeau
+ *
+ * @internal
+ */
+final class Markers extends Elements
+{
+ public static function fromArray(array $elements): self
+ {
+ $elementObjects = [];
+
+ foreach ($elements as $element) {
+ $elementObjects[] = Marker::fromArray($element);
+ }
+
+ return new self(elements: $elementObjects);
+ }
+}
diff --git a/src/Map/src/Polygon.php b/src/Map/src/Polygon.php
index d32594ad000..4faaf7e86b9 100644
--- a/src/Map/src/Polygon.php
+++ b/src/Map/src/Polygon.php
@@ -18,7 +18,7 @@
*
* @author [Pierre Svgnt]
*/
-final readonly class Polygon
+final readonly class Polygon implements Element
{
/**
* @param array $extra Extra data, can be used by the developer to store additional information and use them later JavaScript side
@@ -28,6 +28,7 @@ public function __construct(
private ?string $title = null,
private ?InfoWindow $infoWindow = null,
private array $extra = [],
+ public ?string $id = null,
) {
}
@@ -39,6 +40,7 @@ public function __construct(
* title: string|null,
* infoWindow: array|null,
* extra: array,
+ * id: string|null
* }
*/
public function toArray(): array
@@ -48,6 +50,7 @@ public function toArray(): array
'title' => $this->title,
'infoWindow' => $this->infoWindow?->toArray(),
'extra' => $this->extra,
+ 'id' => $this->id,
];
}
@@ -57,6 +60,7 @@ public function toArray(): array
* title: string|null,
* infoWindow: array|null,
* extra: array,
+ * id: string|null
* } $polygon
*
* @internal
diff --git a/src/Map/src/Polygons.php b/src/Map/src/Polygons.php
new file mode 100644
index 00000000000..5d75ba8f0c1
--- /dev/null
+++ b/src/Map/src/Polygons.php
@@ -0,0 +1,33 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\UX\Map;
+
+/**
+ * Represents a Polygon collection.
+ *
+ * @author Sylvain Blondeau
+ *
+ * @internal
+ */
+final class Polygons extends Elements
+{
+ public static function fromArray(array $elements): self
+ {
+ $elementObjects = [];
+
+ foreach ($elements as $element) {
+ $elementObjects[] = Polygon::fromArray($element);
+ }
+
+ return new self(elements: $elementObjects);
+ }
+}
diff --git a/src/Map/src/Polyline.php b/src/Map/src/Polyline.php
index 4630213637a..15b1b778f45 100644
--- a/src/Map/src/Polyline.php
+++ b/src/Map/src/Polyline.php
@@ -18,7 +18,7 @@
*
* @author [Sylvain Blondeau]
*/
-final readonly class Polyline
+final readonly class Polyline implements Element
{
/**
* @param array $extra Extra data, can be used by the developer to store additional information and use them later JavaScript side
@@ -28,6 +28,7 @@ public function __construct(
private ?string $title = null,
private ?InfoWindow $infoWindow = null,
private array $extra = [],
+ public ?string $id = null,
) {
}
@@ -39,6 +40,7 @@ public function __construct(
* title: string|null,
* infoWindow: array|null,
* extra: array,
+ * id: string|null
* }
*/
public function toArray(): array
@@ -48,6 +50,7 @@ public function toArray(): array
'title' => $this->title,
'infoWindow' => $this->infoWindow?->toArray(),
'extra' => $this->extra,
+ 'id' => $this->id,
];
}
@@ -57,6 +60,7 @@ public function toArray(): array
* title: string|null,
* infoWindow: array|null,
* extra: array,
+ * id: string|null
* } $polyline
*
* @internal
diff --git a/src/Map/src/Polylines.php b/src/Map/src/Polylines.php
new file mode 100644
index 00000000000..810f180d134
--- /dev/null
+++ b/src/Map/src/Polylines.php
@@ -0,0 +1,33 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\UX\Map;
+
+/**
+ * Represents a Polyline collection.
+ *
+ * @author Sylvain Blondeau
+ *
+ * @internal
+ */
+final class Polylines extends Elements
+{
+ public static function fromArray(array $elements): self
+ {
+ $elementObjects = [];
+
+ foreach ($elements as $element) {
+ $elementObjects[] = Polyline::fromArray($element);
+ }
+
+ return new self(elements: $elementObjects);
+ }
+}
diff --git a/src/Map/tests/MapTest.php b/src/Map/tests/MapTest.php
index b176e0d99c1..2f91323ea6b 100644
--- a/src/Map/tests/MapTest.php
+++ b/src/Map/tests/MapTest.php
@@ -187,6 +187,7 @@ public function testWithMaximumConfiguration(): void
'extra' => ['baz' => 'qux'],
],
'extra' => ['foo' => 'bar'],
+ 'id' => null,
],
[
'position' => ['lat' => 45.764, 'lng' => 4.8357],
@@ -200,6 +201,7 @@ public function testWithMaximumConfiguration(): void
'extra' => [],
],
'extra' => [],
+ 'id' => null,
],
[
'position' => ['lat' => 43.2965, 'lng' => 5.3698],
@@ -213,6 +215,7 @@ public function testWithMaximumConfiguration(): void
'extra' => [],
],
'extra' => [],
+ 'id' => null,
],
],
'polygons' => [
@@ -225,6 +228,7 @@ public function testWithMaximumConfiguration(): void
'title' => 'Polygon 1',
'infoWindow' => null,
'extra' => [],
+ 'id' => null,
],
[
'points' => [
@@ -242,6 +246,7 @@ public function testWithMaximumConfiguration(): void
'extra' => [],
],
'extra' => [],
+ 'id' => null,
],
],
'polylines' => [
@@ -254,6 +259,7 @@ public function testWithMaximumConfiguration(): void
'title' => 'Polyline 1',
'infoWindow' => null,
'extra' => [],
+ 'id' => null,
],
[
'points' => [
@@ -271,6 +277,7 @@ public function testWithMaximumConfiguration(): void
'extra' => [],
],
'extra' => [],
+ 'id' => null,
],
],
], $map->toArray());
diff --git a/src/Map/tests/MarkerTest.php b/src/Map/tests/MarkerTest.php
index e55dca0e29d..f5f9d21ddd2 100644
--- a/src/Map/tests/MarkerTest.php
+++ b/src/Map/tests/MarkerTest.php
@@ -31,6 +31,7 @@ public function testToArray(): void
'title' => null,
'infoWindow' => null,
'extra' => $array['extra'],
+ 'id' => null,
], $array);
$marker = new Marker(
@@ -57,6 +58,7 @@ public function testToArray(): void
'extra' => $array['infoWindow']['extra'],
],
'extra' => $array['extra'],
+ 'id' => null,
], $array);
}
}