Seamless Maps Integration
Embed interactive maps in a breeze!
Decouple your code from your map provider: Google Maps, LeaftLet.
composer require symfony/ux-map
// ... use statements hidden - click to show
class MapController extends AbstractController
{
#[Route('/map', name: 'app_map')]
public function __invoke(): Response
{
$map = (new Map('default'))
->center(new Point(45.7534031, 4.8295061))
->zoom(6)
->addMarker(new Marker(
position: new Point(45.7534031, 4.8295061),
title: 'Lyon',
infoWindow: new InfoWindow(
content: '<p>Thank you <a href="https://github.com/Kocal">@Kocal</a> for this component!</p>',
)
))
->options((new LeafletOptions())
->tileLayer(new TileLayer(
url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
options: ['maxZoom' => 19]
))
);
return $this->render('ux_packages/map.html.twig', [
'map' => $map,
]);
}
}
{% extends 'base.html.twig' %}
{% block body %}
<div>
{# The map must have a defined height #}
{{ ux_map(map, {style: 'height: 600px;'}) }}
</div>
{% endblock %}
UX Map