PHP code example of survos / place-map-bundle

1. Go to this page and download the library: Download survos/place-map-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

survos / place-map-bundle example snippets


final class GenevaMapController extends AbstractController
{
    public function __construct(
        private readonly PlaceRepository $places,
        private readonly PlaceMapBuilder $mapBuilder,
    ) {}

    #[Route('/geneva-map')]
    public function __invoke(): Response
    {
        $geneva = $this->places->find('geneva');

        // Item (photo) markers — plain arrays, NOT ux-map Marker objects: the
        // enhance controller builds its own Leaflet markers from these (see README
        // "Why this split"). thumb is resolved through imgproxy when installed.
        $items = array_map(
            fn (Photo $p) => [
                'lat' => $p->lat, 'lng' => $p->lng,
                'title' => $p->title, 'url' => $this->generateUrl('photo_show', ['id' => $p->id]),
                'thumb' => $this->mapBuilder->resolveThumb($p->imageUrl),
            ],
            $this->photoRepository->findGeocoded(),
        );

        return $this->render('geneva_map.html.twig', [
            'polygon' => $this->mapBuilder->polygonFor($geneva),
            'marker' => $this->mapBuilder->markerFor($geneva),
            'items' => $items,
        ]);
    }
}