diff --git a/module/dca/tl_leaflet_layer.php b/module/dca/tl_leaflet_layer.php index e69de29..760e170 100644 --- a/module/dca/tl_leaflet_layer.php +++ b/module/dca/tl_leaflet_layer.php @@ -0,0 +1,178 @@ + array( + 'dataContainer' => 'Table', + 'enableVersioning' => true, + 'sql' => array + ( + 'keys' => array + ( + 'id' => 'primary' + ) + ) + ), + 'list' => array + ( + 'sorting' => array + ( + 'mode' => 5, + 'fields' => array('title'), + 'flag' => 1 + ), + 'label' => array + ( + 'fields' => array('title'), + 'format' => '%s' + ), + 'global_operations' => array + ( + 'all' => array + ( + 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], + 'href' => 'act=select', + 'class' => 'header_edit_all', + 'attributes' => 'onclick="Backend.getScrollOffset();" accesskey="e"' + ) + ), + 'operations' => array + ( + 'edit' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['edit'], + 'href' => 'act=edit', + 'icon' => 'header.gif' + ), + 'copy' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['copy'], + 'href' => 'act=copy', + 'icon' => 'copy.gif' + ), + 'delete' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['delete'], + 'href' => 'act=delete', + 'icon' => 'delete.gif', + 'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"' + ), + 'show' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['show'], + 'href' => 'act=show', + 'icon' => 'show.gif' + ) + ) + ), + + 'metapalettes' => array( + 'default' => array( + 'title' => array('title', 'alias', 'type'), + ), + ), + + 'metasubselectpalettes' => array( + 'type' => array( + 'provider' => array('tile_provider', 'tile_provider_variant') + ), + 'tile_provider' => array( + 'MapBox' => array('tile_provider_key'), + 'HERE' => array('tile_provider_key', 'tile_provider_code'), + ), + ), + + 'fields' => array + ( + 'id' => array + ( + 'sql' => "int(10) unsigned NOT NULL auto_increment" + ), + 'pid' => array + ( + 'sql' => "int(10) unsigned NOT NULL default '0'" + ), + 'sorting' => array + ( + 'sql' => "int(10) unsigned NOT NULL default '0'" + ), + 'tstamp' => array + ( + 'sql' => "int(10) unsigned NOT NULL default '0'" + ), + 'title' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['title'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50'), + 'sql' => "varchar(255) NOT NULL default ''" + ), + 'alias' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['alias'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'), + 'sql' => "varchar(255) NOT NULL default ''" + ), + 'type' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['type'], + 'exclude' => true, + 'inputType' => 'select', + 'eval' => array( + 'mandatory' => true, + 'tl_class' => 'w50', + 'includeBlankOption' => true, + 'submitOnChange' => true, + 'chosen' => true, + ), + 'options' => &$GLOBALS['LEAFLET_LAYERS'], + 'sql' => "varchar(32) NOT NULL default ''" + ), + 'tile_provider' => array( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider'], + 'exclude' => true, + 'inputType' => 'select', + 'eval' => array( + 'mandatory' => true, + 'tl_class' => 'w50 clr', + 'includeBlankOption' => true, + 'submitOnChange' => true, + 'chosen' => true, + ), + 'options' => array_keys($GLOBALS['LEAFLET_TILE_PROVIDERS']), + 'sql' => "varchar(32) NOT NULL default ''" + ), + 'tile_provider_variant' => array( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_variant'], + 'exclude' => true, + 'inputType' => 'select', + 'eval' => array( + 'mandatory' => false, + 'tl_class' => 'w50', + 'submitOnChange' => true, + 'chosen' => false, + ), + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getVariants'), + 'sql' => "varchar(32) NOT NULL default ''" + ), + 'tile_provider_key' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_key'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'clr w50'), + 'sql' => "varchar(255) NOT NULL default ''" + ), + 'tile_provider_code' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_code'], + 'exclude' => true, + 'inputType' => 'text', + 'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50'), + 'sql' => "varchar(255) NOT NULL default ''" + ), + ) +); diff --git a/module/dca/tl_leaflet_map.php b/module/dca/tl_leaflet_map.php index 7c8525f..5215e6b 100644 --- a/module/dca/tl_leaflet_map.php +++ b/module/dca/tl_leaflet_map.php @@ -5,7 +5,6 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'config' => array( 'dataContainer' => 'Table', 'enableVersioning' => true, -// 'ctable' => array('tl_leaflet'), 'sql' => array ( 'keys' => array @@ -30,13 +29,20 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array ), 'global_operations' => array ( + 'layers' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'], + 'href' => 'table=tl_leaflet_layer', + 'class' => 'header_edit_all', + 'attributes' => 'onclick="Backend.getScrollOffset();" accesskey="e"' + ), 'all' => array ( 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], 'href' => 'act=select', 'class' => 'header_edit_all', 'attributes' => 'onclick="Backend.getScrollOffset();" accesskey="e"' - ) + ), ), 'operations' => array ( @@ -73,6 +79,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'title' => array('title', 'alias'), 'zoom' => array('center', 'zoom', 'adjustZoomExtra'), 'controls' => array('zoomControl', 'controls'), + 'layers' => array('layers'), 'interaction' => array( 'dragging', 'touchZoom', @@ -87,10 +94,8 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'closeOnClick', 'bounceAtZoomLimits' ), - 'experts' => array( + 'expert' => array( 'options', - 'detachLibraries', - 'cache' ) ), ), @@ -123,7 +128,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['alias'], 'exclude' => true, 'inputType' => 'text', - 'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50'), + 'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'), 'sql' => "varchar(255) NOT NULL default ''" ), 'center' => array @@ -144,6 +149,18 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array ), 'sql' => "varchar(255) NULL" ), + 'layers' => array + ( + 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['layers'], + 'exclude' => true, + 'inputType' => 'checkboxWizard', + 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getLayers'), + 'default' => '', + 'eval' => array( + 'multiple' => true, + ), + 'sql' => "mediumblob NULL" + ), 'zoom' => array ( 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['zoom'], @@ -226,7 +243,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['zoomValues'], 'default' => true, 'eval' => array('tl_class' => 'w50', 'helpwizard' => true,), - 'sql' => "char(1) NOT NULL default ''" + 'sql' => "char(6) NOT NULL default ''" ), 'doubleClickZoom' => array ( @@ -237,7 +254,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['zoomValues'], 'default' => true, 'eval' => array('tl_class' => 'w50', 'helpwizard' => true,), - 'sql' => "char(1) NOT NULL default ''" + 'sql' => "char(6) NOT NULL default ''" ), 'boxZoom' => array ( @@ -329,23 +346,5 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array 'eval' => array('tl_class' => 'clr lng', 'allowHtml'=>true, 'style' => 'min-height: 40px;'), 'sql' => "char(1) NOT NULL default ''" ), - 'detachLibraries' => array - ( - 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['detachLibraries'], - 'exclude' => true, - 'inputType' => 'checkbox', - 'default' => false, - 'eval' => array('tl_class' => 'w50'), - 'sql' => "char(1) NOT NULL default ''" - ), - 'cache' => array - ( - 'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['cache'], - 'exclude' => true, - 'inputType' => 'checkbox', - 'default' => false, - 'eval' => array('tl_class' => 'w50', 'submitOnChange' => true), - 'sql' => "char(1) NOT NULL default '0'" - ), ), ); diff --git a/src/Netzmacht/Contao/Leaflet/Dca/Layer.php b/src/Netzmacht/Contao/Leaflet/Dca/Layer.php new file mode 100644 index 0000000..a7047dd --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Dca/Layer.php @@ -0,0 +1,28 @@ + + * @copyright 2014 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Dca; + + +class Layer +{ + public function getVariants($dataContainer) + { + if ($dataContainer->activeRecord + && $dataContainer->activeRecord->tile_provider + && !empty($GLOBALS['LEAFLET_TILE_PROVIDERS'][$dataContainer->activeRecord->tile_provider]['variants']) + ) { + return $GLOBALS['LEAFLET_TILE_PROVIDERS'][$dataContainer->activeRecord->tile_provider]['variants']; + } + + return array(); + } +} diff --git a/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php b/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php index a55bd3a..521589e 100644 --- a/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php +++ b/src/Netzmacht/Contao/Leaflet/Mapper/MapMapper.php @@ -11,9 +11,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper; +use Netzmacht\Contao\Leaflet\Model\LayerModel; use Netzmacht\Contao\Leaflet\Model\MapModel; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Map; +use Netzmacht\LeafletPHP\Plugins\LeafletProviders\Provider; class MapMapper extends AbstractMapper { @@ -102,5 +104,15 @@ class MapMapper extends AbstractMapper */ private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper) { + $ids = deserialize($model->layers, true); + $collection = LayerModel::findMultipleByIds($ids); + + if ($collection) { + foreach ($collection as $layer) { + /** @var Provider $layer */ + $layer = $mapper->handle($layer); + $map->addLayer($layer); + } + } } } diff --git a/src/Netzmacht/Contao/Leaflet/Model/LayerModel.php b/src/Netzmacht/Contao/Leaflet/Model/LayerModel.php new file mode 100644 index 0000000..3cd46e3 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Model/LayerModel.php @@ -0,0 +1,19 @@ + + * @copyright 2014 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Model; + + +class LayerModel extends \Model +{ + protected static $strTable = 'tl_leaflet_layer'; + +}