heimrichhannot / contao-google-maps-bundle
This bundle adds google maps integration to Contao.
Installs: 3 120
Dependents: 1
Suggesters: 1
Security: 0
Stars: 2
Watchers: 6
Forks: 8
Open Issues: 3
Type:contao-bundle
Requires
- php: ^7.4 || ^8.0
- contao/core-bundle: ^4.9
- doctrine/dbal: ^2.11 || ^3.0
- heimrichhannot/contao-twig-support-bundle: ^0.2.16 || ^1.0
- heimrichhannot/contao-utils-bundle: ^2.213
- ivory/google-map: ^3.0 || ^5.0 || ^6.0
- mvo/contao-group-widget: ^1.4
- symfony/config: ^4.4 || ^5.0
- symfony/console: ^4.4 || ^5.0
- symfony/dependency-injection: ^4.4 || ^5.0
- symfony/event-dispatcher: ^4.4 || ^5.0
- symfony/http-foundation: ^4.4 || ^5.0
- symfony/http-kernel: ^4.4 || ^5.0
- twig/twig: ^1.38.1 || ^2.7.1 || ^3.0
Requires (Dev)
Conflicts
- heimrichhannot/contao-google-maps-list-bundle: *
- heimrichhannot/contao-privacy-center: <2.10
- hofff/contao-consent-bridge: <1.4 || >=2.0
- ivory/google-map: <3.0.4
- dev-master
- 2.11.1
- 2.11.0
- 2.10.2
- 2.10.1
- 2.10.0
- 2.9.0
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.1
- 2.7.0
- 2.6.0
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.0
- 2.0.0-beta16
- 2.0.0-beta15
- 2.0.0-beta14
- 2.0.0-beta13
- 2.0.0-beta12
- 2.0.0-beta11
- 2.0.0-beta10
- 2.0.0-beta9
- 2.0.0-beta8
- 2.0.0-beta7
- 2.0.0-beta6
- 2.0.0-beta5
- 2.0.0-beta4
- 2.0.0-beta3
- 2.0.0-beta2
- 2.0.0-beta1
- v1.x-dev
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- 0.3.0
- 0.2.0
- 0.1.1
- 0.1.0
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-feature/rewrite_privacy_center_integration
- dev-salteax
- dev-feature/enhance_list_config
- dev-feature/better_list_support
- dev-anisimov
This package is auto-updated.
Last update: 2024-09-30 12:28:53 UTC
README
This bundle adds google maps integration to Contao. It's based on ivory/google-map.
Features
- introduces a simple Contao backend entity to configure your Google Map and overlays (markers, info windows, ...)
- frontend module and content element
- insert tag and twig function
- easy contao command based migration tool for delahaye/dlh_googlemaps (courtesy to delahaye!)
- responsive support (mobile first), provide responsive configurations that will update the map upon reaching the value (greater than breakpoint)
- support for List bundle and Reader bundle
- support for hofff/contao-consent-bridge
Setup and usage
Setup
-
Install with contao manager or composer and update database afterwards
composer require heimrichhannot/contao-google-maps-bundle
-
Optional: If you have already google maps created with delahaye/dlh_googlemaps refer to the section "Migrating from dlh_googlemaps".
-
Set your Google API key (capable of Google Maps and Google Static Maps) if not already done in one of the following places (ascending priority):
- global Contao settings (
tl_settings
) - page root (
tl_page
) - Google Maps config (
tl_google_map
)
- global Contao settings (
Usage
- Create a Google Map using the corresponding menu entry in Contao on the left.
- Optional: create markers with the created google map configuration (markers are child entities of a map)
- Now you can integrate the map in your website using one of the following build-in ways:
- Content element
- Module
- Insert tag (see below)
- Twig function (see below)
- render a list as map, list config element or reader config element
List and reader bundle
For both list and reader bundle a config element is provided to add maps to the items.
For lists you also get the option to render the complete list as map.
In your list configuration, check the renderItemsAsMap
option and do the additional configuration.
You can use or adapt the bundled default template: list_google_maps_default.html.twig
and list_item_google_maps_default.html.twig
.
Typical, your list items don't have the correct fields added and filled to be used as markers on a maps.
So you need to implement an event listener for the GoogleMapsPrepareExternalItemEvent
and create or update an overlay object that can be displayed on the map.
class GoogleMapsSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return [GoogleMapsPrepareExternalItemEvent::class => 'onGoogleMapsPrepareExternalItemEvent',]; } public function onGoogleMapsPrepareExternalItemEvent(GoogleMapsPrepareExternalItemEvent $event): void { if (!$event->getConfigModel() instanceof ListConfigModel) { return; } $item = (object)$event->getItemData(); $overlay = new OverlayModel(); $overlay->title = $item->headline; $overlay->type = Overlay::TYPE_MARKER; if ($item->coordX && $item->coordX) { $overlay->positioningMode = Overlay::POSITIONING_MODE_COORDINATE; $overlay->positioningLat = trim($item->coordX); $overlay->positioningLng = trim($item->coordX); } elseif (!empty($item->address)) { $overlay->positioningMode = Overlay::POSITIONING_MODE_STATIC_ADDRESS; $overlay->positioningAddress = $item->address; } else { $event->setOverlayModel(null); return; } $overlay->markerType = Overlay::MARKER_TYPE_SIMPLE; $overlay->clickEvent = Overlay::CLICK_EVENT_INFO_WINDOW; $overlay->infoWindowText = '<p><b>'.$item->headline.'</b></p>'; $overlay->published='1'; $event->setOverlayModel($overlay); } }
Migrating from dlh_googlemaps
Although we cannot guarantee to fully migrate your existing dlh_googlemaps instances, you will nevertheless have a point to start from. Think of it as a 95% migration ;-)
Migrating is as simple as running vendor/bin/contao-console huh:google-maps:migrate-dlh
from your contao root dir. Your dlh google maps are not changed by this process, only new instances in tl_google_map
and tl_google_map_overlay
are created out of the existing legacy data.
Insert Tags
Twig functions
TODO
- Overlay types:
- polyline
- circle
- rectangle
- ground_overlay