45 Commits
3.0.0 ... 3.1.3

Author SHA1 Message Date
David Molineus
c4feeb1b38 Add missing error block. 2019-01-10 16:41:03 +01:00
David Molineus
cb3e9bc8b4 Make controller public as it's required by Symfony 4. 2019-01-10 16:39:43 +01:00
David Molineus
6a88ed380b Update travis configuration for compatibility issues with phpcq v1.2.0. Test against PHP 7.3 as well. 2018-12-18 10:56:29 +01:00
David Molineus
4ea2adbb85 Merge tag '3.1.2' 2018-12-18 09:26:49 +01:00
David Molineus
dc5a0a081e Complete implementation of tile providers. 2018-12-18 09:23:47 +01:00
David Molineus
79f6efd9f3 Update leaflet providers. 2018-12-17 17:01:08 +01:00
David Molineus
e7bede78b1 Drop not required .htaccess folder. 2018-12-17 15:21:05 +01:00
David Molineus
997e16891b Add defined check. 2018-12-17 15:20:51 +01:00
David Molineus
d5407357d8 Merge tag '3.1.1' 2018-12-07 11:22:41 +01:00
David Molineus
1ba19f63b1 Prepare release. 2018-12-07 11:22:23 +01:00
David Molineus
878492c0b1 Fix Code style. 2018-12-07 11:22:16 +01:00
David Molineus
57ba63556a Ignore markers without defined coordinates. 2018-12-06 10:37:39 +01:00
David Molineus
0e2b8dd3cd Fix missing marker cluster icon. 2018-11-01 16:01:16 +01:00
David Molineus
91d3786187 Merge tag '3.1.0' 2018-11-01 15:37:04 +01:00
David Molineus
5e20b83503 Prepare release. 2018-11-01 15:36:35 +01:00
David Molineus
ca103521aa add url-polyfill to about page. 2018-11-01 15:34:58 +01:00
David Molineus
f422459be2 Gulp task improvement. 2018-11-01 11:37:32 +01:00
David Molineus
c661abb626 Fix dynamic data loading for new request url. 2018-11-01 10:26:38 +01:00
David Molineus
83226cdd80 Fix gulp watch task. 2018-11-01 10:25:54 +01:00
David Molineus
ed10175072 Add hint that zoom level is probably required (Close #56). 2018-10-30 13:00:52 +01:00
David Molineus
d2338332b4 Rewrite about page using own route (Close #48). 2018-10-30 12:38:46 +01:00
David Molineus
7aa4f38902 Update readme. 2018-10-30 10:53:44 +01:00
David Molineus
cb03dcfa41 Fix broken marker cluster (#60). 2018-10-30 10:52:47 +01:00
David Molineus
2108de32d9 Add support for distance filter for the marker layer. 2018-10-30 10:48:38 +01:00
David Molineus
314e2d21ee Update readme. 2018-10-30 09:53:12 +01:00
David Molineus
6faaa866ad Use minified scripts. 2018-10-30 09:38:38 +01:00
David Molineus
b22563b38c Prevent form submit on enter when using control geocoder and close popup when value is chosen. 2018-10-30 09:36:06 +01:00
David Molineus
a10e55a126 Fix: Do not cache insert tags as it would create esi tags. 2018-10-30 08:45:47 +01:00
David Molineus
e27ac21902 Also replace non cachable inserttags. 2018-10-29 16:24:07 +01:00
David Molineus
0ba725ed38 Implement custom route for data request to prevent partial rendering of the page and it's possible issues (f.e. form captcha changes) (Close #49). 2018-10-29 16:02:50 +01:00
David Molineus
7ec2ee0d96 Upgrade to gulp 4.0. 2018-10-29 15:46:38 +01:00
David Molineus
9e54f12555 Use TL_CSS_UNITS for with and height option (#59). 2018-10-19 16:37:49 +02:00
David Molineus
b323049f9d Merge tag '3.0.4' 2018-10-08 16:26:20 +02:00
David Molineus
873de89d7c Fix broken content element attributes (Missing class and custom id). 2018-10-08 16:26:04 +02:00
David Molineus
88927a3de8 Change format of changelog and add semver note. 2018-09-18 10:33:32 +02:00
David Molineus
8fdc7dab29 Make alias generator services public for Contao 4.6/Symfony 4.0 compatibility. 2018-09-18 10:26:38 +02:00
David Molineus
9a1b6dee01 Merge tag '3.0.2' 2018-08-23 14:50:34 +02:00
David Molineus
9e0f11ec18 Prevent cacheKey is not set. 2018-08-23 14:48:58 +02:00
David Molineus
f60ed1b7be Fix changelog versions. 2018-08-23 14:36:46 +02:00
David Molineus
3d45f6b2eb Run composer require checker and solve issues. 2018-08-23 14:35:25 +02:00
David Molineus
e73a4d4bdf Merge tag '3.0.1' 2018-06-20 08:30:50 +02:00
David Molineus
0322a87e94 Fix license. 2018-06-20 08:30:14 +02:00
David Molineus
f5e8701312 Update readme. 2018-06-20 08:25:47 +02:00
David Molineus
2d0221a90a Fix broken filter factory (Close #57). 2018-06-20 08:24:22 +02:00
David Molineus
9f0b34a53b Merge tag '3.0.0' 2018-01-05 17:11:39 +01:00
65 changed files with 4450 additions and 319 deletions

View File

@@ -0,0 +1,11 @@
{
"symbol-whitelist": [
"null", "true", "false",
"static", "self", "parent",
"array", "string", "int", "float", "bool", "iterable", "callable", "void", "object",
"array_insert",
"Contao\\ManagerPlugin\\Bundle\\BundlePluginInterface",
"Contao\\ManagerPlugin\\Bundle\\Config\\BundleConfig",
"Contao\\ManagerPlugin\\Bundle\\Parser\\ParserInterface"
]
}

1
.gitignore vendored
View File

@@ -25,4 +25,3 @@ build.properties
# NPM
node_modules
package-lock.json

View File

@@ -1,12 +1,21 @@
dist: xenial
addons:
apt:
packages:
- ant-optional
language: php
php:
- "7.0"
- "7.1"
- "7.3"
- "7.2"
- "7.1"
env:
- CONTAO_VERSION=contao/core-bundle ~4.4.0
- CONTAO_VERSION=contao/core-bundle ~4.5.0
- CONTAO_VERSION=contao/core-bundle ~4.6.0
matrix:
exclude:

View File

@@ -1,16 +1,114 @@
Changelog
=========
# Changelog
3.0.0 (2018-01-05)
------------------
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 3.1.3 - 2019-01-10
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.1.2...3.1.3)
### Fixed
- Fix broken api routes in Contao 4.6/Symfony 4 (#69)
- Fix broken about.html.twig template. Error block was missing
## 3.1.2 - 2018-12-18
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.1.1...3.1.2)
### Fixed
- Fix broken MapBox integration: Access token is now required
- Fix broken OpenWeatherMap integration: Api key is now required
- Fix broken Thunderforest integration: Api key is now required
### Added
- Add missing OpenPtMap of leaflet-providers
- Add missing OpenRailwayMap of leaflet-providers
- Add missing OpenFireMap of leaflet-providers
- Add missing SafeCast of leaflet-providers
- Add missing map types `normalNightTransit`, `normalNightTransitMobile`, `reducedDay`, `reducedNight`,
`hybridDayTransit` and `hybridDayGrey` of HERE provider
- Add missing map types `Voyager`, `VoyagerNoLabels`, `VoyagerOnlyLabels` and `VoyagerLabelsUnder` of CartoDB provider
- Add missing Wikimedia of leaflet-providers
- Add missing GeoportailFrance of leaflet-providers
- Add missing OneMapSG of leaflet-providers
## 3.1.1 - 2018-12-07
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.1.0...3.1.1)
### Fixed
- Fix missing marker cluster icon.
- Ignore markers without coordinates to prevent uncaught exception caused by invalid coordinates.
## 3.1.0 - 2018-11-01
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.0.4...3.1.0)
### Added
- Custom route to load map data.
- Add distance filter support for the marker layer (Bounds Mode "fit" has to be enabled).
- Add support for relative css units for map size definition (#59).
- Add hint that zoom level is probably required (#56).
### Deprecated
- Deprecate `Netzmacht\Contao\Leaflet\Frontend\RequestUrl`. Use router to generate request url for layer data.
- Deprecate `Netzmacht\Contao\Leaflet\Frontend\DataController`. Use introduced endpoint to get map data.
### Changed
- Require PHP 7.1.
- Rewritten about page using own route (#48).
### Fixed
- Pressing enter on backend geocode control doesn't submit form anymore.
- Fix broken marker cluster layer (#60).
## 3.0.4 - 2018-10-08
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.0.3...3.0.4)
### Fixed
- Fix broken content element attributes (Missing class and custom id).
## 3.0.3 - 2018-09-18
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.0.2...3.0.3)
### Fixed
- Make alias generator services public for Contao 4.6/Symfony 4.0 compatibility.
## 3.0.2 - 2018-08-23
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.0.1...3.0.2)
- Run composer require checker and solve issues.
## 3.0.1 - 2018-06-20
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.0.0...3.0.1)
- Fix broken dynamic bbox related data loading (#57)
## 3.0.0 - 2018-01-05
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.0.0-beta1...3.0.0)
- Make hook/dca listener services public
3.0.0-beta1 (2017-11-15)
------------------------
## 3.0.0-beta1 - 2017-11-15
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.0.0-alpha2...3.0.0-beta1)
@@ -23,15 +121,9 @@ Bugfixes
- Broken service definitions
- Broken file layer id
3.0.0-alpha2
------------
## 3.0.0-alpha1 - 2017-10-19
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.0.0-alpha2...2.0.0-alpha3)
3.0.0-alpha1 (2017-10-19)
------------------------
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.0.0-alpha1...2.0.0-alpha2)
[Full Changelog](https://github.com/netzmacht/contao-leaflet-maps/compare/3.0.0-alpha1...3.0.0-alpha2)
Implemented enhancements

View File

@@ -7,7 +7,7 @@
"leaflet"
],
"type": "contao-bundle",
"license": "LGPL-3.0+",
"license": "LGPL-3.0-or-later",
"authors": [
{
"name": "David Molineus",
@@ -22,20 +22,32 @@
"source": "https://github.com/netzmacht/contao-leaflet-maps"
},
"require": {
"php": ">=7.0",
"php": ">=7.1",
"ext-json": "*",
"ext-pdo": "*",
"contao/core-bundle": "~4.4",
"netzmacht/contao-leaflet-libraries": "^1.0",
"doctrine/dbal": "^2.5",
"symfony/config": "~3.3 || ~4.0",
"symfony/event-dispatcher": "~3.3 || ~4.0",
"symfony/dependency-injection": "~3.3 || ~4.0",
"symfony/filesystem": "~3.3 || ~4.0",
"symfony/http-kernel": "~3.3 || ~4.0",
"symfony/translation": "~3.3 || ~4.0",
"symfony/templating": "~3.3 || ~4.0",
"netzmacht/contao-leaflet-libraries": "^1.3.4",
"netzmacht/contao-leaflet-geocode-widget": "^1.2",
"netzmacht/php-javascript-builder": "^1.0",
"netzmacht/php-leaflet": "^1.0.2",
"netzmacht/php-leaflet": "^1.1.0",
"netzmacht/contao-toolkit": "~3.0",
"netzmacht/contao-page-context": "~1.0",
"contao-community-alliance/meta-palettes": "^2.0 || ^1.5",
"menatwork/contao-multicolumnwizard": "^3.2",
"doctrine/cache": "^1.0"
},
"require-dev": {
"phpcq/all-tasks": "^1.2",
"contao/manager-plugin": "^2.1"
"contao/manager-plugin": "^2.1",
"phpstan/phpstan": "^0.10.3"
},
"autoload": {
"psr-4": {
@@ -49,8 +61,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev",
"dev-develop": "3.1.x-dev",
"dev-master": "3.1.x-dev",
"dev-develop": "3.2.x-dev",
"dev-support/2.x": "2.0.x-dev"
},
"contao-manager-plugin": "Netzmacht\\Contao\\Leaflet\\Bundle\\ContaoManager\\Plugin",

View File

@@ -1,28 +1,35 @@
var gulp = require('gulp');
var del = require('del');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
const { series, src, watch, dest, parallel, task} = require('gulp');
const del = require('promised-del');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
var paths = {
minified: 'contao-leaflet.js',
scripts: ['js/*.js'],
scripts: ['js/vendor/*.js', 'js/*.js'],
dest: 'src/Bundle/Resources/public/js'
};
gulp.task('clear', function() {
del([paths.dest + '/' + paths.minified]);
});
function clean () {
return del([paths.dest + '/' + paths.minified]);
}
gulp.task('scripts', ['clear'], function() {
return gulp.src(paths.scripts)
function build () {
return src(paths.scripts)
.pipe(concat(paths.minified))
.pipe(uglify())
.pipe(gulp.dest(paths.dest));
});
.pipe(dest(paths.dest));
}
const buildTasks = series(clean, build);
gulp.task('default', ['scripts']);
function watchTask () {
watch(
paths.scripts,
buildTasks
)
}
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['scripts']);
});
exports.clean = clean;
exports.watch = watchTask;
exports.build = buildTasks;
exports.default = buildTasks;

View File

@@ -138,7 +138,8 @@ L.Contao = L.Evented.extend({
* @param customLayer optional custom layer.
* @param map Pass a map object so that the data loading events are passed to the map.
*/
loadFile: function (url, type, options, customLayer, map) {
loadUrl: function (url, type, options, customLayer, map) {
url = this.applyFilterToUrl(url, map);
var layer = omnivore[type](url, options, customLayer);
if (map) {
@@ -147,7 +148,7 @@ L.Contao = L.Evented.extend({
// Add listener for map bounds changes.
if (map.options.dynamicLoad && layer.options.boundsMode == 'fit') {
layer.options.requestHash = hash;
layer.options.requestUrl = url;
map.on('moveend', layer.refreshData, layer);
map.on('layerremove', function(e) {
@@ -172,6 +173,19 @@ L.Contao = L.Evented.extend({
return layer;
},
/**
* Load data from an url into a layer using omnivore.
*
* @param url A file url.
* @param type The response content format.
* @param options Parser options
* @param customLayer optional custom layer.
* @param map Pass a map object so that the data loading events are passed to the map.
*/
loadFile: function (url, type, options, customLayer, map) {
return this.loadUrl(url, type, options, customLayer, map);
},
/**
* Point to layer callback. Adds a geo json point to the layer.
*
@@ -313,6 +327,36 @@ L.Contao = L.Evented.extend({
}
return value;
},
/**
* Apply the filter to a request url.
*
* @param {string} url The request url.
* @param {L.Map} map The map.
*
* @returns {string}
*/
applyFilterToUrl: function (url, map) {
var value, query, bounds;
if (!map || !map.options.dynamicLoad) {
return url;
}
url = new URL(url);
query = new URLSearchParams(url.search);
bounds = map.getBounds();
value = bounds.getSouth() + ',' + bounds.getWest();
value += ',' + bounds.getNorth() + ',' + bounds.getEast();
query.set('filter', 'bbox');
query.set('values', value);
url.search = query.toString();
return url.toString();
}
});

View File

@@ -29,6 +29,6 @@ L.GeoJSON.include({
});
// TODO: Allow other data formats.
omnivore.geojson(L.contao.createRequestUrl(this.options.requestHash, e.target), null, dataLayer);
omnivore.geojson(L.contao.applyFilterToUrl(this.options.requestUrl, e.target), null, dataLayer);
}
});

3297
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -4,10 +4,11 @@
"description": "Leaflet maps for Contao",
"main": "gulpfile.js",
"dependencies": {
"del": "^3.0.0",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.0",
"gulp-uglify": "^3.0.0"
"gulp": "^4.0.0",
"gulp-cli": "^2.0.1",
"gulp-concat": "^2.6.1",
"gulp-uglify": "^3.0.1",
"promised-del": "^1.0.2"
},
"devDependencies": {},
"scripts": {
@@ -23,7 +24,7 @@
"Maps"
],
"author": "netzmacht David Molineus",
"license": "LGPL-3.0",
"license": "LGPL-3.0-or-later",
"bugs": {
"url": "https://github.com/netzmacht/contao-leaflet-maps/issues"
},

View File

@@ -10,30 +10,59 @@
* @filesource
*/
namespace Netzmacht\Contao\Leaflet\Backend;
namespace Netzmacht\Contao\Leaflet\Backend\Action;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as Engine;
use Symfony\Component\HttpFoundation\Response;
/**
* Credits backend module.
*
* @package Netzmacht\Contao\Leaflet\Backend
*/
class About
final class AboutAction
{
/**
* Templating engine.
*
* @var Engine
*/
private $engine;
/**
* Project directory.
*
* @var string
*/
private $projectDir;
/**
* AboutAction constructor.
*
* @param Engine $engine Templating engine.
* @param string $projectDir Project directory.
*/
public function __construct(Engine $engine, string $projectDir)
{
$this->engine = $engine;
$this->projectDir = $projectDir;
}
/**
* Generate the backend view.
*
* @return string
*/
public function generate()
public function __invoke(): Response
{
$template = new \BackendTemplate('be_leaflet_about');
$data = [
'headline' => 'Leaftlet maps integration for Contao CMS',
'libraries' => $this->getLibraries(),
];
$template->headline = 'Leaftlet maps integration for Contao CMS';
$template->libraries = $this->getLibraries();
[$data['version'], $data['dependencies']] = $this->extractFromComposer();
list($template->version, $template->dependencies) = $this->extractFromComposer();
return $template->parse();
return $this->engine->renderResponse('@NetzmachtContaoLeaflet/backend/about.html.twig', $data);
}
/**
@@ -43,7 +72,7 @@ class About
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
private function getLibraries()
private function getLibraries(): array
{
return array_map(
function ($library) {
@@ -57,9 +86,8 @@ class About
if ($library['homepage']) {
$library['homepage'] = sprintf(
'<a href="%s" %s>%s</a>',
'<a href="%s" target="_blank">%s</a>',
$library['homepage'],
LINK_NEW_WINDOW,
preg_replace('#^(https?://(www)?)#i', '', $library['homepage'])
);
}
@@ -69,7 +97,7 @@ class About
array_filter(
$GLOBALS['LEAFLET_LIBRARIES'],
function ($library) {
return isset($library['name']) && isset($library['license']);
return isset($library['name'], $library['license']);
}
)
);
@@ -80,10 +108,10 @@ class About
*
* @return array
*/
private function extractFromComposer()
private function extractFromComposer(): array
{
$extFile = TL_ROOT . '/vendor/netzmacht/contao-leaflet-maps/composer.json';
$lockFile = TL_ROOT . '/composer.lock';
$extFile = $this->projectDir . '/vendor/netzmacht/contao-leaflet-maps/composer.json';
$lockFile = $this->projectDir . '/composer.lock';
if (!file_exists($extFile) || !file_exists($lockFile)) {
return [];

View File

@@ -18,15 +18,20 @@ use Contao\CoreBundle\ContaoCoreBundle;
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\ManagerPlugin\Routing\RoutingPluginInterface;
use Netzmacht\Contao\Leaflet\Bundle\NetzmachtContaoLeafletBundle;
use Netzmacht\Contao\PageContext\NetzmachtContaoPageContextBundle;
use Netzmacht\Contao\Toolkit\Bundle\NetzmachtContaoToolkitBundle;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\RouteCollection;
/**
* Contao manager plugin.
*
* @package Netzmacht\Contao\Leaflet\ContaoManager
*/
class Plugin implements BundlePluginInterface
class Plugin implements BundlePluginInterface, RoutingPluginInterface
{
/**
* {@inheritdoc}
@@ -35,8 +40,27 @@ class Plugin implements BundlePluginInterface
{
return [
BundleConfig::create(NetzmachtContaoLeafletBundle::class)
->setLoadAfter([ContaoCoreBundle::class, NetzmachtContaoToolkitBundle::class])
->setLoadAfter(
[
ContaoCoreBundle::class,
NetzmachtContaoToolkitBundle::class,
NetzmachtContaoPageContextBundle::class
]
)
->setReplace(['leaflet']),
];
}
/**
* {@inheritdoc}
*/
public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel): ?RouteCollection
{
$loader = $resolver->resolve(__DIR__ . '/../Resources/config/routing.yml');
if (!$loader) {
return null;
}
return $loader->load(__DIR__ . '/../Resources/config/routing.yml');
}
}

View File

@@ -32,7 +32,7 @@ parameters:
markercluster:
children: true
icon: 'bundles/netzmachtcontaoleaflet/img/markercluster.png'
icon: 'bundles/netzmachtcontaoleaflet/img/cluster.png'
tile:
children: false

View File

@@ -30,6 +30,8 @@ services:
- '@netzmacht.contao_toolkit.dca.manager'
- '@database_connection'
- '@netzmacht.contao_toolkit.repository_manager'
- '@translator'
- '@session'
netzmacht.contao_leaflet.listeners.dca.control:
class: Netzmacht\Contao\Leaflet\Listener\Dca\ControlDcaListener
@@ -113,3 +115,13 @@ services:
- '@netzmacht.contao_leaflet.definition.builder'
tags:
- { name: 'contao.hook', hook: 'initializeSystem', method: 'onInitializeSystem' }
netzmacht.contao_leaflet.listeners.backend_menu:
class: Netzmacht\Contao\Leaflet\Listener\Backend\UserNavigationListener
arguments:
- '@request_stack'
- '@router'
- '@translator'
- '@netzmacht.contao_toolkit.assets_manager'
tags:
- { name: 'contao.hook', hook: 'getUserNavigation', method: '__invoke'}

View File

@@ -32,6 +32,7 @@ services:
class: Netzmacht\Contao\Leaflet\Mapper\Layer\MarkersLayerMapper
arguments:
- '@netzmacht.contao_toolkit.repository_manager'
- '@router'
tags:
- { name: netzmacht.contao_leaflet.mapper }
@@ -46,6 +47,7 @@ services:
class: Netzmacht\Contao\Leaflet\Mapper\Layer\VectorsLayerMapper
arguments:
- '@netzmacht.contao_toolkit.repository_manager'
- '@router'
tags:
- { name: netzmacht.contao_leaflet.mapper }
@@ -69,7 +71,7 @@ services:
- '@netzmacht.contao_leaflet.map.assets'
- '@netzmacht.contao_toolkit.repository_manager'
tags:
- { name: netzmacht.contao_leflet_maps.mapper }
- { name: netzmacht.contao_leaflet.mapper }
netzmacht.contao_leaflet.mapper.file_layer:
class: Netzmacht\Contao\Leaflet\Mapper\Layer\FileLayerMapper

View File

@@ -1,13 +1,22 @@
parameters:
netzmacht.contao_leaflet.providers:
OpenStreetMap:
variants: ['Mapnik', 'BlackAndWhite', 'DE', 'France', 'HOT', 'BZH']
variants: ['Mapnik', 'BlackAndWhite', 'DE', 'CH', 'France', 'HOT', 'BZH']
OpenSeaMap: []
OpenTopoMap: []
OpenPtMap: []
OpenRailwayMap: []
OpenFireMap: []
SafeCast: []
Thunderforest:
class: 'Netzmacht\LeafletPHP\Plugins\LeafletProviders\ThunderforestProvider'
variants:
- 'OpenCycleMap'
- 'Transport'
@@ -16,6 +25,9 @@ parameters:
- 'Landscape'
- 'Outdoors'
- 'Pioneer'
options:
apiKey: 'tile_provider_key'
fields: ['tile_provider_key']
OpenMapSurfer:
variants: ['Roads', 'AdminBounds', 'Grayscale']
@@ -26,7 +38,8 @@ parameters:
MapBox:
class: 'Netzmacht\LeafletPHP\Plugins\LeafletProviders\MapBoxProvider'
options:
key: 'tile_provider_key'
accessToken: 'tile_provider_key'
fields: ['tile_provider_key']
Stamen:
variants:
@@ -56,6 +69,7 @@ parameters:
- 'WorldGrayCanvas'
OpenWeatherMap:
class: 'Netzmacht\LeafletPHP\Plugins\LeafletProviders\OpenWeatherMapProvider'
variants:
- 'Clouds'
- 'CloudsClassic'
@@ -68,6 +82,9 @@ parameters:
- 'Wind'
- 'Temperature'
- 'Snow'
options:
apiKey: 'tile_provider_key'
fields: ['tile_provider_key']
HERE:
class: 'Netzmacht\LeafletPHP\Plugins\LeafletProviders\HereProvider'
@@ -83,12 +100,18 @@ parameters:
- 'normalNightMobile'
- 'normalNightGrey'
- 'normalNightGreyMobile'
- 'normalNightTransit'
- 'normalNightTransitMobile'
- 'reducedDay'
- 'reducedNight'
- 'basicMap'
- 'mapLabels'
- 'trafficFlow'
- 'carnavDayGrey'
- 'hybridDay'
- 'hybridDayMobile'
- 'hybridDayTransit'
- 'hybridDayGrey'
- 'pedestrianDay'
- 'pedestrianNight'
- 'satelliteDay'
@@ -123,6 +146,10 @@ parameters:
- 'DarkMatter'
- 'DarkMatterNoLabels'
- 'DarkMatterOnlyLabels'
- 'Voyager'
- 'VoyagerNoLabels'
- 'VoyagerOnlyLabels'
- 'VoyagerLabelsUnder'
HikeBike:
variants:
@@ -155,3 +182,20 @@ parameters:
- 'ModisTerraChlorophyll'
NLS: []
Wikimedia: []
GeoportailFrance:
variants:
- 'parcels'
- 'ignMaps'
- 'maps'
- 'orthos'
OneMapSG:
variants:
- 'Default'
- 'Night'
- 'Original'
- 'Grey'
- 'LandLot'

View File

@@ -0,0 +1,18 @@
leaflet_layer:
path: /leaflet/api/layer/{layerId}
controller: Netzmacht\Contao\Leaflet\Frontend\Action\LayerDataAction
defaults:
_leaflet_scope: page
_format: geojson
_scope: frontend
requirements:
_format: geojson
context: \w+
contextId: \d+
leaflet_backend_about:
path: /contao/leaflet/about
controller: Netzmacht\Contao\Leaflet\Backend\Action\AboutAction
defaults:
_scope: backend
_backend_module: leaflet_about

View File

@@ -74,11 +74,13 @@ services:
netzmacht.contao_leaflet.definition.alias_generator.factory_default:
class: Netzmacht\Contao\Leaflet\Alias\DefaultAliasGeneratorFactory
public: true
arguments:
- '@database_connection'
netzmacht.contao_leaflet.definition.alias_generator.factory_parent:
class: Netzmacht\Contao\Leaflet\Alias\ParentAliasGeneratorFactory
public: true
arguments:
- '@database_connection'
@@ -120,3 +122,19 @@ services:
arguments:
- '@netzmacht.contao_leaflet.filter_factory'
- '%kernel.debug%'
Netzmacht\Contao\Leaflet\Frontend\PageIdDeterminator:
tags:
- { name: Netzmacht\Contao\PageContext\Request\PageIdDeterminator }
Netzmacht\Contao\Leaflet\Frontend\Action\LayerDataAction:
public: true
arguments:
- '@netzmacht.contao_leaflet.map.provider'
- '@netzmacht.contao_leaflet.filter_factory'
Netzmacht\Contao\Leaflet\Backend\Action\AboutAction:
public: true
arguments:
- '@templating'
- '%kernel.project_dir%'

View File

@@ -40,16 +40,11 @@ array_insert(
'stylesheet' => 'bundles/netzmachtcontaoleaflet/css/backend.css',
'javascript' => 'bundles/netzmachtcontaoleaflet/js/backend.js',
],
'leaflet_about' => [
'callback' => Netzmacht\Contao\Leaflet\Backend\About::class,
'icon' => 'bundles/netzmachtcontaoleaflet/img/about.png',
'stylesheet' => 'bundles/netzmachtcontaoleaflet/css/about.css',
],
],
]
);
if (TL_MODE === 'BE') {
if (defined('TL_MODE') && TL_MODE === 'BE') {
$GLOBALS['TL_CSS'][] = 'bundles/netzmachtcontaoleaflet/css/backend_global.css';
}

View File

@@ -49,7 +49,7 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['leaflet_mapId'] = [
$GLOBALS['TL_DCA']['tl_content']['fields']['leaflet_width'] = [
'label' => &$GLOBALS['TL_LANG']['tl_content']['leaflet_width'],
'inputType' => 'inputUnit',
'options' => ['px', '%', 'em', 'pt', 'pc', 'in', 'cm', 'mm'],
'options' => $GLOBALS['TL_CSS_UNITS'],
'search' => false,
'exclude' => true,
'eval' => ['rgxp' => 'digit', 'tl_class' => 'clr w50'],
@@ -60,7 +60,7 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['leaflet_width'] = [
$GLOBALS['TL_DCA']['tl_content']['fields']['leaflet_height'] = [
'label' => &$GLOBALS['TL_LANG']['tl_content']['leaflet_height'],
'inputType' => 'inputUnit',
'options' => ['px', '%', 'em', 'pt', 'pc', 'in', 'cm', 'mm'],
'options' => $GLOBALS['TL_CSS_UNITS'],
'search' => false,
'exclude' => true,
'eval' => ['rgxp' => 'digit', 'tl_class' => 'w50'],

View File

@@ -232,12 +232,14 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [
'provider' => ['tile_provider', 'tile_provider_variant'],
],
'tile_provider' => [
'MapBox' => ['tile_provider_key'],
'HERE' => ['tile_provider_key', 'tile_provider_code'],
'MapBox' => ['tile_provider_key'],
'HERE' => ['tile_provider_key', 'tile_provider_code'],
'OpenWeatherMap' => ['tile_provider_key'],
'Thunderforest' => ['tile_provider_key'],
],
'fileFormat' => [
'!' => ['file'],
],
'fileFormat' => [
'!' => ['file']
]
],
'metasubpalettes' => [
@@ -864,7 +866,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [
],
'sql' => 'mediumtext NULL',
],
'fileFormat' => [
'fileFormat' => [
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormat'],
'exclude' => true,
'inputType' => 'select',
@@ -882,19 +884,19 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [
'sql' => "varchar(32) NOT NULL default ''",
],
'file' => [
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['file'],
'exclude' => true,
'inputType' => 'fileTree',
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['file'],
'exclude' => true,
'inputType' => 'fileTree',
'load_callback' => [
['netzmacht.contao_leaflet.listeners.dca.layer', 'prepareFileWidget'],
],
'eval' => [
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => true,
'tl_class' => 'clr',
'eval' => [
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => true,
'tl_class' => 'clr',
],
'sql' => 'binary(16) NULL',
'sql' => 'binary(16) NULL',
],
],
];

View File

@@ -23,6 +23,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = [
],
'onload_callback' => [
['netzmacht.contao_leaflet.listeners.dca.leaflet', 'loadLanguageFile'],
['netzmacht.contao_leaflet.listeners.dca.map', 'addIncompleteConfigurationWarning'],
],
'onsubmit_callback' => [
['netzmacht.contao_leaflet.listeners.dca.leaflet', 'clearCache'],

View File

@@ -49,7 +49,7 @@ $GLOBALS['TL_DCA']['tl_module']['fields']['leaflet_mapId'] = [
$GLOBALS['TL_DCA']['tl_module']['fields']['leaflet_width'] = [
'label' => &$GLOBALS['TL_LANG']['tl_module']['leaflet_width'],
'inputType' => 'inputUnit',
'options' => ['px', '%', 'em', 'pt', 'pc', 'in', 'cm', 'mm'],
'options' => $GLOBALS['TL_CSS_UNITS'],
'search' => false,
'exclude' => true,
'eval' => ['rgxp' => 'digit', 'tl_class' => 'clr w50'],
@@ -60,7 +60,7 @@ $GLOBALS['TL_DCA']['tl_module']['fields']['leaflet_width'] = [
$GLOBALS['TL_DCA']['tl_module']['fields']['leaflet_height'] = [
'label' => &$GLOBALS['TL_LANG']['tl_module']['leaflet_height'],
'inputType' => 'inputUnit',
'options' => ['px', '%', 'em', 'pt', 'pc', 'in', 'cm', 'mm'],
'options' => $GLOBALS['TL_CSS_UNITS'],
'search' => false,
'exclude' => true,
'eval' => ['rgxp' => 'digit', 'tl_class' => 'w50'],

View File

@@ -0,0 +1,15 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2018 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
$GLOBALS['TL_LANG']['ERR']['leafletMissingZoomLevel'] = 'No zoom level defined. Only leave it empty on purpose (Zoom level might by initialized by bounds adjustments). Otherwise no map will be shown.';

View File

@@ -149,6 +149,10 @@ $GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormat'][0] = 'File
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormat'][1] = 'Choose which file format is used.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['file'][0] = 'File';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['file'][1] = 'Choose a file containing geodata. Supported formats are: %s.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_key'][0] = 'API key / Access token';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_key'][1] = 'Please define the API key / access token which is required for this tile provider.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_code'][0] = 'App code';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_code'][1] = 'Please define the required app code for this tile provider.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][0] = 'Layer group';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][1] = 'Basic layer group. <br> See <a href="http://leafletjs.com/reference.html#layergroup" target="_blank">http://leafletjs.com/reference.html#layergroup</a>';

View File

@@ -1,7 +0,0 @@
<IfModule !mod_authz_core.c>
Order allow,deny
Allow from all
</IfModule>
<IfModule mod_authz_core.c>
Require all granted
</IfModule>

View File

@@ -1,140 +0,0 @@
<div class="netzmacht-leaflet-credits">
<div class="header">
<h1 class="sub_headline"><?php echo $this->headline; ?>
<small><?php echo $this->version; ?></small>
</h1>
</div>
<div class="tl_box block row">
<h2>About</h2>
<div class="left">
<p>
The Leaflet maps integration for Contao CMS is an Open Source Software license under the LGPL 3.0.
This extension is only exists because of great other Open Source Software which it heavenly depends on.
</p>
<p>
This software ships with an visible attribution to <em>netzmacht creative</em> in the map attribution
control.
If you want to remove this attribution, you have to purchase a commercial license.
For more details visit the <a href="https://netzmacht.de/contao-leaflet" target="_blank">project
website</a>.
</p>
</div>
<div class="right">
<a href="http://www.netzmacht.de" <?php echo LINK_NEW_WINDOW; ?>>
<img src="bundles/netzmachtcontaoleaflet/img/logo.png"></a>
<p>
<strong class="company">netzmacht </strong><br>
David Molineus<br>
</p>
<p>
DAB Bank München<br>
IBAN: DE52701204008354237003<br>
BIC: DABBDEMMXXX
</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="YWMA95YS3FT6U">
<input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_donate_SM.gif" border="0"
name="submit" alt="PayPal The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</div>
<div class="tl_box">
<h2>Support Contao Leaflet</h2>
<div class="row">
<div class="col">
<h3>Report issues</h3>
<p>If you found a bug, got some troubles or have a feature request - feel free to open an issue.</p>
<p><a href="http://github.com/netzmacht/contao-leaflet-maps/issues" class="btn" target="_blank">Issue
tracker</a></p>
</div>
<div class="col">
<h3>Contribute</h3>
<p>There are many ways you can con&shy;tribute. Translations,
docu&shy;mentation or code contributions are welcome.
</p>
<p><a href="https://netzmacht/contao-leaflet/contribute.html" class="btn" target="_blank">Contribute</a>
</p>
</div>
<div class="col">
<h3>Fund a feature</h3>
<p>Contao Leaflet is not feature complete. Have a look at the list of planned feature and support
them.</p>
<p><a href="https://netzmacht/contao-leaflet/planned-features.html" class="btn" target="_blank">Planned
features</a></p>
</div>
</div>
<div class="row">
<div class="col">
<h3>Individual development</h3>
<p>If you have special requirements you can hire me for an individual development.</p>
<p><a href="https://netzmacht/contao-leaflet/contact.html" class="btn" target="_blank">Contact</a></p>
</div>
<div class="col">
<h3>Commercial license</h3>
<p>If you want to remove the attribution in the attribution control, you can purchase a commercial
license.</p>
<p><a href="https://netzmacht/contao-leaflet/commercial-license.html" class="btn" target="_blank">Purchase
license</a></p>
</div>
</div>
</div>
<div class="tl_box">
<h2>Credits</h2>
<table class="tl_listing">
<tr>
<th>Name</th>
<th>Version</th>
<th>License</th>
<th>Homepage</th>
</tr>
<?php if ($this->libraries): ?>
<tr>
<th colspan="4" class="subtitle">Libraries</th>
</tr>
<?php endif; ?>
<?php foreach ($this->libraries as $library): ?>
<tr>
<td><?php echo $library['name']; ?></td>
<td><?php echo $library['version']; ?></td>
<td><?php echo $library['license']; ?></td>
<td><?php echo $library['homepage']; ?></td>
</tr>
<?php endforeach; ?>
<tr>
<th class="subtitle" colspan="4">Graphics</th>
</tr>
<tr>
<td>Farm Fresh-Web Icons</td>
<td>3.9.2</td>
<td><a href="http://creativecommons.org/licenses/by/3.0/us/" target="_blank">CC BY 3.0 US</a></td>
<td><a href="http://www.fatcow.com/free-icons" target="_blank">fatcow.com/free-icons</a></td>
</tr>
<tr>
<td>Web Blog Icons by SEM Labs</td>
<td>3.9.2</td>
<td><a href="http://creativecommons.org/licenses/by/4.0/" target="_blank">CC BY 4.0</a></td>
<td><a href="http://semlabs.co.uk/" target="_blank">semlabs.co.uk</a></td>
</tr>
<?php if ($this->dependencies): ?>
<tr>
<th colspan="4" class="subtitle">Dependencies</th>
</tr>
<?php endif; ?>
<?php foreach ($this->dependencies as $dep): ?>
<tr>
<td><?php echo $dep['name']; ?></td>
<td><?php echo $dep['version']; ?></td>
<td><?php echo $dep['license']; ?></td>
<td><?php echo $dep['homepage']; ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>

View File

@@ -1,8 +1,8 @@
<?php $GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet/leaflet.css'; ?>
<?php $GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.css'; ?>
<?php $GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet/leaflet.min.css'; ?>
<?php $GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.min.css'; ?>
<?php $GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/leaflet/leaflet.js'; ?>
<?php $GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.js'; ?>
<?php $GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/libs/control-geocoder/Control.Geocoder.min.js'; ?>
<div id="map_<?php echo $this->field; ?>" style="margin-top: 5px; width: calc(100% - 28px); height: 300px"></div>
<script>
@@ -17,6 +17,12 @@
placeholder: '<?php echo $GLOBALS['TL_LANG']['leaflet']['searchPosition']; ?>'
}).addTo(map);
document.querySelector('.leaflet-control-geocoder input').addEventListener('keydown', function (event) {
if (event.keyCode === 13) {
event.preventDefault();
}
});
geocoder.on('markgeocode', function (event) {
var container = document.createElement('div');
var link = document.createElement('button');
@@ -28,7 +34,8 @@
e.stop();
element.set('value', result.center.lat + ',' + result.center.lng);
});
this._geocodeMarker.closePopup();
}.bind(this));
container.appendHTML(result.html || result.name);
container.appendChild(link);

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,132 @@
{% extends "@ContaoCore/Backend/be_page.html.twig" %}
{% block headline %}{{ "MOD.leaflet_about.1"|trans({}, 'contao_modules') }}{% endblock %}
{% block error %}{% endblock %}
{% block main %}
<div class="netzmacht-leaflet-credits">
<div class="header">
<h1 class="sub_headline">{{ headline }}
<small>{{ version }}</small>
</h1>
</div>
<div class="tl_box block row">
<h2>About</h2>
<p>
The Leaflet maps integration for Contao CMS is an Open Source Software license under the LGPL 3.0.
This extension is only exists because of great other Open Source Software which it heavenly depends on.
</p>
<p>
This software ships with an visible attribution to <em>netzmacht creative</em> in the map attribution
control.
If you want to remove this attribution, you have to purchase a commercial license.
For more details visit the <a href="https://netzmacht.de/contao-leaflet" target="_blank">project
website</a>.
</p>
</div>
<div class="tl_box">
<h2>Support Contao Leaflet</h2>
<div class="row">
<div class="col">
<h3>Report issues</h3>
<p>If you found a bug, got some troubles or have a feature request - feel free to open an issue.</p>
<p><a href="https://github.com/netzmacht/contao-leaflet-maps/issues" class="btn" target="_blank">Issue
tracker</a></p>
</div>
<div class="col">
<h3>Contribute</h3>
<p>There are many ways you can con&shy;tribute. Translations,
docu&shy;mentation or code contributions are welcome.
</p>
<p><a href="https://netzmacht.de/contao-leaflet/contribute.html" class="btn" target="_blank">Contribute</a>
</p>
</div>
<div class="col">
<h3>Fund a feature</h3>
<p>Contao Leaflet is not feature complete. Have a look at the list of planned feature and support
them.</p>
<p><a href="https://github.com/netzmacht/contao-leaflet-maps/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement" class="btn" target="_blank">Planned
features</a></p>
</div>
</div>
<div class="row">
<div class="col">
<h3>Individual development</h3>
<p>If you have special requirements you can hire me for an individual development.</p>
<p><a href="https://netzmacht.de/contao-leaflet/contact.html" class="btn" target="_blank">Contact</a></p>
</div>
<div class="col">
<h3>Commercial license</h3>
<p>If you want to remove the attribution in the attribution control, you can purchase a commercial
license.</p>
<p><a href="https://netzmacht.de/contao-leaflet/commercial-license.html" class="btn" target="_blank">Purchase
license</a></p>
</div>
</div>
</div>
<div class="tl_box">
<h2>Credits</h2>
<table class="tl_listing">
<tr>
<th>Name</th>
<th>Version</th>
<th>License</th>
<th>Homepage</th>
</tr>
{% if libraries %}
<tr>
<th colspan="4" class="subtitle">Libraries</th>
</tr>
{% endif %}
{% for library in libraries %}
<tr>
<td>{{ library.name }}</td>
<td>{{ library.version }}</td>
<td>{{ library.license|raw }}</td>
<td>{{ library.homepage|raw }}</td>
</tr>
{% endfor %}
<tr>
<td>url-polyfill</td>
<td>v1.1.0</td>
<td><a href="https://github.com/lifaon74/url-polyfill/blob/master/LICENSE" target="_blank">MIT</a></td>
<td><a href="https://github.com/lifaon74/url-polyfill" target="_blank">github.com/lifaon74/url-polyfill</a></td>
</tr>
<tr>
<th class="subtitle" colspan="4">Graphics</th>
</tr>
<tr>
<td>Farm Fresh-Web Icons</td>
<td>3.9.2</td>
<td><a href="http://creativecommons.org/licenses/by/3.0/us/" target="_blank">CC BY 3.0 US</a></td>
<td><a href="http://www.fatcow.com/free-icons" target="_blank">fatcow.com/free-icons</a></td>
</tr>
<tr>
<td>Web Blog Icons by SEM Labs</td>
<td>3.9.2</td>
<td><a href="http://creativecommons.org/licenses/by/4.0/" target="_blank">CC BY 4.0</a></td>
<td><a href="http://semlabs.co.uk/" target="_blank">semlabs.co.uk</a></td>
</tr>
{% if dependencies %}
<tr>
<th colspan="4" class="subtitle">Dependencies</th>
</tr>
{% endif %}
{% for dep in dependencies %}
<tr>
<td>{{ dep.name }}</td>
<td>{{ dep.version }}</td>
<td>{{ dep.license|raw }}</td>
<td>{{ dep.homepage|raw }}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}

View File

@@ -90,7 +90,7 @@ class EncoderSubscriber implements EventSubscriberInterface
$value = $event->getValue();
$encoder = $event->getEncoder();
$template = 'L.contao.%s(%s, %s, %s, %s, map);';
$method = 'loadFile';
$method = 'loadUrl';
if ($value instanceof OmnivoreLayer) {
$url = $value->getUrl();

View File

@@ -36,7 +36,7 @@ class BuildDefinitionEvent extends Event
/**
* The model.
*
* @var \Model
* @var Model
*/
private $model;
@@ -74,7 +74,7 @@ class BuildDefinitionEvent extends Event
/**
* Get the model.
*
* @return \Model
* @return Model
*/
public function getModel()
{

View File

@@ -93,4 +93,24 @@ class DistanceFilter implements Filter
'center' => $this->center,
];
}
/**
* Get the center coordinate.
*
* @return LatLng
*/
public function getCenter(): LatLng
{
return $this->center;
}
/**
* Get the distance radius.
*
* @return int
*/
public function getRadius(): int
{
return $this->radius;
}
}

View File

@@ -51,7 +51,7 @@ final class FilterFactory
public function create(string $filter, string $values): Filter
{
if (isset($this->filters[$filter])) {
return call_user_func([$filter, 'fromRequest'], $values);
return call_user_func([$this->filters[$filter], 'fromRequest'], $values);
}
throw new \RuntimeException(sprintf('Creating filter failed. Unsupported filter "%s"', $filter));

View File

@@ -18,6 +18,7 @@ use Contao\Database\Result;
use Contao\Input;
use Contao\Model;
use Contao\Model\Collection;
use Contao\StringUtil;
use Netzmacht\Contao\Leaflet\MapProvider;
use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\Contao\Toolkit\Component\Hybrid\AbstractHybrid;
@@ -118,6 +119,8 @@ abstract class AbstractMapHybrid extends AbstractHybrid
*/
protected function prepareTemplateData(array $data): array
{
$data = parent::prepareTemplateData($data);
try {
$template = $this->get('leaflet_template') ?: 'leaflet_map_js';
$mapId = $this->getIdentifier();
@@ -127,8 +130,8 @@ abstract class AbstractMapHybrid extends AbstractHybrid
$data['mapId'] = $mapId;
$style = '';
$height = deserialize($this->get('leaflet_height'), true);
$width = deserialize($this->get('leaflet_width'), true);
$height = StringUtil::deserialize($this->get('leaflet_height'), true);
$width = StringUtil::deserialize($this->get('leaflet_width'), true);
if (!empty($width['value'])) {
$style .= 'width:' . $width['value'] . $width['unit'] . ';';

View File

@@ -0,0 +1,103 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2018 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Frontend\Action;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Filter\FilterFactory;
use Netzmacht\Contao\Leaflet\MapProvider;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
/**
* Request action which handles request for layer data
*/
final class LayerDataAction
{
/**
* Map provider.
*
* @var MapProvider
*/
private $mapProvider;
/**
* Filter factory.
*
* @var FilterFactory
*/
private $filterFactory;
/**
* LayerDataAction constructor.
*
* @param MapProvider $mapProvider Map provider.
* @param FilterFactory $filterFactory Filter factory.
*/
public function __construct(MapProvider $mapProvider, FilterFactory $filterFactory)
{
$this->mapProvider = $mapProvider;
$this->filterFactory = $filterFactory;
}
/**
* Handle the request.
*
* @param int $layerId The layer id.
* @param string $_format The requested output format.
* @param Request $request The request.
*
* @return Response
*
* @throws BadRequestHttpException When unsupported format is given.
*
* @SuppressWarnings(PHPMD.CamelCaseParameterName)
* @SuppressWarnings(PHPMD.CamelCaseVariableName)
*/
public function __invoke(int $layerId, string $_format, Request $request): Response
{
$filter = $this->createFilter($request);
$data = $this->mapProvider->getFeatureCollection($layerId, $filter);
if ($_format === 'geojson') {
$response = new JsonResponse($data);
$response->setEncodingOptions(JSON_UNESCAPED_SLASHES);
return $response;
}
throw new BadRequestHttpException(sprintf('Unsupported format "%s"', $_format));
}
/**
* Create the filter if defined in the request.
*
* @param Request $request The request.
*
* @return Filter|null
*/
private function createFilter(Request $request): ?Filter
{
if (!$request->query->has('filter')) {
return null;
}
$filter = (string) $request->query->get('filter');
$values = (string) $request->query->get('values');
return $this->filterFactory->create($filter, $values);
}
}

View File

@@ -12,14 +12,18 @@
namespace Netzmacht\Contao\Leaflet\Frontend;
use const E_USER_DEPRECATED;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Filter\FilterFactory;
use Netzmacht\Contao\Leaflet\MapProvider;
use function trigger_error;
/**
* The data controller handles ajax request for sub data.
*
* @package Netzmacht\Contao\Leaflet\Frontend
*
* @deprecated
*/
class DataController
{
@@ -60,6 +64,13 @@ class DataController
{
$this->debugMode = $debugMode;
$this->filterFactory = $filterFactory;
// @codingStandardsIgnoreStart
@trigger_error(
'Deprecated since 3.1.0 and will be removed in 4.0.0 - Use properly route instead.',
E_USER_DEPRECATED
);
// @codingStandardsIgnoreEnd
}
/**

View File

@@ -0,0 +1,47 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2018 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Frontend;
use Netzmacht\Contao\PageContext\Exception\DeterminePageIdFailed;
use Netzmacht\Contao\PageContext\Request\PageIdDeterminator as PageContextPageIdDeterminator;
use Symfony\Component\HttpFoundation\Request;
/**
* Class ApiPageIdDeterminator
*/
final class PageIdDeterminator implements PageContextPageIdDeterminator
{
/**
* {@inheritDoc}
*/
public function match(Request $request): bool
{
return ($request->attributes->get('_leaflet_scope') === 'page' && $request->query->get('context') === 'page');
}
/**
* {@inheritDoc}
*
* @throws DeterminePageIdFailed When no context id is given.
*/
public function determinate(Request $request): int
{
if (!$request->query->has('contextId')) {
throw new DeterminePageIdFailed('Could not determine page id for from request.');
}
return $request->query->getInt('contextId');
}
}

View File

@@ -12,6 +12,8 @@
namespace Netzmacht\Contao\Leaflet\Frontend;
use Contao\Config;
use Contao\Frontend;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Mapper\Request;
@@ -19,6 +21,8 @@ use Netzmacht\Contao\Leaflet\Mapper\Request;
* Class RequestUrl creates the request url.
*
* @package Netzmacht\Contao\Leaflet\Request
*
* @deprecated
*/
class RequestUrl implements \JsonSerializable
{
@@ -72,7 +76,7 @@ class RequestUrl implements \JsonSerializable
$query .= '&amp;f=' . $filter->getName() . '&amp;v=' . $filter->toRequest();
}
$url = \Config::get('websitePath') . '/' . \Frontend::addToUrl($query, false);
$url = Config::get('websitePath') . '/' . Frontend::addToUrl($query, false);
return new static($url, $hash, $request);
}
@@ -87,6 +91,13 @@ class RequestUrl implements \JsonSerializable
{
$this->url = $url;
$this->hash = $hash;
// @codingStandardsIgnoreStart
@trigger_error(
'Deprecated since 3.1.0 and will be removed in 4.0.0. Use The router instead.',
E_USER_DEPRECATED
);
// @codingStandardsIgnoreEnd
}
/**

View File

@@ -73,6 +73,8 @@ class ValueFilter
*/
public function filter($value)
{
return $this->getReplacer()->replace($value);
$value = $this->getReplacer()->replace($value, false);
return $value;
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014-2018 netzmacht David Molineus. All rights reserved.
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
* @filesource
*/
declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Listener\Backend;
use Contao\CoreBundle\Event\MenuEvent;
use Netzmacht\Contao\Toolkit\View\Assets\AssetsManager;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface as Router;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/**
* Class BackendMenuListener adds backend entries to the navigation.
*/
final class UserNavigationListener
{
/**
* Request stack.
*
* @var RequestStack
*/
private $requestStack;
/**
* Router.
*
* @var Router
*/
private $router;
/**
* Translator.
*
* @var Translator
*/
private $translator;
/**
* Assets manager.
*
* @var AssetsManager
*/
private $assets;
/**
* BackendUserNavigationListener constructor.
*
* @param RequestStack $requestStack Request stack.
* @param Router $router Router.
* @param Translator $translator Translator.
* @param AssetsManager $assets Assets manager.
*/
public function __construct(
RequestStack $requestStack,
Router $router,
Translator $translator,
AssetsManager $assets
) {
$this->requestStack = $requestStack;
$this->router = $router;
$this->translator = $translator;
$this->assets = $assets;
}
/**
* Handle the event.
*
* @param array $modules Backend navigation modules.
*
* @return array
*/
public function __invoke(array $modules): array
{
if (!isset($modules['leaflet'])) {
return $modules;
}
$request = $this->requestStack->getCurrentRequest();
$isActive = $request && $request->attributes->get('_backend_module') === 'leaflet_about';
$modules['leaflet']['modules']['leaflet_about'] = [
'label' => $this->translator->trans('MOD.leaflet_about.0', [], 'contao_modules'),
'title' => $this->translator->trans('MOD.leaflet_about.1', [], 'contao_modules'),
'href' => $this->router->generate('leaflet_backend_about'),
'icon' => 'bundles/netzmachtcontaoleaflet/img/about.png',
'class' => 'navigation leaflet_about',
'isActive' => $isActive,
];
if ($isActive) {
$this->assets->addStylesheet('bundles/netzmachtcontaoleaflet/css/about.css');
}
return $modules;
}
}

View File

@@ -517,9 +517,9 @@ class LayerDcaListener extends AbstractListener
{
return sprintf(
'<a href="%s" title="%s">%s</a> ',
\Backend::addToUrl($href . '&amp;id=' . $row['id']),
Backend::addToUrl($href . '&amp;id=' . $row['id']),
$title,
\Image::getHtml($icon, $label, $attributes)
Image::getHtml($icon, $label, $attributes)
);
}
}

View File

@@ -122,6 +122,7 @@ class LeafletDcaListener
$data['marker'] = json_encode($latLng);
} catch (\Exception $e) {
// LatLng throws an exception of value could not be created. Just let the value empty when.
$data['marker'] = null;
}
return $this->templateEngine->render('toolkit:be:be_leaflet_geocode.html5', $data);

View File

@@ -15,14 +15,20 @@ declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Listener\Dca;
use Contao\DataContainer;
use Contao\Input;
use Contao\StringUtil;
use Doctrine\DBAL\Connection;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
use Netzmacht\Contao\Toolkit\Dca\Listener\AbstractListener;
use Netzmacht\Contao\Toolkit\Dca\Manager;
use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder;
use PDO;
use function strlen;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Translation\TranslatorInterface as Translator;
use function var_dump;
/**
* Class Map is the helper class for the tl_leaflet_map dca.
@@ -52,19 +58,70 @@ class MapDcaListener extends AbstractListener
*/
private $repositoryManager;
/**
* Translator.
*
* @var Translator
*/
private $translator;
/**
* Session.
*
* @var Session
*/
private $session;
/**
* Construct.
*
* @param Manager $manager Data container manager.
* @param Connection $connection Database connection.
* @param RepositoryManager $repositoryManager Repository manager.
* @param Translator $translator Translator.
* @param Session $session Session.
*/
public function __construct(Manager $manager, Connection $connection, RepositoryManager $repositoryManager)
{
public function __construct(
Manager $manager,
Connection $connection,
RepositoryManager $repositoryManager,
Translator $translator,
Session $session
) {
parent::__construct($manager);
$this->connection = $connection;
$this->repositoryManager = $repositoryManager;
$this->translator = $translator;
$this->session = $session;
}
/**
* Add warnings for incomplete configurations.
*
* @param DataContainer $dataContainer The data container driver.
*
* @return void
*/
public function addIncompleteConfigurationWarning($dataContainer): void
{
if (Input::get('act') !== 'edit') {
return;
}
$repository = $this->repositoryManager->getRepository(MapModel::class);
$map = $repository->find((int) $dataContainer->id);
if (!$map) {
return;
}
if ($map->zoom === null || $map->zoom === '') {
$this->session->getFlashBag()->add(
'contao.BE.info',
$this->translator->trans('ERR.leafletMissingZoomLevel', [], 'contao_default')
);
}
}
/**

View File

@@ -13,6 +13,7 @@
namespace Netzmacht\Contao\Leaflet\Listener\Dca;
use Contao\Controller;
use Contao\StringUtil;
use Doctrine\DBAL\Connection;
use Netzmacht\Contao\Leaflet\Model\IconModel;
use Netzmacht\Contao\Leaflet\Model\PopupModel;
@@ -113,7 +114,7 @@ class MarkerDcaListener
'altitude' => null,
];
$values = trimsplit(',', $value);
$values = StringUtil::trimsplit(',', $value);
$keys = array_keys($combined);
$count = count($values);

View File

@@ -13,6 +13,7 @@
namespace Netzmacht\Contao\Leaflet\Listener\Dca;
use Contao\DataContainer;
use Contao\StringUtil;
use Netzmacht\Contao\Toolkit\Dca\Manager;
use Netzmacht\LeafletPHP\Value\LatLng;
use Symfony\Component\Translation\TranslatorInterface as Translator;
@@ -116,7 +117,7 @@ class Validator
*/
public function validateMultipleCoordinateSets($values, $dataContainer)
{
$sets = deserialize($values, true);
$sets = StringUtil::deserialize($values, true);
foreach ($sets as $lines) {
$this->validateMultipleCoordinates($lines, $dataContainer);
}

View File

@@ -16,6 +16,7 @@ namespace Netzmacht\Contao\Leaflet\Listener;
use Contao\FilesModel;
use Contao\Model;
use Contao\StringUtil;
use Netzmacht\Contao\Leaflet\Event\ConvertToGeoJsonEvent;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
@@ -117,7 +118,7 @@ final class GeoJsonListener
public function enrichObjects(GeoJsonObject $feature, LeafletDefinition $definition, $model)
{
if (($definition instanceof Marker || $definition instanceof Vector)
&& $model instanceof \Model && $feature instanceof Feature) {
&& $model instanceof Model && $feature instanceof Feature) {
$this->setDataProperty($model, $feature);
$this->setBoundsInformation($model, $feature);
}
@@ -148,7 +149,7 @@ final class GeoJsonListener
*/
public function setModelData(GeoJsonObject $feature, $model)
{
if (!$model instanceof \Model || !$feature instanceof Feature
if (!$model instanceof Model || !$feature instanceof Feature
|| empty($this->featureModelProperties[$model->getTable()])) {
return;
}
@@ -169,12 +170,12 @@ final class GeoJsonListener
/**
* Parse the model value based on the config.
*
* @param \Model $model The model.
* @param mixed $property The property config.
* @param Model $model The model.
* @param mixed $property The property config.
*
* @return array|mixed|null
*/
private function parseModelValue(\Model $model, &$property)
private function parseModelValue(Model $model, &$property)
{
if (is_array($property)) {
list($property, $type) = $property;
@@ -183,7 +184,7 @@ final class GeoJsonListener
switch ($type) {
case 'array':
case 'object':
$value = deserialize($value, true);
$value = StringUtil::deserialize($value, true);
break;
case 'file':
@@ -194,7 +195,7 @@ final class GeoJsonListener
case 'files':
$repository = $this->repositoryManager->getRepository(FilesModel::class);
$collection = $repository->findMultipleByUuids(deserialize($value, true));
$collection = $repository->findMultipleByUuids(StringUtil::deserialize($value, true));
if ($collection) {
$value = $collection->fetchEach('path');

View File

@@ -12,6 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Listener;
use Contao\Model;
use Netzmacht\Contao\Leaflet\Event\GetHashEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -46,7 +47,7 @@ class HashSubscriber implements EventSubscriberInterface
{
$data = $event->getData();
if ($data instanceof \Model) {
if ($data instanceof Model) {
$event->setHash($data->getTable() . '::' . $data->{$data->getPk()});
}
}

View File

@@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Netzmacht\Contao\Leaflet\Listener;
use Contao\File;
use Netzmacht\Contao\Leaflet\Encoder\ContaoAssets;
use Netzmacht\Contao\Leaflet\Frontend\Assets\LibrariesConfiguration;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
@@ -117,7 +118,7 @@ class LoadAssetsListener
// TODO: Cache it.
// codingStandardsIgnoreEnd
$file = new \File('assets/leaflet/js/icons.js');
$file = new File('assets/leaflet/js/icons.js');
$file->write($buffer);
$file->close();

View File

@@ -206,7 +206,10 @@ class MapProvider
$model = $this->getModel($mapId);
}
if ($model->cache) {
$cacheKey = null;
$doCache = $model->cache;
if ($doCache) {
$cacheKey = $this->getCacheKey($mapId, $filter, $elementId, $template, $style);
if ($this->cache->contains($cacheKey)) {
@@ -219,7 +222,7 @@ class MapProvider
$buffer = $this->doGenerate($model, $filter, $elementId, $template, $style);
if ($model->cache) {
if ($doCache) {
$this->cache->save(
$cacheKey,
[

View File

@@ -13,6 +13,7 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Contao\Model;
use Contao\StringUtil;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\Request;
use Netzmacht\LeafletPHP\Definition;
@@ -68,7 +69,7 @@ class AttributionControlMapper extends AbstractControlMapper
$parent->setAttributionControl(false);
}
$attributions = deserialize($model->attributions, true);
$attributions = StringUtil::deserialize($model->attributions, true);
foreach ($attributions as $attribution) {
$definition->addAttribution($attribution);

View File

@@ -13,7 +13,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Contao\Model;
use Netzmacht\Contao\Leaflet\Frontend\RequestUrl;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper;
use Netzmacht\Contao\Leaflet\Mapper\Request;
@@ -24,6 +23,7 @@ use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
use Netzmacht\LeafletPHP\Plugins\Omnivore\GeoJson as OmnivoreGeoJson;
use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection;
use Symfony\Component\Routing\RouterInterface;
/**
* Class MarkersLayerMapper maps the layer model to the markers definition.
@@ -46,14 +46,23 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
*/
private $repositoryManager;
/**
* Router.
*
* @var RouterInterface
*/
private $router;
/**
* Construct.
*
* @param RepositoryManager $repositoryManager Repository manager.
* @param RouterInterface $router Router.
*/
public function __construct(RepositoryManager $repositoryManager)
public function __construct(RepositoryManager $repositoryManager, RouterInterface $router)
{
$this->repositoryManager = $repositoryManager;
$this->router = $router;
parent::__construct();
}
@@ -93,7 +102,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
return [
$this->getElementId($model, $elementId),
RequestUrl::create($model->id, null, null, $request),
$this->generateUrl((int) $model->id, $request),
[],
$layer,
];
@@ -101,7 +110,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
return [
$this->getElementId($model, $elementId),
RequestUrl::create($model->id, null, null, $request),
$this->generateUrl((int) $model->id, $request),
];
}
@@ -170,16 +179,43 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
* @param Model $model The layer model.
* @param Request $request Optional building request.
*
* @return \Model\Collection|null
* @return \Contao\Model\Collection|null
*/
protected function loadMarkerModels(Model $model, Request $request = null)
{
$repository = $this->repositoryManager->getRepository(MarkerModel::class);
if ($model->boundsMode == 'fit') {
if ($model->boundsMode === 'fit') {
return $repository->findByFilter($model->id, $request->getFilter());
}
return $repository->findByFilter($model->id);
}
/**
* Generate the data url for a layer.
*
* @param int $layerId The layer id.
* @param Request|null $request The request.
*
* @return string
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
private function generateUrl(int $layerId, ?Request $request = null): string
{
$params = ['layerId' => $layerId];
if ($request && ($filter = $request->getFilter())) {
$params['filter'] = $filter::getName();
$params['values'] = $filter->toRequest();
}
if (isset($GLOBALS['objPage'])) {
$params['context'] = 'page';
$params['contextId'] = $GLOBALS['objPage']->id;
}
return $this->router->generate('leaflet_layer', $params, RouterInterface::ABSOLUTE_URL);
}
}

View File

@@ -13,6 +13,7 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Contao\Model;
use Contao\StringUtil;
use Netzmacht\Contao\Leaflet\Definition\Layer\OverpassLayer;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\Request;
@@ -146,7 +147,7 @@ class OverpassLayerMapper extends AbstractLayerMapper
*/
private function filterAmenityIconsConfig($amenityIconsConfig)
{
$amenityIconsConfig = deserialize($amenityIconsConfig, true);
$amenityIconsConfig = StringUtil::deserialize($amenityIconsConfig, true);
$amenityIconsMap = [];
foreach ($amenityIconsConfig as $config) {

View File

@@ -14,7 +14,6 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Contao\Model;
use Contao\Model\Collection;
use Netzmacht\Contao\Leaflet\Frontend\RequestUrl;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper;
use Netzmacht\Contao\Leaflet\Mapper\Request;
@@ -25,6 +24,7 @@ use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
use Netzmacht\LeafletPHP\Plugins\Omnivore\GeoJson as OmnivoreGeoJson;
use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection;
use Symfony\Component\Routing\RouterInterface;
/**
* Class VectorsLayerMapper maps the layer model for the Vectors layer definition.
@@ -47,14 +47,23 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
*/
private $repositoryManager;
/**
* Router.
*
* @var RouterInterface
*/
private $router;
/**
* Construct.
*
* @param RepositoryManager $repositoryManager Repository manager.
* @param RouterInterface $router Router
*/
public function __construct(RepositoryManager $repositoryManager)
public function __construct(RepositoryManager $repositoryManager, RouterInterface $router)
{
$this->repositoryManager = $repositoryManager;
$this->router = $router;
parent::__construct();
}
@@ -101,7 +110,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
return [
$this->getElementId($model, $elementId),
RequestUrl::create($model->id, null, null, $request),
$this->generateUrl((int) $model->id, $request),
[],
$layer,
];
@@ -109,7 +118,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
return [
$this->getElementId($model, $elementId),
RequestUrl::create($model->id, null, null, $request),
$this->generateUrl((int) $model->id, $request),
];
}
@@ -188,11 +197,11 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
* Add javascript callbacks.
*
* @param GeoJson $definition The definition.
* @param \Model $model The database model.
* @param Model $model The database model.
*
* @return void
*/
protected function addCallbacks(GeoJson $definition, \Model $model)
protected function addCallbacks(GeoJson $definition, Model $model)
{
if ($model->pointToLayer) {
$definition->setPointToLayer(new Expression($model->pointToLayer));
@@ -202,4 +211,31 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
$definition->setOnEachFeature(new Expression($model->onEachFeature));
}
}
/**
* Generate the data url for a layer.
*
* @param int $layerId The layer id.
* @param Request|null $request The request.
*
* @return string
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
private function generateUrl(int $layerId, ?Request $request = null): string
{
$params = ['layerId' => $layerId];
if ($request && ($filter = $request->getFilter())) {
$params['filter'] = $filter::getName();
$params['values'] = $filter->toRequest();
}
if (isset($GLOBALS['objPage'])) {
$params['context'] = 'page';
$params['contextId'] = $GLOBALS['objPage']->id;
}
return $this->router->generate('leaflet_layer', $params, RouterInterface::ABSOLUTE_URL);
}
}

View File

@@ -13,6 +13,7 @@
namespace Netzmacht\Contao\Leaflet\Mapper;
use Contao\Model;
use Contao\StringUtil;
use Netzmacht\Contao\Leaflet\Model\ControlModel;
use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
@@ -195,7 +196,7 @@ class MapMapper extends AbstractMapper
*/
private function buildBoundsCalculation(Map $map, MapModel $model)
{
$adjustBounds = deserialize($model->adjustBounds, true);
$adjustBounds = StringUtil::deserialize($model->adjustBounds, true);
if (in_array('deferred', $adjustBounds)) {
$map->setOption('adjustBounds', true);

View File

@@ -131,7 +131,7 @@ class OptionsBuilder
* Build options and conditional options.
*
* @param Definition $definition The definition being built.
* @param \Model $model The model.
* @param Model $model The model.
*
* @return $this
*/
@@ -147,7 +147,7 @@ class OptionsBuilder
* Build options.
*
* @param Definition $definition The definition being built.
* @param \Model $model The model.
* @param Model $model The model.
*
* @return void
*/
@@ -160,11 +160,11 @@ class OptionsBuilder
* Build conditional options.
*
* @param Definition $definition The definition being built.
* @param \Model $model The model.
* @param Model $model The model.
*
* @return void
*/
private function buildConditionals($definition, \Model $model)
private function buildConditionals($definition, Model $model)
{
foreach ($this->conditional as $column => $conditions) {
foreach ($conditions as $value => $options) {

View File

@@ -12,6 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Type;
use Contao\File;
use Contao\FilesModel;
use Contao\Model;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
@@ -118,7 +119,7 @@ class ImageIconMapper extends AbstractIconMapper
if ($file) {
$definition->setIconUrl($file->path);
$file = new \File($file->path);
$file = new File($file->path);
$definition->setIconSize([$file->width, $file->height]);
if (!$model->iconAnchor) {
@@ -162,7 +163,7 @@ class ImageIconMapper extends AbstractIconMapper
if ($file) {
$definition->setShadowUrl($file->path);
$file = new \File($file->path);
$file = new File($file->path);
$definition->setShadowSize([$file->width, $file->height]);
if (!$model->shadowAnchor) {

View File

@@ -13,6 +13,7 @@
namespace Netzmacht\Contao\Leaflet\Mapper\UI;
use Contao\Model;
use Contao\StringUtil;
use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\Request;
@@ -76,9 +77,9 @@ class PopupMapper extends AbstractMapper
if ($model->autoPan) {
$padding = array_map(
function ($value) {
return array_map('intval', trimsplit(',', $value));
return array_map('intval', StringUtil::trimsplit(',', $value));
},
deserialize($model->autoPanPadding, true)
StringUtil::deserialize($model->autoPanPadding, true)
);
if ($padding[0] === $padding[1]) {

View File

@@ -13,6 +13,7 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Contao\Model;
use Contao\StringUtil;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\Request;
use Netzmacht\LeafletPHP\Definition;
@@ -67,7 +68,7 @@ class MultiPolylineMapper extends AbstractVectorMapper
*/
protected function createLatLngs(Polyline $definition, Model $model)
{
foreach (deserialize($model->multiData, true) as $ring => $data) {
foreach (StringUtil::deserialize($model->multiData, true) as $ring => $data) {
$latLngs = array_map(
function ($row) {
return LatLng::fromString($row);

View File

@@ -13,6 +13,7 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Contao\Model;
use Contao\StringUtil;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\Request;
use Netzmacht\LeafletPHP\Definition\Vector\Rectangle;
@@ -53,7 +54,7 @@ class RectangleMapper extends AbstractVectorMapper
function ($latLng) {
return LatLng::fromString($latLng);
},
deserialize($model->bounds, true)
StringUtil::deserialize($model->bounds, true)
);
$arguments = parent::buildConstructArguments($model, $mapper, $request, $elementId);

View File

@@ -12,6 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Model;
use Contao\Model;
use Contao\Model\Collection;
/**
@@ -19,7 +20,7 @@ use Contao\Model\Collection;
*
* @package Netzmacht\Contao\Leaflet\Model
*/
abstract class AbstractActiveModel extends \Model
abstract class AbstractActiveModel extends Model
{
/**
* Find an active model by its model id.

View File

@@ -12,7 +12,8 @@
namespace Netzmacht\Contao\Leaflet\Model;
use Model\Collection;
use Contao\Database;
use Contao\Model\Collection;
/**
* Class ControlModel for the tl_leaflet_vector table.
@@ -42,7 +43,7 @@ LEFT JOIN tl_leaflet_control_layer c ON l.id = c.lid
WHERE c.cid=?
SQL;
$result = \Database::getInstance()
$result = Database::getInstance()
->prepare($query)
->execute($this->id);
@@ -68,7 +69,7 @@ c ON l.id = c.lid
WHERE c.cid=? AND l.active=1
SQL;
$result = \Database::getInstance()
$result = Database::getInstance()
->prepare($query)
->execute($this->id);

View File

@@ -12,7 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Model;
use Model\Collection;
use Contao\Model\Collection;
/**
* Class LayerModel for the tl_leaflet_layer table.

View File

@@ -12,7 +12,9 @@
namespace Netzmacht\Contao\Leaflet\Model;
use Model\Collection;
use Contao\Database;
use Contao\Model;
use Contao\Model\Collection;
/**
* Class MapModel for the tl_leaflet_map table.
@@ -22,7 +24,7 @@ use Model\Collection;
*
* @package Netzmacht\Contao\Leaflet\Model
*/
class MapModel extends \Model
class MapModel extends Model
{
/**
* Model table.
@@ -39,7 +41,7 @@ class MapModel extends \Model
public function findLayers()
{
$query = 'SELECT l.* FROM tl_leaflet_layer l LEFT JOIN tl_leaflet_map_layer m ON l.id = m.lid WHERE m.mid=?';
$result = \Database::getInstance()
$result = Database::getInstance()
->prepare($query)
->execute($this->id);
@@ -65,7 +67,7 @@ ON l.id = m.lid
WHERE m.mid=? AND l.active=1
SQL;
$result = \Database::getInstance()->prepare($query)->execute($this->id);
$result = Database::getInstance()->prepare($query)->execute($this->id);
if ($result->numRows) {
return Collection::createFromDbResult($result, 'tl_leaflet_layer');

View File

@@ -12,9 +12,12 @@
namespace Netzmacht\Contao\Leaflet\Model;
use Contao\Model\Collection;
use Netzmacht\Contao\Leaflet\Filter\BboxFilter;
use Netzmacht\Contao\Leaflet\Filter\DistanceFilter;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\LeafletPHP\Value\LatLngBounds;
use function var_dump;
/**
* Class MarkerModel for the tl_leaflet_marker table.
@@ -33,21 +36,35 @@ class MarkerModel extends AbstractActiveModel
/**
* Find by a filter.
*
* @param int $pid The parent id.
* @param Filter $filter The filter.
* @param int $pid The parent id.
* @param Filter|null $filter The filter.
*
* @return \Model\Collection|null
* @return Collection|null
*/
public static function findByFilter($pid, Filter $filter = null)
public static function findByFilter($pid, ?Filter $filter = null)
{
if (!$filter) {
return static::findActiveBy('pid', $pid, ['order' => 'sorting']);
$table = static::getTable();
return static::findBy(
[
$table . '.active=1',
$table . '.pid=?',
$table . '.latitude>0',
$table . '.longitude>0',
],
[$pid],
['order' => 'sorting']
);
}
switch ($filter->getName()) {
case 'bbox':
switch (true) {
case $filter instanceof BboxFilter:
return static::findByBBoxFilter($pid, $filter);
case $filter instanceof DistanceFilter:
return static::findByDistanceFilter($pid, $filter);
default:
return null;
}
@@ -59,15 +76,16 @@ class MarkerModel extends AbstractActiveModel
* @param int $pid The layer id.
* @param BboxFilter $filter The bbox filter.
*
* @return \Model\Collection|null
* @return Collection|null|MarkerModel[]
*/
public static function findByBBoxFilter($pid, BboxFilter $filter)
{
$table = static::getTable();
$columns = [
'active=1',
'pid=?',
'latitude > ? AND latitude < ?',
'longitude > ? AND longitude < ?',
$table . '.active=1',
$table . '.pid=?',
$table . '.latitude > ? AND ' . $table . '.latitude < ?',
$table . '.longitude > ? AND ' . $table . '.longitude < ?',
];
/** @var LatLngBounds $bounds */
@@ -80,6 +98,39 @@ class MarkerModel extends AbstractActiveModel
$bounds->getNorthEast()->getLongitude(),
];
return static::findBy($columns, $values, ['order' => 'sorting']);
return static::findBy($columns, $values, ['order' => $table . '.sorting']);
}
/**
* Find marker by distance filter.
*
* @param int $pid The layer id.
* @param DistanceFilter $filter THe distance filter.
*
* @return Collection|null|MarkerModel[]
*/
public static function findByDistanceFilter($pid, DistanceFilter $filter): ?Collection
{
$table = static::getTable();
$query = <<<SQL
round(
sqrt(
power( 2 * pi() / 360 * (? - {$table}.latitude) * 6371,2)
+ power( 2 * pi() / 360 * (? - {$table}.longitude) * 6371 * COS( 2 * pi() / 360 * (? + {$table}.latitude) * 0.5 ),2)
)
) <= ?
SQL;
$center = $filter->getCenter();
$latitude = $center->getLatitude();
$longitude = $center->getLongitude();
$values = [$pid, $latitude, $longitude, $latitude, $filter->getRadius()];
$columns = [
$table . '.active=1',
$table . '.pid=?',
$query
];
return static::findBy($columns, $values, ['order' => $table . '.sorting']);
}
}