Skip to content
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
4 changes: 4 additions & 0 deletions src/Map/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 2.31

- Add `fitBoundsToMarkers` parameter to `ux_map()` Twig function

## 2.30

- Ensure compatibility with PHP 8.5
Expand Down
10 changes: 10 additions & 0 deletions src/Map/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,17 @@ templates. The function accepts the same arguments as the ``Map`` class:
infoWindow: { content: 'Welcome to <b>New York</b>' }
},
],
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 ``<twig:ux:map />``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -354,6 +359,7 @@ Alternatively, you can use the ``<twig:ux:map />`` component.
"infoWindow": {"content": "Welcome to <b>New York</b>"}
}
]'
:fitBoundsToMarkers="true",
class="foo"
style="height: 800px; width: 100%; border: 4px solid red; margin-block: 10vh;"
/>
Expand All @@ -364,6 +370,10 @@ The ``<twig:ux:map />`` 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
~~~~~~~~~~~~~~~~~~~~~

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

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Map/src/Twig/UXMapComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ final class UXMapComponent

public ?Point $center;

public ?bool $fitBoundsToMarkers;

/**
* @var Marker[]
*/
Expand Down
Loading