Skip to content

Commit 9d7ec20

Browse files
committed
feature #2811 [Map] Do not override fitBoundsToMarkers when using LiveComponent (Danny van Wijk)
This PR was merged into the 2.x branch. Discussion ---------- [Map] Do not override `fitBoundsToMarkers` when using LiveComponent | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Docs? | yes <!-- required for new features --> | Issues | Fix #2774 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Update/add documentation as required (we can help!) - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Commits ------- c9698c2 [Map] Do not override `fitBoundsToMarkers` when using LiveComponent
2 parents c6badf4 + c9698c2 commit 9d7ec20

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/Map/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## 2.27
4+
5+
- The `fitBoundsToMarkers` option is not overridden anymore when using the `Map` LiveComponent, but now respects the value you defined.
6+
You may encounter unwanted behavior when adding/removing elements to the map.
7+
To use the previous behavior, you must call `$this->getMap()->fitBoundsToMarkers(false)` in your LiveComponent's live actions
8+
39
## 2.26
410

511
- Add support for creating `Polygon` with holes, by passing an array of `array<Point>` as `points` parameter to the `Polygon` constructor, e.g.:

src/Map/doc/index.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ You can interact with the Map by using ``LiveAction`` attribute::
628628
{
629629
return (new Map())
630630
->center(new Point(48.8566, 2.3522))
631-
->zoom(7)
631+
->fitBoundsToMarkers()
632632
->addMarker(new Marker(position: new Point(48.8566, 2.3522), title: 'Paris', infoWindow: new InfoWindow('Paris')))
633633
->addMarker(new Marker(position: new Point(45.75, 4.85), title: 'Lyon', infoWindow: new InfoWindow('Lyon')))
634634
;
@@ -655,6 +655,9 @@ You can retrieve the map instance using the ``getMap()`` method, and change the
655655
// Change the map zoom
656656
$this->getMap()->zoom(6);
657657

658+
// To prevent the Map from automatically fitting the bounds to the markers after adding a new element, disable the option `fitBoundsToMarkers`:
659+
$this->getMap()->fitBoundsToMarkers(false);
660+
658661
// Add a new marker
659662
$this->getMap()->addMarker(new Marker(position: new Point(43.2965, 5.3698), title: 'Marseille', infoWindow: new InfoWindow('Marseille')));
660663

src/Map/src/Map.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ public function toArray(): array
167167
*/
168168
public static function fromArray(array $map): self
169169
{
170-
$map['fitBoundsToMarkers'] = true;
171-
172170
if (isset($map['options'])) {
173171
$map['options'] = [] === $map['options'] ? null : MapOptionsNormalizer::denormalize($map['options']);
174172
}
@@ -177,10 +175,6 @@ public static function fromArray(array $map): self
177175
$map['center'] = Point::fromArray($map['center']);
178176
}
179177

180-
if (isset($map['zoom']) || isset($map['center'])) {
181-
$map['fitBoundsToMarkers'] = false;
182-
}
183-
184178
$map['markers'] ??= [];
185179
if (!\is_array($map['markers'])) {
186180
throw new InvalidArgumentException('The "markers" parameter must be an array.');

0 commit comments

Comments
 (0)