mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-01 20:43:52 +01:00
Add reference layer.
This commit is contained in:
@@ -57,6 +57,10 @@ class Layer
|
||||
|
||||
$icon = \Image::getHtml($src, $alt, sprintf('title="%s"', strip_tags($alt)));
|
||||
|
||||
if (!empty($this->layers[$row['type']]['label'])) {
|
||||
$label = $this->layers[$row['type']]['label']($row, $label);
|
||||
}
|
||||
|
||||
return $icon . ' ' . $label;
|
||||
}
|
||||
|
||||
@@ -146,6 +150,15 @@ class Layer
|
||||
return $this->generateButton($row, $href, $label, $title, $icon, $attributes);
|
||||
}
|
||||
|
||||
public function getLayers($dataContainer)
|
||||
{
|
||||
$collection = LayerModel::findBy('id !', $dataContainer->id);
|
||||
|
||||
return OptionsBuilder::fromCollection($collection, 'id', 'title')
|
||||
->asTree()
|
||||
->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
* @param $href
|
||||
|
||||
@@ -52,7 +52,7 @@ class BuildDefinitionEvent extends Event
|
||||
* @param \Model $model The definition model.
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
*/
|
||||
public function __construct(Definition $definition, \Model $model, LatLngBounds $bounds = null)
|
||||
public function __construct(Definition $definition = null, \Model $model, LatLngBounds $bounds = null)
|
||||
{
|
||||
$this->definition = $definition;
|
||||
$this->model = $model;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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\Layer;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class ReferenceLayerMapper maps an reference layer to another
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
||||
*/
|
||||
class ReferenceLayerMapper extends AbstractLayerMapper
|
||||
{
|
||||
/**
|
||||
* Layer type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $type = 'reference';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null)
|
||||
{
|
||||
$reference = LayerModel::findByPk($model->reference);
|
||||
|
||||
if (!$reference || !$reference->active) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $mapper->handle($reference, $bounds, $this->getElementId($model, $elementId));
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
|
||||
trait ActiveTrait
|
||||
abstract class AbstractActiveModel extends \Model
|
||||
{
|
||||
/**
|
||||
*
|
||||
@@ -28,14 +28,14 @@ trait ActiveTrait
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $modelId
|
||||
* @param int $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return \Model|null
|
||||
*/
|
||||
public static function findActiveByPid($modelId, $options = array())
|
||||
public static function findActiveBy($column, $value, $options = array())
|
||||
{
|
||||
return static::findBy('active=1 AND pid', $modelId, $options);
|
||||
return static::findBy('active=1 AND ' . $column, $value, $options);
|
||||
}
|
||||
|
||||
public static function findActivated($options = array())
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
class ControlModel extends \Model
|
||||
class ControlModel extends AbstractActiveModel
|
||||
{
|
||||
protected static $strTable = 'tl_leaflet_control';
|
||||
}
|
||||
|
||||
@@ -21,9 +21,7 @@ namespace Netzmacht\Contao\Leaflet\Model;
|
||||
* @property mixed|null shadowRetinaImage
|
||||
* @property mixed|null shadowImage
|
||||
*/
|
||||
class IconModel extends \Model
|
||||
class IconModel extends AbstractActiveModel
|
||||
{
|
||||
use ActiveTrait;
|
||||
|
||||
protected static $strTable = 'tl_leaflet_icon';
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
|
||||
class LayerModel extends \Model
|
||||
class LayerModel extends AbstractActiveModel
|
||||
{
|
||||
protected static $strTable = 'tl_leaflet_layer';
|
||||
|
||||
|
||||
@@ -12,9 +12,7 @@
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
|
||||
class StyleModel extends \Model
|
||||
class StyleModel extends AbstractActiveModel
|
||||
{
|
||||
use ActiveTrait;
|
||||
|
||||
protected static $strTable = 'tl_leaflet_style';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user