From c9698c205a9bd51f954b99ea2ad7a901bf67b0f6 Mon Sep 17 00:00:00 2001 From: Danny van Wijk Date: Mon, 2 Jun 2025 10:48:25 +0200 Subject: [PATCH] [Map] Do not override `fitBoundsToMarkers` when using LiveComponent --- src/Map/CHANGELOG.md | 6 ++++++ src/Map/doc/index.rst | 5 ++++- src/Map/src/Map.php | 6 ------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Map/CHANGELOG.md b/src/Map/CHANGELOG.md index c400f59c456..e756969e4f4 100644 --- a/src/Map/CHANGELOG.md +++ b/src/Map/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## 2.27 + +- The `fitBoundsToMarkers` option is not overridden anymore when using the `Map` LiveComponent, but now respects the value you defined. + You may encounter unwanted behavior when adding/removing elements to the map. + To use the previous behavior, you must call `$this->getMap()->fitBoundsToMarkers(false)` in your LiveComponent's live actions + ## 2.26 - Add support for creating `Polygon` with holes, by passing an array of `array` as `points` parameter to the `Polygon` constructor, e.g.: diff --git a/src/Map/doc/index.rst b/src/Map/doc/index.rst index 2f3eebf969e..cdeed061d00 100644 --- a/src/Map/doc/index.rst +++ b/src/Map/doc/index.rst @@ -628,7 +628,7 @@ You can interact with the Map by using ``LiveAction`` attribute:: { return (new Map()) ->center(new Point(48.8566, 2.3522)) - ->zoom(7) + ->fitBoundsToMarkers() ->addMarker(new Marker(position: new Point(48.8566, 2.3522), title: 'Paris', infoWindow: new InfoWindow('Paris'))) ->addMarker(new Marker(position: new Point(45.75, 4.85), title: 'Lyon', infoWindow: new InfoWindow('Lyon'))) ; @@ -655,6 +655,9 @@ You can retrieve the map instance using the ``getMap()`` method, and change the // Change the map zoom $this->getMap()->zoom(6); + // To prevent the Map from automatically fitting the bounds to the markers after adding a new element, disable the option `fitBoundsToMarkers`: + $this->getMap()->fitBoundsToMarkers(false); + // Add a new marker $this->getMap()->addMarker(new Marker(position: new Point(43.2965, 5.3698), title: 'Marseille', infoWindow: new InfoWindow('Marseille'))); diff --git a/src/Map/src/Map.php b/src/Map/src/Map.php index f0d49c60f06..52832a8f311 100644 --- a/src/Map/src/Map.php +++ b/src/Map/src/Map.php @@ -167,8 +167,6 @@ public function toArray(): array */ public static function fromArray(array $map): self { - $map['fitBoundsToMarkers'] = true; - if (isset($map['options'])) { $map['options'] = [] === $map['options'] ? null : MapOptionsNormalizer::denormalize($map['options']); } @@ -177,10 +175,6 @@ public static function fromArray(array $map): self $map['center'] = Point::fromArray($map['center']); } - if (isset($map['zoom']) || isset($map['center'])) { - $map['fitBoundsToMarkers'] = false; - } - $map['markers'] ??= []; if (!\is_array($map['markers'])) { throw new InvalidArgumentException('The "markers" parameter must be an array.');