Skip to content

Commit dbea936

Browse files
committed
feature #3114 [Map] Add fitBoundsToMarkers option to Twig extension and component (ker0x)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Map] Add fitBoundsToMarkers option to Twig extension and component | Q | A | -------------- | --- | Bug fix? | no | New feature? | yes | Deprecations? | no | Documentation? | yes | Issues | - | License | MIT This PR add option `fitBoundsToMarkers` to the Twig function and component because currently, when using the twig function or component by passing an array of markers without specifying the center and zoom, this throws an exception due to `fitBoundsToMarkers` set to `false` by default. Commits ------- 44f9025 [Map] Add fitBoundsToMarkers option to Twig extension and component
2 parents 007db4e + 44f9025 commit dbea936

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-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` parameter to `ux_map()` Twig function
6+
37
## 2.30
48

59
- Ensure compatibility with PHP 8.5

src/Map/doc/index.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,17 @@ templates. The function accepts the same arguments as the ``Map`` class:
329329
infoWindow: { content: 'Welcome to <b>New York</b>' }
330330
},
331331
],
332+
fitBoundsToMarkers: true,
332333
attributes: {
333334
class: 'foo',
334335
style: 'height: 800px; width: 100%; border: 4px solid red; margin-block: 10vh;',
335336
}
336337
) }}
337338

339+
.. versionadded:: 2.31
340+
341+
`fitBoundsToMarkers` option for the twig function is available since UX Map 2.31.
342+
338343
Twig Component ``<twig:ux:map />``
339344
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
340345

@@ -354,6 +359,7 @@ Alternatively, you can use the ``<twig:ux:map />`` component.
354359
"infoWindow": {"content": "Welcome to <b>New York</b>"}
355360
}
356361
]'
362+
:fitBoundsToMarkers="true",
357363
class="foo"
358364
style="height: 800px; width: 100%; border: 4px solid red; margin-block: 10vh;"
359365
/>
@@ -364,6 +370,10 @@ The ``<twig:ux:map />`` component requires the `Twig Component`_ package.
364370
365371
$ composer require symfony/ux-twig-component
366372
373+
.. versionadded:: 2.31
374+
375+
`fitBoundsToMarkers` option for the twig component is available since UX Map 2.31.
376+
367377
Interact with the map
368378
~~~~~~~~~~~~~~~~~~~~~
369379

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)