mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-28 11:04:08 +01:00
Fix code style issues.
This commit is contained in:
@@ -72,10 +72,6 @@ class LayerCallbacks extends Callbacks
|
||||
* @var array
|
||||
*/
|
||||
private $amenities;
|
||||
/**
|
||||
* @var Manager
|
||||
*/
|
||||
private $manager;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
@@ -85,7 +81,7 @@ class LayerCallbacks extends Callbacks
|
||||
* @param Translator $translator Translator.
|
||||
* @param array $layers Leaflet layer configuration.
|
||||
* @param array $tileProviders Tile providers.
|
||||
* @param array $amenities OSM amenities
|
||||
* @param array $amenities OSM amenities.
|
||||
*/
|
||||
public function __construct(
|
||||
Manager $manager,
|
||||
@@ -102,7 +98,6 @@ class LayerCallbacks extends Callbacks
|
||||
$this->database = $database;
|
||||
$this->layers = $layers;
|
||||
$this->tileProviders = $tileProviders;
|
||||
$this->manager = $manager;
|
||||
$this->translator = $translator;
|
||||
$this->amenities = $amenities;
|
||||
}
|
||||
|
||||
@@ -59,28 +59,6 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the debug mode.
|
||||
*
|
||||
* @param bool $debug Debug mode.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDebug($debug)
|
||||
{
|
||||
return $this->setOption('debug', (bool) $debug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get debug mode.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getDebug()
|
||||
{
|
||||
return $this->getOption('debug', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the query.
|
||||
*
|
||||
@@ -96,7 +74,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas
|
||||
/**
|
||||
* Get query.
|
||||
*
|
||||
* @return bool
|
||||
* @return string
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
@@ -118,7 +96,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas
|
||||
/**
|
||||
* Get endpoint.
|
||||
*
|
||||
* @return bool
|
||||
* @return string
|
||||
*/
|
||||
public function getEndpoint()
|
||||
{
|
||||
@@ -164,7 +142,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas
|
||||
/**
|
||||
* Get minZoom.
|
||||
*
|
||||
* @return bool
|
||||
* @return int
|
||||
*/
|
||||
public function getMinZoom()
|
||||
{
|
||||
@@ -176,7 +154,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas
|
||||
*/
|
||||
public function encode(Encoder $encoder, $flags = null)
|
||||
{
|
||||
$buffer = sprintf (
|
||||
$buffer = sprintf(
|
||||
'%s = new L.OverPassLayer(%s)%s',
|
||||
$encoder->encodeReference($this),
|
||||
$encoder->encodeArray($this->getOptions(), JSON_FORCE_OBJECT),
|
||||
|
||||
@@ -19,7 +19,7 @@ use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
|
||||
/**
|
||||
* Class OverpassLayerMapper
|
||||
* Class OverpassLayerMapper.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
||||
*/
|
||||
@@ -92,19 +92,11 @@ class OverpassLayerMapper extends AbstractLayerMapper
|
||||
*/
|
||||
protected function buildAmenityIconsMap(Model $model)
|
||||
{
|
||||
$amenityIconsConfig = deserialize($model->amenityIcons, true);
|
||||
$amenityIconsMap = [];
|
||||
foreach ($amenityIconsConfig as $config) {
|
||||
if (!$config['amenity'] || !$config['icon']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$amenityIconsMap[$config['amenity']] = $config['icon'];
|
||||
}
|
||||
$amenityIconsMap = $this->filterAmenityIconsConfig($model->amenityIcons);
|
||||
|
||||
if ($amenityIconsMap) {
|
||||
$collection = IconModel::findMultipleByIds(array_unique($amenityIconsMap));
|
||||
$icons = [];
|
||||
$collection = IconModel::findMultipleByIds(array_unique($amenityIconsMap));
|
||||
$icons = [];
|
||||
|
||||
if ($collection) {
|
||||
foreach ($collection as $iconModel) {
|
||||
@@ -121,4 +113,27 @@ class OverpassLayerMapper extends AbstractLayerMapper
|
||||
|
||||
return $amenityIconsMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the amenity icons config.
|
||||
*
|
||||
* @param mixed $amenityIconsConfig Raw config from the db.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function filterAmenityIconsConfig($amenityIconsConfig)
|
||||
{
|
||||
$amenityIconsConfig = deserialize($amenityIconsConfig, true);
|
||||
$amenityIconsMap = [];
|
||||
|
||||
foreach ($amenityIconsConfig as $config) {
|
||||
if (!$config['amenity'] || !$config['icon']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$amenityIconsMap[$config['amenity']] = $config['icon'];
|
||||
}
|
||||
|
||||
return $amenityIconsMap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
use Netzmacht\Contao\Toolkit\Boot\Event\InitializeSystemEvent;
|
||||
use Netzmacht\Contao\Toolkit\DependencyInjection\Services;
|
||||
use Netzmacht\LeafletPHP\Assets;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\Icon;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
@@ -218,23 +219,7 @@ class BootSubscriber implements EventSubscriberInterface
|
||||
'options' => $icon->getOptions(),
|
||||
);
|
||||
|
||||
foreach ($icon::getRequiredLibraries() as $library) {
|
||||
if (!isset($this->libraries[$library])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$assets = $this->libraries[$library];
|
||||
|
||||
if (!empty($assets['css'])) {
|
||||
list ($source, $type) = (array) $assets['css'];
|
||||
$this->assets->addStylesheet($source, $type ?: Assets::TYPE_FILE);
|
||||
}
|
||||
|
||||
if (!empty($assets['javascript'])) {
|
||||
list ($source, $type) = (array) $assets['javascript'];
|
||||
$this->assets->addJavascript($source, $type ?: Assets::TYPE_FILE);
|
||||
}
|
||||
}
|
||||
$this->loadIconsLibraries($icon);
|
||||
}
|
||||
|
||||
if ($icons) {
|
||||
@@ -266,4 +251,32 @@ class BootSubscriber implements EventSubscriberInterface
|
||||
|
||||
return new $mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all libraries for an icon.
|
||||
*
|
||||
* @param Icon $icon Icon definition
|
||||
*
|
||||
* @return void.
|
||||
*/
|
||||
protected function loadIconsLibraries($icon)
|
||||
{
|
||||
foreach ($icon::getRequiredLibraries() as $library) {
|
||||
if (!isset($this->libraries[$library])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$assets = $this->libraries[$library];
|
||||
|
||||
if (!empty($assets['css'])) {
|
||||
list ($source, $type) = (array)$assets['css'];
|
||||
$this->assets->addStylesheet($source, $type ?: Assets::TYPE_FILE);
|
||||
}
|
||||
|
||||
if (!empty($assets['javascript'])) {
|
||||
list ($source, $type) = (array)$assets['javascript'];
|
||||
$this->assets->addJavascript($source, $type ?: Assets::TYPE_FILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user