forked from Snck3rs/contao-leaflet-maps
Fix code style issues.
This commit is contained in:
@@ -72,10 +72,6 @@ class LayerCallbacks extends Callbacks
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $amenities;
|
private $amenities;
|
||||||
/**
|
|
||||||
* @var Manager
|
|
||||||
*/
|
|
||||||
private $manager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct.
|
* Construct.
|
||||||
@@ -85,7 +81,7 @@ class LayerCallbacks extends Callbacks
|
|||||||
* @param Translator $translator Translator.
|
* @param Translator $translator Translator.
|
||||||
* @param array $layers Leaflet layer configuration.
|
* @param array $layers Leaflet layer configuration.
|
||||||
* @param array $tileProviders Tile providers.
|
* @param array $tileProviders Tile providers.
|
||||||
* @param array $amenities OSM amenities
|
* @param array $amenities OSM amenities.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Manager $manager,
|
Manager $manager,
|
||||||
@@ -102,7 +98,6 @@ class LayerCallbacks extends Callbacks
|
|||||||
$this->database = $database;
|
$this->database = $database;
|
||||||
$this->layers = $layers;
|
$this->layers = $layers;
|
||||||
$this->tileProviders = $tileProviders;
|
$this->tileProviders = $tileProviders;
|
||||||
$this->manager = $manager;
|
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->amenities = $amenities;
|
$this->amenities = $amenities;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,28 +59,6 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas
|
|||||||
$this->setOptions($options);
|
$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.
|
* Set the query.
|
||||||
*
|
*
|
||||||
@@ -96,7 +74,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas
|
|||||||
/**
|
/**
|
||||||
* Get query.
|
* Get query.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getQuery()
|
public function getQuery()
|
||||||
{
|
{
|
||||||
@@ -118,7 +96,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas
|
|||||||
/**
|
/**
|
||||||
* Get endpoint.
|
* Get endpoint.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getEndpoint()
|
public function getEndpoint()
|
||||||
{
|
{
|
||||||
@@ -164,7 +142,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas
|
|||||||
/**
|
/**
|
||||||
* Get minZoom.
|
* Get minZoom.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getMinZoom()
|
public function getMinZoom()
|
||||||
{
|
{
|
||||||
@@ -176,7 +154,7 @@ class OverpassLayer extends AbstractLayer implements HasOptions, ConvertsToJavas
|
|||||||
*/
|
*/
|
||||||
public function encode(Encoder $encoder, $flags = null)
|
public function encode(Encoder $encoder, $flags = null)
|
||||||
{
|
{
|
||||||
$buffer = sprintf (
|
$buffer = sprintf(
|
||||||
'%s = new L.OverPassLayer(%s)%s',
|
'%s = new L.OverPassLayer(%s)%s',
|
||||||
$encoder->encodeReference($this),
|
$encoder->encodeReference($this),
|
||||||
$encoder->encodeArray($this->getOptions(), JSON_FORCE_OBJECT),
|
$encoder->encodeArray($this->getOptions(), JSON_FORCE_OBJECT),
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use Netzmacht\JavascriptBuilder\Type\Expression;
|
|||||||
use Netzmacht\LeafletPHP\Definition;
|
use Netzmacht\LeafletPHP\Definition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class OverpassLayerMapper
|
* Class OverpassLayerMapper.
|
||||||
*
|
*
|
||||||
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
||||||
*/
|
*/
|
||||||
@@ -92,19 +92,11 @@ class OverpassLayerMapper extends AbstractLayerMapper
|
|||||||
*/
|
*/
|
||||||
protected function buildAmenityIconsMap(Model $model)
|
protected function buildAmenityIconsMap(Model $model)
|
||||||
{
|
{
|
||||||
$amenityIconsConfig = deserialize($model->amenityIcons, true);
|
$amenityIconsMap = $this->filterAmenityIconsConfig($model->amenityIcons);
|
||||||
$amenityIconsMap = [];
|
|
||||||
foreach ($amenityIconsConfig as $config) {
|
|
||||||
if (!$config['amenity'] || !$config['icon']) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$amenityIconsMap[$config['amenity']] = $config['icon'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($amenityIconsMap) {
|
if ($amenityIconsMap) {
|
||||||
$collection = IconModel::findMultipleByIds(array_unique($amenityIconsMap));
|
$collection = IconModel::findMultipleByIds(array_unique($amenityIconsMap));
|
||||||
$icons = [];
|
$icons = [];
|
||||||
|
|
||||||
if ($collection) {
|
if ($collection) {
|
||||||
foreach ($collection as $iconModel) {
|
foreach ($collection as $iconModel) {
|
||||||
@@ -121,4 +113,27 @@ class OverpassLayerMapper extends AbstractLayerMapper
|
|||||||
|
|
||||||
return $amenityIconsMap;
|
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\Boot\Event\InitializeSystemEvent;
|
||||||
use Netzmacht\Contao\Toolkit\DependencyInjection\Services;
|
use Netzmacht\Contao\Toolkit\DependencyInjection\Services;
|
||||||
use Netzmacht\LeafletPHP\Assets;
|
use Netzmacht\LeafletPHP\Assets;
|
||||||
|
use Netzmacht\LeafletPHP\Definition\Type\Icon;
|
||||||
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
|
||||||
@@ -218,23 +219,7 @@ class BootSubscriber implements EventSubscriberInterface
|
|||||||
'options' => $icon->getOptions(),
|
'options' => $icon->getOptions(),
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($icon::getRequiredLibraries() as $library) {
|
$this->loadIconsLibraries($icon);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($icons) {
|
if ($icons) {
|
||||||
@@ -266,4 +251,32 @@ class BootSubscriber implements EventSubscriberInterface
|
|||||||
|
|
||||||
return new $mapper;
|
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