Skip to content
Open
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
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This bundle adds google maps integration to [Contao](https://contao.org/de/). It
- frontend module and content element
- insert tag and twig function
- easy contao command based migration tool for [delahaye/dlh_googlemaps](https://github.com/delahaye/dlh_googlemaps) (courtesy to delahaye!)
- GeoJSON layer overlay type replacing the deprecated `KmlLayer`, including a command to convert existing KML files
- responsive support (mobile first), provide responsive configurations that will update the map upon reaching the value (greater than breakpoint)
- support for [hofff/contao-consent-bridge](https://github.com/hofff/contao-consent-bridge)
- support for [Oveleon Cookiebar](https://packagist.org/packages/oveleon/contao-cookiebar)
Expand Down Expand Up @@ -70,6 +71,42 @@ To render your map in a twig template, use `google_map` function:



## GeoJSON layers (replacing KML)

Google's `KmlLayer` is deprecated: unavailable from Maps JavaScript API 3.66 (August 2026), removed in May 2027. The **GeoJSON layer**
overlay type replaces it, built on `google.maps.Data`.

Since GeoJSON has no style specification, styling comes from each feature's [simplestyle](https://github.com/mapbox/simplestyle-spec)
properties (`stroke`, `stroke-width`, `fill`, `icon`, ...), falling back to the overlay's own style settings. Info windows are built from the
remaining properties and use BEM classes (`.huh-geojson-infowindow`, `__text`, `__properties`) without any styling of their own, so style
them in your project.

### Converting existing KML files

```bash
vendor/bin/contao-console huh:google-maps:convert-kml files/maps --dry-run
vendor/bin/contao-console huh:google-maps:convert-kml files/maps --force

# rewrite absolute icon URLs to mirrored local files
vendor/bin/contao-console huh:google-maps:convert-kml files/maps --force \
--icon-base=files/maps/ico --local-host=maps.example.com
```

Writes `<name>.geojson` next to each `<name>.kml` and leaves the sources untouched. Paths may be files or directories (scanned recursively),
defaulting to the project root.

| Option | Description |
|------------------|------------------------------------------------------------------------------------------------------------|
| `--dry-run` | Report what would be written without writing. |
| `--force` | Overwrite existing `.geojson` files. |
| `--icon-base` | Project-relative base path for rewritten icon URLs. Without it, URLs stay untouched. |
| `--local-host` | Host whose icon URLs are rewritten below `--icon-base`. Repeatable. |
| `--keep-folders` | Keep the KML folder hierarchy as `folder`/`folderPath` properties, e.g. to drive a layer switcher. |
| `--precision` | Coordinate decimal places (default `6`). |

Icons on `maps.google.com` are matched by file name below `<icon-base>/google/`. After each run, external URLs left alone and rewritten
paths that do not exist are reported, so broken markers surface before they reach the map.

## 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 ;-)
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"heimrichhannot/contao-utils-bundle": "^3.6",
"ivory/google-map": "^6.0",
"mvo/contao-group-widget": "^1.5",
"symfony/config": "^6.4",
"symfony/console": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/event-dispatcher": "^6.4",
"symfony/http-foundation": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/config": "^6.4 || ^7.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"symfony/event-dispatcher": "^6.4 || ^7.0",
"symfony/http-foundation": "^6.4 || ^7.0",
"symfony/http-kernel": "^6.4 || ^7.0",
"twig/twig": "^3.15"
},
"require-dev": {
Expand Down
6 changes: 5 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ services:

HeimrichHannot\GoogleMapsBundle\:
resource: '../src/{Command,Controller,EventListener,MapBuilder,Security,Twig,Util}/*'
exclude: '../src/EventListener/{MapRendererListener.php,ApiRenderListener.php}'
exclude: '../src/{EventListener/MapRendererListener.php,EventListener/ApiRenderListener.php,Util/KmlConverter.php}'

HeimrichHannot\GoogleMapsBundle\Command\ConvertKmlCommand:
arguments:
$projectDir: '%kernel.project_dir%'

HeimrichHannot\GoogleMapsBundle\Manager\:
resource: '../src/Manager/*'
Expand Down
4 changes: 2 additions & 2 deletions contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/
Expand Down
4 changes: 2 additions & 2 deletions contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/
Expand Down
4 changes: 2 additions & 2 deletions contao/dca/tl_google_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/
Expand Down
128 changes: 126 additions & 2 deletions contao/dca/tl_google_map_overlay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/
Expand Down Expand Up @@ -60,6 +60,7 @@
'markerType',
'clickEvent',
'addRouting',
'geojsonSource',
// CAUTION: type must be at this position, else a Contao palette error takes places!
'type',
'published',
Expand All @@ -69,8 +70,11 @@
OverlayListener::TYPE_INFO_WINDOW => '{general_legend},title,type;{config_legend},positioningMode,infoWindowWidth,infoWindowHeight,infoWindowText,addRouting,zIndex;{publish_legend},published;',
OverlayListener::TYPE_KML_LAYER => '{general_legend},title,type;{config_legend},kmlUrl,kmlClickable,kmlPreserveViewport,kmlScreenOverlays,kmlSuppressInfowindows,zIndex;{publish_legend},published;',
OverlayListener::TYPE_POLYGON => '{general_legend},title,type;{config_legend},pathCoordinates,strokeColor,strokeOpacity,fillColor,fillOpacity,strokeWeight,zIndex;{publish_legend},published;',
OverlayListener::TYPE_GEOJSON_LAYER => '{general_legend},title,type;{config_legend},geojsonSource,geojsonClickable,geojsonFitBounds,zIndex;{style_legend},geojsonStrokeColor,geojsonStrokeWeight,geojsonStrokeOpacity,geojsonFillColor,geojsonFillOpacity,geojsonStylePropertiesEnabled;{publish_legend},published;',
],
'subpalettes' => [
'geojsonSource_'.OverlayListener::GEOJSON_SOURCE_FILE => 'geojsonFile',
'geojsonSource_'.OverlayListener::GEOJSON_SOURCE_URL => 'geojsonUrl',
'titleMode_'.OverlayListener::TITLE_MODE_CUSTOM_TEXT => 'titleText',
'positioningMode_'.OverlayListener::POSITIONING_MODE_COORDINATE => 'positioningLat,positioningLng',
'positioningMode_'.OverlayListener::POSITIONING_MODE_STATIC_ADDRESS => 'positioningAddress',
Expand Down Expand Up @@ -477,6 +481,126 @@
],
'sql' => "char(1) NOT NULL default ''",
],
'geojsonSource' => [
'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['geojsonSource'],
'default' => OverlayListener::GEOJSON_SOURCE_FILE,
'inputType' => 'select',
'options' => OverlayListener::GEOJSON_SOURCES,
'reference' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['reference']['geojsonSource'],
'eval' => [
'submitOnChange' => true,
'mandatory' => true,
'tl_class' => 'w50',
],
'sql' => "varchar(16) NOT NULL default ''",
],
'geojsonFile' => [
'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['geojsonFile'],
'inputType' => 'fileTree',
'eval' => [
'fieldType' => 'radio',
'filesOnly' => true,
'extensions' => 'geojson,json',
'mandatory' => true,
'tl_class' => 'clr',
],
'sql' => 'binary(16) NULL',
],
'geojsonUrl' => [
'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['geojsonUrl'],
'search' => true,
'inputType' => 'text',
'eval' => [
'rgxp' => 'url',
'decodeEntities' => true,
'maxlength' => 255,
'mandatory' => true,
'tl_class' => 'clr w50',
],
'sql' => "varchar(255) NOT NULL default ''",
],
'geojsonClickable' => [
'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['geojsonClickable'],
'filter' => true,
'default' => true,
'inputType' => 'checkbox',
'eval' => [
'tl_class' => 'clr m12',
],
'sql' => "char(1) NOT NULL default '1'",
],
'geojsonFitBounds' => [
'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['geojsonFitBounds'],
'filter' => true,
'default' => false,
'inputType' => 'checkbox',
'eval' => [
'tl_class' => 'm12',
],
'sql' => "char(1) NOT NULL default ''",
],
'geojsonStrokeColor' => [
'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['geojsonStrokeColor'],
'inputType' => 'text',
'eval' => [
'maxlength' => 6,
'isHexColor' => true,
'colorpicker' => true,
'decodeEntities' => true,
'tl_class' => 'w50 wizard',
],
'sql' => "varchar(6) NOT NULL default ''",
],
'geojsonStrokeWeight' => [
'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['geojsonStrokeWeight'],
'inputType' => 'text',
'eval' => [
'rgxp' => 'natural',
'maxlength' => 3,
'tl_class' => 'w50',
],
'sql' => "varchar(3) NOT NULL default ''",
],
'geojsonStrokeOpacity' => [
'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['geojsonStrokeOpacity'],
'inputType' => 'text',
'eval' => [
'maxlength' => 3,
'tl_class' => 'w50',
],
'sql' => "varchar(3) NOT NULL default ''",
],
'geojsonFillColor' => [
'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['geojsonFillColor'],
'inputType' => 'text',
'eval' => [
'maxlength' => 6,
'isHexColor' => true,
'colorpicker' => true,
'decodeEntities' => true,
'tl_class' => 'w50 wizard',
],
'sql' => "varchar(6) NOT NULL default ''",
],
'geojsonFillOpacity' => [
'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['geojsonFillOpacity'],
'inputType' => 'text',
'eval' => [
'maxlength' => 3,
'tl_class' => 'w50',
],
'sql' => "varchar(3) NOT NULL default ''",
],
'geojsonStylePropertiesEnabled' => [
'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['geojsonStylePropertiesEnabled'],
'filter' => true,
'default' => true,
'inputType' => 'checkbox',
'eval' => [
'tl_class' => 'clr m12',
],
'sql' => "char(1) NOT NULL default '1'",
],
'pathCoordinates' => [
'inputType' => 'group',
'palette' => ['positioningLat', 'positioningLng'],
Expand Down
4 changes: 2 additions & 2 deletions contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/
Expand Down
4 changes: 2 additions & 2 deletions contao/dca/tl_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/
Expand Down
5 changes: 2 additions & 3 deletions contao/dca/tl_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/

$dca = &$GLOBALS['TL_DCA']['tl_settings'];

/*
Expand Down
4 changes: 2 additions & 2 deletions contao/dca/tl_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/
Expand Down
4 changes: 2 additions & 2 deletions contao/dca/tl_user_group.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/
Expand Down
4 changes: 2 additions & 2 deletions contao/languages/de/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/
Expand Down
4 changes: 2 additions & 2 deletions contao/languages/de/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/
Expand Down
5 changes: 2 additions & 3 deletions contao/languages/de/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/

$lang = &$GLOBALS['TL_LANG']['tl_content'];

/*
Expand Down
4 changes: 2 additions & 2 deletions contao/languages/de/tl_google_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

/*
* Copyright (c) 2024 Heimrich & Hannot GmbH
/**
* Copyright (c) 2024 Heimrich & Hannot GmbH.
*
* @license LGPL-3.0-or-later
*/
Expand Down
Loading