Skip to content

[Map] Do not override fitBoundsToMarkers when using LiveComponent #2811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2025
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
6 changes: 6 additions & 0 deletions src/Map/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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<Point>` as `points` parameter to the `Polygon` constructor, e.g.:
Expand Down
5 changes: 4 additions & 1 deletion src/Map/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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')))
;
Expand All @@ -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')));

Expand Down
6 changes: 0 additions & 6 deletions src/Map/src/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand All @@ -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.');
Expand Down
Loading