mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-01 04:24:02 +01:00
Store layer relations in extra table.
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\ControlModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
@@ -45,12 +46,12 @@ class LayersControlMapper extends AbstractControlMapper
|
||||
$arguments[1] = array();
|
||||
$arguments[2] = array();
|
||||
|
||||
$definition = $this->getLayersDefinition($model);
|
||||
$collection = LayerModel::findMultipleByIds(array_keys($definition));
|
||||
/** @var ControlModel $model */
|
||||
$collection = $model->findLayers();
|
||||
|
||||
if ($collection) {
|
||||
foreach ($collection as $layer) {
|
||||
$argument = ($definition[$layer->id] === 'overlay') ? 2 : 1;
|
||||
$argument = ($layer->controlMode === 'overlay') ? 2 : 1;
|
||||
|
||||
$arguments[$argument][] = $mapper->handle($layer, $bounds);
|
||||
}
|
||||
@@ -58,25 +59,4 @@ class LayersControlMapper extends AbstractControlMapper
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get layers definition from the control model.
|
||||
*
|
||||
* @param \Model $model The control model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getLayersDefinition(\Model $model)
|
||||
{
|
||||
$layers = deserialize($model->layers, true);
|
||||
$definition = array();
|
||||
|
||||
foreach ($layers as $layer) {
|
||||
if ($layer['layer']) {
|
||||
$definition[$layer['layer']] = $layer['mode'];
|
||||
}
|
||||
}
|
||||
|
||||
return $definition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,8 +127,7 @@ class MapMapper extends AbstractMapper
|
||||
*/
|
||||
private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
{
|
||||
$ids = deserialize($model->layers, true);
|
||||
$collection = LayerModel::findMultipleByIds($ids);
|
||||
$collection = $model->findLayers();
|
||||
|
||||
if ($collection) {
|
||||
foreach ($collection as $layer) {
|
||||
|
||||
Reference in New Issue
Block a user