Skip to content

Commit da642fd

Browse files
committed
[Map] Add fitBoundsToMarkers option to Twig extension and component
1 parent 269016e commit da642fd

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/Map/CHANGELOG.md

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

3+
## 2.31
4+
5+
- Add `fitBoundsToMarkers` option to Twig extension and component
6+
37
## 2.30
48

59
- Ensure compatibility with PHP 8.5

src/Map/src/Twig/MapRuntime.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ public function renderMap(
5353
?array $rectangles = null,
5454
?float $minZoom = null,
5555
?float $maxZoom = null,
56+
?bool $fitBoundsToMarkers = null,
5657
): string {
5758
if ($map instanceof Map) {
58-
if (null !== $center || null !== $zoom || $markers || $polygons || $polylines || $circles || $rectangles || $minZoom || $maxZoom) {
59+
if (null !== $center || null !== $zoom || $markers || $polygons || $polylines || $circles || $rectangles || $minZoom || $maxZoom || null !== $fitBoundsToMarkers) {
5960
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.');
6061
}
6162

@@ -90,13 +91,16 @@ public function renderMap(
9091
if (null !== $maxZoom) {
9192
$map->maxZoom($maxZoom);
9293
}
94+
if (null !== $fitBoundsToMarkers) {
95+
$map->fitBoundsToMarkers($fitBoundsToMarkers);
96+
}
9397

9498
return $this->renderer->renderMap($map, $attributes);
9599
}
96100

97101
public function render(array $args = []): string
98102
{
99-
$map = array_intersect_key($args, array_flip(['map', 'center', 'zoom', 'markers', 'polygons', 'polylines', 'circles', 'rectangles', 'minZoom', 'maxZoom']));
103+
$map = array_intersect_key($args, array_flip(['map', 'center', 'zoom', 'markers', 'polygons', 'polylines', 'circles', 'rectangles', 'minZoom', 'maxZoom', 'fitBoundsToMarkers']));
100104
$attributes = array_diff_key($args, $map);
101105

102106
return $this->renderMap(...$map, attributes: $attributes);

src/Map/src/Twig/UXMapComponent.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ final class UXMapComponent
3333

3434
public ?Point $center;
3535

36+
public ?bool $fitBoundsToMarkers;
37+
3638
/**
3739
* @var Marker[]
3840
*/

0 commit comments

Comments
 (0)