Move layers configuration.

This commit is contained in:
David Molineus
2017-10-06 10:07:19 +02:00
parent 320359d2f0
commit f5badd14c5
10 changed files with 478 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2016-2017 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\Backend\Renderer\Label\Layer;
/**
* Class AbstractLabelRenderer.
*
* @package Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer
*/
abstract class AbstractLabelRenderer implements LayerLabelRenderer
{
/**
* {@inheritdoc}
*/
public function supports(array $row): bool
{
return $row['type'] === $this->getLayerType();
}
/**
* Get the supported layer type.
*
* @return string
*/
abstract protected function getLayerType(): string;
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2016-2017 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\Backend\Renderer\Label\Layer;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/**
* Class ChainRenderer.
*
* @package Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer
*/
final class ChainRenderer implements LayerLabelRenderer
{
/**
* List of layer label renderer.
*
* @var array|LayerLabelRenderer[]
*/
private $renderer;
/**
* ChainRenderer constructor.
*
* @param array|LayerLabelRenderer[] $renderer List of layer label renderer.
*/
public function __construct($renderer)
{
$this->renderer = $renderer;
}
/**
* {@inheritDoc}
*/
public function supports(array $row): bool
{
foreach ($this->renderer as $renderer) {
if ($renderer->supports($row)) {
return true;
}
}
return false;
}
/**
* {@inheritDoc}
*/
public function render(array $row, string $label, Translator $translator): string
{
foreach ($this->renderer as $renderer) {
if ($renderer->supports($row)) {
return $renderer->render($row, $label, $translator);
}
}
return $label;
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2016-2017 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\Backend\Renderer\Label\Layer;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/**
* Interface LayerLabelRenderer.
*
* @package Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer
*/
interface LayerLabelRenderer
{
/**
* Check if current row is supported.
*
* @param array $row Current row.
*
* @return bool
*/
public function supports(array $row): bool;
/**
* Render the backend label of an layer.
*
* @param array $row Current row.
* @param string $label Default label.
* @param Translator $translator The translator.
*
* @return string
*/
public function render(array $row, string $label, Translator $translator): string;
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2016-2017 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\Backend\Renderer\Label\Layer;
use Netzmacht\Contao\Leaflet\Model\MarkerModel;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/**
* Class MarkersLabelRenderer.
*
* @package Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer
*/
final class MarkersLabelRenderer extends AbstractLabelRenderer
{
/**
* {@inheritdoc}
*/
protected function getLayerType(): string
{
return 'markers';
}
/**
* {@inheritdoc}
*/
public function render(array $row, string $label, Translator $translator): string
{
$count = MarkerModel::countBy('pid', $row['id']);
$label .= sprintf(
'<span class="tl_gray"> (%s %s)</span>',
$count,
$translator->trans('countEntries', [], 'contao_tl_leaflet_layer')
);
return $label;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2016-2017 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\Backend\Renderer\Label\Layer;
use Contao\StringUtil;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/**
* Class OverpassLabelRenderer.
*
* @package Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer
*/
final class OverpassLabelRenderer extends AbstractLabelRenderer
{
/**
* {@inheritdoc}
*/
protected function getLayerType(): string
{
return 'vectors';
}
/**
* {@inheritdoc}
*/
public function render(array $row, string $label, Translator $translator): string
{
if ($row['overpassQuery']) {
$label .= '<span class="tl_gray"> ' . StringUtil::substr($row['overpassQuery'], 50) . '</span>';
}
return $label;
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2016-2017 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\Backend\Renderer\Label\Layer;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/**
* Backend label renderer for provider layer.
*
* @package Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer
*/
final class ProviderLabelRenderer extends AbstractLabelRenderer
{
/**
* {@inheritdoc}
*/
protected function getLayerType(): string
{
return 'provider';
}
/**
* {@inheritdoc}
*/
public function render(array $row, string $label, Translator $translator): string
{
$langKey = 'leaflet_provider.' . $row['tile_provider'] . '.0';
$translated = $translator->trans($langKey, [], 'contao_leaflet');
if ($translated !== $langKey) {
$provider = $translated;
} else {
$provider = $row['tile_provider'];
}
$label .= sprintf('<span class="tl_gray"> (%s)</span>', $provider);
return $label;
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2016-2017 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\Backend\Renderer\Label\Layer;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/**
* Class ReferenceLabelRenderer.
*
* @package Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer
*/
final class ReferenceLabelRenderer extends AbstractLabelRenderer
{
/**
* {@inheritdoc}
*/
protected function getLayerType(): string
{
return 'vectors';
}
/**
* {@inheritdoc}
*/
public function render(array $row, string $label, Translator $translator): string
{
$reference = LayerModel::findByPk($row['reference']);
if ($reference) {
$label .= '<span class="tl_gray"> (' . $reference->title . ')</span>';
}
return $label;
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Leaflet maps for Contao CMS.
*
* @package contao-leaflet-maps
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2016-2017 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\Backend\Renderer\Label\Layer;
use Netzmacht\Contao\Leaflet\Model\VectorModel;
use Symfony\Component\Translation\TranslatorInterface as Translator;
/**
* Class VectorsLabelRenderer.
*
* @package Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer
*/
final class VectorsLabelRenderer extends AbstractLabelRenderer
{
/**
* {@inheritdoc}
*/
protected function getLayerType(): string
{
return 'vectors';
}
/**
* {@inheritdoc}
*/
public function render(array $row, string $label, Translator $translator): string
{
$count = VectorModel::countBy('pid', $row['id']);
$label .= sprintf(
'<span class="tl_gray"> (%s %s)</span>',
$count,
$translator->trans('countEntries', [], 'contao_tl_leaflet_layer')
);
return $label;
}
}

View File

@@ -47,5 +47,6 @@ class NetzmachtContaoLeafletExtension extends Extension
$loader->load('filters.yml'); $loader->load('filters.yml');
$loader->load('mappers.yml'); $loader->load('mappers.yml');
$loader->load('encoders.yml'); $loader->load('encoders.yml');
$loader->load('layers.yml');
} }
} }

View File

@@ -0,0 +1,80 @@
# Leaflet layer types.
#
# The type is used for the database driven definitions.
parameters:
netzmacht.contao_leaflet_maps.layers:
provider:
children: false
icon: 'bundles/netzmachtcontaoleaflet/img/provider.png'
group:
children: true
icon: 'bundles/netzmachtcontaoleaflet/img/group.png'
markers:
children: false
icon: 'bundles/netzmachtcontaoleaflet/img/markers.png'
markers: true
boundsMode:
extend: true
fit: 'deferred'
vectors:
children: false
icon: 'bundles/netzmachtcontaoleaflet/img/vectors.png'
vectors: true
boundsMode:
extend: true
reference:
children: false
icon: 'bundles/netzmachtcontaoleaflet/img/reference.png'
markercluster:
children: true
icon: 'bundles/netzmachtcontaoleaflet/img/markercluster.png'
tile:
children: false
icon: 'bundles/netzmachtcontaoleaflet/img/tile.png'
overpass:
children: false
icon: 'bundles/netzmachtcontaoleaflet/img/overpass.png'
boundsMode:
extend: true
fit: true
services:
_defaults:
public: false
netzmacht.contao_leaflet_maps.layer_label_renderer:
class: Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer\ChainRenderer
arguments:
- []
netzmacht.contao_leaflet_maps.layer_label_renderer.markers:
class: Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer\MarkersLabelRenderer
tags:
- { name: 'netzmacht.contao_leaflet_maps.layer_label_renderer' }
netzmacht.contao_leaflet_maps.layer_label_renderer.overpass:
class: Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer\OverpassLabelRenderer
tags:
- { name: 'netzmacht.contao_leaflet_maps.layer_label_renderer' }
netzmacht.contao_leaflet_maps.layer_label_renderer.provider:
class: Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer\ProviderLabelRenderer
tags:
- { name: 'netzmacht.contao_leaflet_maps.layer_label_renderer' }
netzmacht.contao_leaflet_maps.layer_label_renderer.reference:
class: Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer\ReferenceLabelRenderer
tags:
- { name: 'netzmacht.contao_leaflet_maps.layer_label_renderer' }
netzmacht.contao_leaflet_maps.layer_label_renderer.vectors:
class: Netzmacht\Contao\Leaflet\Backend\Renderer\Label\Layer\VectorsLabelRenderer
tags:
- { name: 'netzmacht.contao_leaflet_maps.layer_label_renderer' }