Use assets manager in the marker cluster layer mapper.

This commit is contained in:
David Molineus
2016-10-06 09:02:12 +02:00
parent a375a73668
commit daf902b989
2 changed files with 26 additions and 3 deletions

View File

@@ -93,7 +93,11 @@ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\MarkersLa
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\GroupLayerMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\VectorsLayerMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\ReferenceLayerMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\MarkerClusterLayerMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = function () {
return new \Netzmacht\Contao\Leaflet\Mapper\Layer\MarkerClusterLayerMapper(
$GLOBALS['container'][\Netzmacht\Contao\Toolkit\DependencyInjection\Services::ASSETS_MANAGER]
);
};
// Control mappers.
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\ZoomControlMapper';

View File

@@ -14,6 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Filter\Filter;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\Contao\Toolkit\View\Assets\AssetsManager;
use Netzmacht\JavascriptBuilder\Type\AnonymousFunction;
use Netzmacht\JavascriptBuilder\Type\Expression;
use Netzmacht\LeafletPHP\Definition;
@@ -42,6 +43,25 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper
*/
protected static $type = 'markercluster';
/**
* Assets manager.
*
* @var AssetsManager
*/
private $assetsManager;
/**
* MarkerClusterLayerMapper constructor.
*
* @param AssetsManager $assetsManager Assets manager.
*/
public function __construct(AssetsManager $assetsManager)
{
parent::__construct();
$this->assetsManager = $assetsManager;
}
/**
* {@inheritdoc}
*/
@@ -61,7 +81,6 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.Superglobals)
*/
protected function build(
Definition $definition,
@@ -83,7 +102,7 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper
}
if (!$model->disableDefaultStyle) {
$GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet-markercluster/MarkerCluster.Default.css||static';
$this->assetsManager->addStylesheet('assets/leaflet/libs/leaflet-markercluster/MarkerCluster.Default.css');
}
$collection = LayerModel::findBy(