Store layer relations in extra table.

This commit is contained in:
David Molineus
2015-01-09 22:33:57 +01:00
parent c7f37238d9
commit ff2c3fb8c3
12 changed files with 307 additions and 29 deletions

View File

@@ -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;
}
}

View File

@@ -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) {