mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-29 03:24:37 +01:00
Add reference layer.
This commit is contained in:
@@ -30,8 +30,10 @@ L.Contao = L.Class.extend({
|
||||
var map = this;
|
||||
|
||||
this.on('layeradd', function(e) {
|
||||
e.layer.on('data:loading', function() { map.fire('dataloading'); });
|
||||
e.layer.on('data:loaded', function() { map.fire('dataload'); });
|
||||
if (e.layer.on) {
|
||||
e.layer.on('data:loading', function() { map.fire('dataloading'); });
|
||||
e.layer.on('data:loaded', function() { map.fire('dataload'); });
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
BIN
module/assets/img/reference.png
Normal file
BIN
module/assets/img/reference.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 730 B |
BIN
module/assets/img/reference_1.png
Normal file
BIN
module/assets/img/reference_1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 634 B |
@@ -16,7 +16,7 @@ array_insert(
|
||||
'tl_leaflet_map',
|
||||
'tl_leaflet_control',
|
||||
),
|
||||
'icon' => 'system/modules/leaflet/assets/img/leaflet.png',
|
||||
'icon' => 'system/modules/leaflet/assets/img/map.png',
|
||||
'stylesheet' => 'system/modules/leaflet/assets/css/backend.css',
|
||||
),
|
||||
'leaflet_layer' => array
|
||||
@@ -67,6 +67,7 @@ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\ProviderL
|
||||
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\MarkersLayerMapper';
|
||||
$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';
|
||||
|
||||
// Control mappers.
|
||||
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Control\ZoomControlMapper';
|
||||
@@ -122,6 +123,17 @@ $GLOBALS['LEAFLET_LAYERS'] = array
|
||||
(
|
||||
'children' => false,
|
||||
'icon' => 'system/modules/leaflet/assets/img/tile.png',
|
||||
'label' => function ($row, $label) {
|
||||
if (!empty($GLOBALS['TL_LANG']['leaflet_provider'][$row['tile_provider']][0])) {
|
||||
$provider = $GLOBALS['TL_LANG']['leaflet_provider'][$row['tile_provider']][0];
|
||||
} else {
|
||||
$provider = $row['tile_provider'];
|
||||
}
|
||||
|
||||
$label .= sprintf('<span class="tl_gray"> (%s)</span>', $provider);
|
||||
|
||||
return $label;
|
||||
}
|
||||
),
|
||||
'group' => array
|
||||
(
|
||||
@@ -133,13 +145,47 @@ $GLOBALS['LEAFLET_LAYERS'] = array
|
||||
'children' => false,
|
||||
'icon' => 'system/modules/leaflet/assets/img/markers.png',
|
||||
'markers' => true,
|
||||
'label' => function ($row, $label) {
|
||||
$count = \Netzmacht\Contao\Leaflet\Model\MarkerModel::countBy('pid', $row['id']);
|
||||
$label .= sprintf(
|
||||
'<span class="tl_gray"> (%s %s)</span>',
|
||||
$count,
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['countEntries']
|
||||
);
|
||||
|
||||
return $label;
|
||||
}
|
||||
),
|
||||
'vectors' => array
|
||||
(
|
||||
'children' => false,
|
||||
'icon' => 'system/modules/leaflet/assets/img/vectors.png',
|
||||
'vectors' => true,
|
||||
'label' => function ($row, $label) {
|
||||
$count = \Netzmacht\Contao\Leaflet\Model\VectorModel::countBy('pid', $row['id']);
|
||||
$label .= sprintf(
|
||||
'<span class="tl_gray"> (%s %s)</span>',
|
||||
$count,
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['countEntries']
|
||||
);
|
||||
|
||||
return $label;
|
||||
}
|
||||
),
|
||||
'reference' => array
|
||||
(
|
||||
'children' => false,
|
||||
'icon' => 'system/modules/leaflet/assets/img/reference.png',
|
||||
'label' => function ($row, $label) {
|
||||
$reference = \Netzmacht\Contao\Leaflet\Model\LayerModel::findByPk($row['reference']);
|
||||
|
||||
if ($reference) {
|
||||
$label .= '<span class="tl_gray"> (' . $reference->title . ')</span>';
|
||||
}
|
||||
|
||||
return $label;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
|
||||
@@ -136,6 +136,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
|
||||
'vectors extends default' => array(
|
||||
'+active' => array('deferred'),
|
||||
),
|
||||
'reference extends default' => array(
|
||||
'+title' => array('reference')
|
||||
)
|
||||
),
|
||||
|
||||
'metasubselectpalettes' => array(
|
||||
@@ -294,5 +297,19 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
|
||||
'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes'],
|
||||
'sql' => "varchar(32) NOT NULL default ''"
|
||||
),
|
||||
'reference' => array
|
||||
(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['reference'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'select',
|
||||
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getLayers'),
|
||||
'eval' => array(
|
||||
'mandatory' => true,
|
||||
'tl_class' => 'w50',
|
||||
'chosen' => true,
|
||||
'includeBlankOption' => true,
|
||||
),
|
||||
'sql' => "int(10) unsigned NOT NULL default '0'",
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -11,14 +11,16 @@ $GLOBALS['TL_LANG']['leaflet_control']['scale'][1] = 'A simple scale contr
|
||||
$GLOBALS['TL_LANG']['leaflet_control']['loading'][0] = 'Loading indicator';
|
||||
$GLOBALS['TL_LANG']['leaflet_control']['loading'][1] = 'Leaflet.loading is a simple loading indicator implemented as control. For more details read the <a href="https://github.com/ebrelsford/Leaflet.loading" target="_blank">Plugin documentation</a>.';
|
||||
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['provider'][0] = 'Leaflet provider';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['provider'][1] = 'Leaflet tile provider. For more details read the <a href="https://github.com/leaflet-extras/leaflet-providers" target="_blank">plugin documentation</a>.';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['group'][0] = 'Layer group';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['group'][1] = 'Layer groups combines different layers. For more details read the <a href="http://leafletjs.com/reference.html#layergroup" target="_blank">Leaflet documentation</a>. ';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['markers'][0] = 'Markers';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['markers'][1] = 'Layer containing Markers.';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['vectors'][0] = 'Vectors';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['vectors'][1] = 'Vectors layer containing vectors like polygons, polylines, etc.';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['provider'][0] = 'Leaflet provider';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['provider'][1] = 'Leaflet tile provider. For more details read the <a href="https://github.com/leaflet-extras/leaflet-providers" target="_blank">plugin documentation</a>.';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['group'][0] = 'Layer group';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['group'][1] = 'Layer groups combines different layers. For more details read the <a href="http://leafletjs.com/reference.html#layergroup" target="_blank">Leaflet documentation</a>. ';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['markers'][0] = 'Markers';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['markers'][1] = 'Layer containing Markers.';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['vectors'][0] = 'Vectors';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['vectors'][1] = 'Vectors layer containing vectors like polygons, polylines, etc.';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['reference'][0] = 'Reference';
|
||||
$GLOBALS['TL_LANG']['leaflet_layer']['reference'][1] = 'The reference layer is a link to another layer.';
|
||||
|
||||
$GLOBALS['TL_LANG']['leaflet_vector']['polyline'][0] = 'Polyline';
|
||||
$GLOBALS['TL_LANG']['leaflet_vector']['polyline'][1] = 'Polyline overlay. For more details read the <a href="http://leafletjs.com/reference.html#polyline" target="_blank">Leaflet documentation</a>.';
|
||||
|
||||
@@ -36,6 +36,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_variant'][0] = 'Tile vari
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_variant'][1] = 'Tile variant style.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['active'][0] = 'Activate layer';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['active'][1] = 'Activate layer on the map.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['reference'][0] = 'Reference';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['reference'][1] = 'Choose the reference layer.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['markerCluster'][0] = 'Marker cluster';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['markerCluster'][1] = 'Choose a marker cluster layer so that markers get clustered.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['deferred'][0] = 'Deferred loading';
|
||||
@@ -47,3 +49,5 @@ $GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][0] = 'Layer gro
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][1] = 'Basic layer group. <br> See <a href="http://leafletjs.com/reference.html#layergroup" target="_blank">http://leafletjs.com/reference.html#layergroup</a>';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['feature'][0] = 'Feature group';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['feature'][1] = 'Extended layer group with events and popup support. <br>See <a href="http://leafletjs.com/reference.html#featuregroup" target="_blank">http://leafletjs.com/reference.html#featuregroup</a>';
|
||||
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['countEntries'] = 'Entries';
|
||||
|
||||
@@ -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