diff --git a/src/Map/CHANGELOG.md b/src/Map/CHANGELOG.md
index 3fa6150dd53..ff1e1c6c288 100644
--- a/src/Map/CHANGELOG.md
+++ b/src/Map/CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG
+## 2.31
+
+- Add `fitBoundsToMarkers` parameter to `ux_map()` Twig function
+
## 2.30
- Ensure compatibility with PHP 8.5
diff --git a/src/Map/doc/index.rst b/src/Map/doc/index.rst
index 4bd2ecdd0c7..56afd3315ca 100644
--- a/src/Map/doc/index.rst
+++ b/src/Map/doc/index.rst
@@ -329,12 +329,17 @@ templates. The function accepts the same arguments as the ``Map`` class:
infoWindow: { content: 'Welcome to New York' }
},
],
+ fitBoundsToMarkers: true,
attributes: {
class: 'foo',
style: 'height: 800px; width: 100%; border: 4px solid red; margin-block: 10vh;',
}
) }}
+.. versionadded:: 2.31
+
+ `fitBoundsToMarkers` option for the twig function is available since UX Map 2.31.
+
Twig Component ````
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -354,6 +359,7 @@ Alternatively, you can use the ```` component.
"infoWindow": {"content": "Welcome to New York"}
}
]'
+ :fitBoundsToMarkers="true",
class="foo"
style="height: 800px; width: 100%; border: 4px solid red; margin-block: 10vh;"
/>
@@ -364,6 +370,10 @@ The ```` component requires the `Twig Component`_ package.
$ composer require symfony/ux-twig-component
+.. versionadded:: 2.31
+
+ `fitBoundsToMarkers` option for the twig component is available since UX Map 2.31.
+
Interact with the map
~~~~~~~~~~~~~~~~~~~~~
diff --git a/src/Map/src/Twig/MapRuntime.php b/src/Map/src/Twig/MapRuntime.php
index cece6919452..c1af979de31 100644
--- a/src/Map/src/Twig/MapRuntime.php
+++ b/src/Map/src/Twig/MapRuntime.php
@@ -53,9 +53,10 @@ public function renderMap(
?array $rectangles = null,
?float $minZoom = null,
?float $maxZoom = null,
+ ?bool $fitBoundsToMarkers = null,
): string {
if ($map instanceof Map) {
- if (null !== $center || null !== $zoom || $markers || $polygons || $polylines || $circles || $rectangles || $minZoom || $maxZoom) {
+ if (null !== $center || null !== $zoom || $markers || $polygons || $polylines || $circles || $rectangles || $minZoom || $maxZoom || null !== $fitBoundsToMarkers) {
throw new \InvalidArgumentException('It is not allowed to pass both a Map object and other parameters (like "center", "zoom", "markers", etc...) to the "renderMap" method. Please use either a Map object or the individual parameters.');
}
@@ -90,13 +91,16 @@ public function renderMap(
if (null !== $maxZoom) {
$map->maxZoom($maxZoom);
}
+ if (null !== $fitBoundsToMarkers) {
+ $map->fitBoundsToMarkers($fitBoundsToMarkers);
+ }
return $this->renderer->renderMap($map, $attributes);
}
public function render(array $args = []): string
{
- $map = array_intersect_key($args, array_flip(['map', 'center', 'zoom', 'markers', 'polygons', 'polylines', 'circles', 'rectangles', 'minZoom', 'maxZoom']));
+ $map = array_intersect_key($args, array_flip(['map', 'center', 'zoom', 'markers', 'polygons', 'polylines', 'circles', 'rectangles', 'minZoom', 'maxZoom', 'fitBoundsToMarkers']));
$attributes = array_diff_key($args, $map);
return $this->renderMap(...$map, attributes: $attributes);
diff --git a/src/Map/src/Twig/UXMapComponent.php b/src/Map/src/Twig/UXMapComponent.php
index 2dc6c46b59f..6716f1294d0 100644
--- a/src/Map/src/Twig/UXMapComponent.php
+++ b/src/Map/src/Twig/UXMapComponent.php
@@ -33,6 +33,8 @@ final class UXMapComponent
public ?Point $center;
+ public ?bool $fitBoundsToMarkers;
+
/**
* @var Marker[]
*/