mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-29 11:33:46 +01:00
Add DivIcon support.
This commit is contained in:
@@ -22,4 +22,12 @@ class AbstractIconMapper extends AbstractTypeMapper
|
||||
* @var string
|
||||
*/
|
||||
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\IconModel';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
$this->addConditionalOption('className');
|
||||
}
|
||||
}
|
||||
|
||||
61
src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php
Normal file
61
src/Netzmacht/Contao/Leaflet/Mapper/Type/DivIconMapper.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2015 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Type;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\DivIcon;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
class DivIconMapper extends AbstractIconMapper
|
||||
{
|
||||
/**
|
||||
* Class of the definition being created.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Type\DivIcon';
|
||||
|
||||
/**
|
||||
* Layer type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $type = 'div';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
$this->addOption('html');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
) {
|
||||
parent::build($definition, $model, $mapper, $bounds);
|
||||
|
||||
if ($definition instanceof DivIcon && $model->iconSize) {
|
||||
$definition->setIconSize(explode(',', $model->iconSize, 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Type;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\Icon;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
class ImageIconMapper extends AbstractIconMapper
|
||||
@@ -25,7 +25,7 @@ class ImageIconMapper extends AbstractIconMapper
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Type\Icon';
|
||||
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Type\ImageIcon';
|
||||
|
||||
/**
|
||||
* Layer type.
|
||||
@@ -34,14 +34,6 @@ class ImageIconMapper extends AbstractIconMapper
|
||||
*/
|
||||
protected static $type = 'image';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
$this->addConditionalOption('className');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -69,7 +61,7 @@ class ImageIconMapper extends AbstractIconMapper
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
) {
|
||||
if ($definition instanceof Icon) {
|
||||
if ($definition instanceof ImageIcon) {
|
||||
$this->addIcon($definition, $model);
|
||||
$this->addShadow($definition, $model);
|
||||
}
|
||||
@@ -78,12 +70,12 @@ class ImageIconMapper extends AbstractIconMapper
|
||||
/**
|
||||
* Add icon image.
|
||||
*
|
||||
* @param Icon $definition The icon definition.
|
||||
* @param ImageIcon $definition The icon definition.
|
||||
* @param IconModel $model The model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addIcon(Icon $definition, IconModel $model)
|
||||
private function addIcon(ImageIcon $definition, IconModel $model)
|
||||
{
|
||||
if ($model->iconImage) {
|
||||
$file = \FilesModel::findByUuid($model->iconImage);
|
||||
@@ -120,12 +112,12 @@ class ImageIconMapper extends AbstractIconMapper
|
||||
/**
|
||||
* Add shadow if defined.
|
||||
*
|
||||
* @param Icon $definition The icon definition.
|
||||
* @param ImageIcon $definition The icon definition.
|
||||
* @param IconModel $model The model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function addShadow(Icon $definition, $model)
|
||||
private function addShadow(ImageIcon $definition, $model)
|
||||
{
|
||||
if ($model->shadowImage) {
|
||||
$file = \FilesModel::findByUuid($model->shadowImage);
|
||||
|
||||
@@ -16,7 +16,7 @@ use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\Icon;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\UI\Marker;
|
||||
|
||||
@@ -80,7 +80,7 @@ class MarkerMapper extends AbstractMapper
|
||||
);
|
||||
|
||||
if ($iconModel) {
|
||||
/** @var Icon $icon */
|
||||
/** @var ImageIcon $icon */
|
||||
$icon = $builder->handle($iconModel);
|
||||
$definition->setIcon($icon);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ use Netzmacht\Contao\Leaflet\Event\InitializeLeafletBuilderEvent;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
use Netzmacht\LeafletPHP\Assets;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\Icon;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
@@ -136,7 +136,7 @@ class BootSubscriber implements EventSubscriberInterface
|
||||
$icons = array();
|
||||
|
||||
foreach ($collection as $model) {
|
||||
/** @var Icon $icon */
|
||||
/** @var ImageIcon $icon */
|
||||
$icon = $mapper->handle($model);
|
||||
$icons[] = array(
|
||||
'id' => $icon->getId(),
|
||||
|
||||
Reference in New Issue
Block a user