Ongoing development.

This commit is contained in:
David Molineus
2015-01-06 14:55:53 +01:00
parent dfb558b655
commit e9d1ec7081
32 changed files with 1050 additions and 95 deletions

View File

@@ -3,6 +3,10 @@
background: url('./../img/fol-placeholder.gif') no-repeat 6px 1px;
}
.tl_listing_container.tree_view ul > li.tl_file > div {
line-height: 18px;
}
.tl_listing_container.tree_view > ul > li.tl_file {
padding-left: 26px;
}

BIN
module/assets/img/group.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
module/assets/img/map.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 873 B

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -89,7 +89,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
'default' => array(
'name' => array('title', 'alias', 'type', 'position'),
'config' => array(),
'active' => array('active')
'active' => array('active'),
),
'zoom extends default' => array(
'config' => array('zoomInText', 'zoomOutText', 'zoomInTitle', 'zoomOutTitle'),
@@ -160,7 +160,8 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
'exclude' => true,
'inputType' => 'select',
'options' => array('topleft', 'topright', 'bottomleft', 'bottomright'),
'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50'),
'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_control'],
'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50', 'helpwizard' => true),
'sql' => "varchar(255) NOT NULL default ''"
),
'active' => array
@@ -189,7 +190,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
),
'zoomInTitle' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomInText'],
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomInTitle'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
@@ -197,7 +198,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
),
'zoomOutTitle' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomInText'],
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomOutTitle'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
@@ -245,12 +246,14 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
),
'mode' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['layer'],
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_control']['layerMode'],
'exclude' => true,
'inputType' => 'select',
'options' => array('base', 'overlay'),
'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_control'],
'eval' => array(
'style' => 'width: 200px'
'style' => 'width: 200px',
'helpwizard' => true,
),
),
)

View File

@@ -26,7 +26,8 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'label' => array
(
'fields' => array('title'),
'format' => '%s'
'format' => '%s',
'label_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'generateRow')
),
'global_operations' => array
(
@@ -47,6 +48,13 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
),
'operations' => array
(
'markers' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['markers'],
'href' => 'table=tl_leaflet_marker',
'icon' => 'edit.gif',
'button_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'generateMarkersButton'),
),
'edit' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['edit'],
@@ -73,6 +81,16 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'icon' => 'delete.gif',
'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"'
),
'toggle' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['toggle'],
'icon' => 'visible.gif',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
'button_callback' => \Netzmacht\Contao\DevTools\Dca::createToggleIconCallback(
'tl_leaflet_layer',
'active'
)
),
'show' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['show'],
@@ -82,9 +100,17 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
)
),
'palettes' => array(
'__selector__' => array('type'),
),
'metapalettes' => array(
'default' => array(
'title' => array('title', 'alias', 'type'),
'title' => array('title', 'alias', 'type'),
'active' => array('active'),
),
'markers extends default' => array(
'+title' => array('markerCluster'),
),
),
@@ -97,26 +123,25 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'HERE' => array('tile_provider_key', 'tile_provider_code'),
),
),
'fields' => array
(
'id' => array
'id' => array
(
'sql' => "int(10) unsigned NOT NULL auto_increment"
'sql' => "int(10) unsigned NOT NULL auto_increment"
),
'pid' => array
'pid' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'"
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'sorting' => array
'sorting' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'"
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'tstamp' => array
'tstamp' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'"
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'title' => array
'title' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['title'],
'exclude' => true,
@@ -124,7 +149,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'alias' => array
'alias' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['alias'],
'exclude' => true,
@@ -132,7 +157,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'type' => array
'type' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['type'],
'exclude' => true,
@@ -145,9 +170,18 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'chosen' => true,
),
'options' => array_keys($GLOBALS['LEAFLET_LAYERS']),
'reference' => &$GLOBALS['TL_LANG']['leaflet_layer'],
'sql' => "varchar(32) NOT NULL default ''"
),
'tile_provider' => array(
'active' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['active'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
),
'tile_provider' => array(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider'],
'exclude' => true,
'inputType' => 'select',
@@ -162,19 +196,19 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'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,
'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 ''"
'sql' => "varchar(32) NOT NULL default ''"
),
'tile_provider_key' => array
'tile_provider_key' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_key'],
'exclude' => true,
@@ -182,7 +216,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'clr w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'tile_provider_code' => array
'tile_provider_code' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_code'],
'exclude' => true,
@@ -190,5 +224,21 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'markerCluster' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['markerCluster'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Layer', 'getMarkerClusterLayers'),
'reference' => &$GLOBALS['TL_LANG']['leaflet_layer'],
'eval' => array(
'mandatory' => false,
'maxlength' => 255,
'tl_class' => 'w50',
'chosen' => true,
'includeBlankOption' => true
),
'sql' => "varchar(255) NOT NULL default ''"
),
)
);

View File

@@ -0,0 +1,361 @@
<?php
$GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
(
'config' => array(
'dataContainer' => 'Table',
'enableVersioning' => true,
'ptable' => 'tl_leaflet_layer',
'sql' => array
(
'keys' => array
(
'id' => 'primary'
)
)
),
'list' => array
(
'sorting' => array
(
'mode' => 4,
'fields' => array('title'),
'flag' => 1,
'headerFields' => array('title', 'type'),
'child_record_callback' => array('Netzmacht\Contao\Leaflet\Dca\Marker', 'generateRow'),
),
'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_marker']['edit'],
'href' => 'act=edit',
'icon' => 'edit.gif'
),
'copy' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['copy'],
'href' => 'act=copy',
'icon' => 'copy.gif'
),
'delete' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['delete'],
'href' => 'act=delete',
'icon' => 'delete.gif',
'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"'
),
'toggle' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['toggle'],
'icon' => 'visible.gif',
'attributes' => 'onclick="Backend.getScrollOffset();return AjaxRequest.toggleVisibility(this,%s)"',
'button_callback' => \Netzmacht\Contao\DevTools\Dca::createToggleIconCallback(
'tl_leaflet_marker',
'active'
)
),
'show' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['show'],
'href' => 'act=show',
'icon' => 'show.gif'
)
)
),
'metapalettes' => array(
'default' => array(
'title' => array('title', 'alias', 'coordinates'),
'content' => array('tooltip', 'alt', 'addPopup'),
'icon' => array(':hide', 'customIcon'),
'config' => array(
':hide',
'clickable',
'draggable',
'keyboard',
'zIndexOffset',
'opacity',
'riseOnHover',
'riseOffset'
),
'active' => array('active')
),
),
'metasubpalettes' => array(
'addPopup' => array('popupContent'),
'customIcon' => array(
'icon',
'retinaIcon',
'iconAnchor',
'popupAnchor',
'iconClassName',
'shadowImage',
'shadowRetinaImage',
'shadowAnchor',
)
),
'fields' => array
(
'id' => array
(
'sql' => "int(10) unsigned NOT NULL auto_increment"
),
'tstamp' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'pid' => array
(
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'title' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['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_marker']['alias'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'coordinates' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['coordinates'],
'exclude' => true,
'inputType' => 'text',
'save_callback' => array(
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate')
),
'wizard' => array(
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getGeocoder')
),
'eval' => array(
'maxlength' => 255,
'tl_class' => 'long clr',
'nullIfEmpty' => true,
),
'sql' => "varchar(255) NULL"
),
'active' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['active'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
),
'tooltip' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['tooltip'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'alt' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['alt'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
'addPopup' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['addPopup'],
'exclude' => true,
'inputType' => 'checkbox',
'default' => true,
'eval' => array('tl_class' => 'w50', 'submitOnChange' => true),
'sql' => "char(1) NOT NULL default ''"
),
'popupContent' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['popupContent'],
'exclude' => true,
'inputType' => 'text',
'default' => true,
'eval' => array('mandatory' => true, 'rte' => 'tinyMCE', 'helpwizard' => true, 'tl_class' => 'clr'),
'explanation' => 'insertTags',
'sql' => "mediumtext NULL"
),
'customIcon' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['customIcon'],
'exclude' => true,
'inputType' => 'checkbox',
'default' => true,
'eval' => array('tl_class' => 'w50', 'submitOnChange' => true),
'sql' => "char(1) NOT NULL default ''"
),
'icon' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['icon'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => true,
'tl_class' => 'clr w50',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",
),
'retinaIcon' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['retinaIcon'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => false,
'tl_class' => 'w50',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",
),
'shadowImage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['shadowImage'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => false,
'tl_class' => 'clr w50',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",
),
'shadowRetinaImage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['shadowRetinaImage'],
'exclude' => true,
'inputType' => 'fileTree',
'eval' => array(
'filesOnly' => true,
'fieldType' => 'radio',
'mandatory' => false,
'tl_class' => 'w50',
'extensions' => 'gif,png,svg,jpg'
),
'sql' => "binary(16) NULL",
),
'draggable' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['draggable'],
'exclude' => true,
'inputType' => 'checkbox',
'default' => true,
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
),
'clickable' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['clickable'],
'exclude' => true,
'inputType' => 'checkbox',
'default' => true,
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
),
'keyboard' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['keyboard'],
'exclude' => true,
'inputType' => 'checkbox',
'default' => true,
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
),
'zIndexOffset' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['zIndexOffset'],
'exclude' => true,
'inputType' => 'text',
'default' => 0,
'eval' => array('mandatory' => true, 'maxlength' => 4, 'rgxp' => 'digit', 'tl_class' => 'clr w50'),
'sql' => "int(4) NOT NULL default '0'"
),
'iconAnchor' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['iconAnchor'],
'exclude' => true,
'inputType' => 'text',
'save_callback' => array(
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate')
),
'eval' => array(
'maxlength' => 255,
'tl_class' => 'w50',
'nullIfEmpty' => true,
),
'sql' => "varchar(255) NULL"
),
'shadowAnchor' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['shadowAnchor'],
'exclude' => true,
'inputType' => 'text',
'save_callback' => array(
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate')
),
'eval' => array(
'maxlength' => 255,
'tl_class' => 'w50',
'nullIfEmpty' => true,
),
'sql' => "varchar(255) NULL"
),
'popupAnchor' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['popupAnchor'],
'exclude' => true,
'inputType' => 'text',
'save_callback' => array(
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate')
),
'eval' => array(
'maxlength' => 255,
'tl_class' => 'w50',
'nullIfEmpty' => true,
),
'sql' => "varchar(255) NULL"
),
'iconClassName' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['iconClassName'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
'sql' => "varchar(255) NOT NULL default ''"
),
),
);

View File

View File

@@ -0,0 +1,6 @@
<?php
$GLOBALS['TL_LANG']['leaflet_layer']['provider'][0] = 'Leaflet provider';
$GLOBALS['TL_LANG']['leaflet_layer']['provider'][1] = 'Leaflet tile provider';
$GLOBALS['TL_LANG']['leaflet_layer']['group'][0] = 'Layer group';
$GLOBALS['TL_LANG']['leaflet_layer']['group'][1] = 'Layers group';

View File

@@ -0,0 +1,75 @@
<?php
$GLOBALS['TL_LANG']['tl_leaflet_control']['name_legend'] = 'Title and type';
$GLOBALS['TL_LANG']['tl_leaflet_control']['config_legend'] = 'Configuration';
$GLOBALS['TL_LANG']['tl_leaflet_control']['active_legend'] = 'Activation';
$GLOBALS['TL_LANG']['tl_leaflet_control']['new'][0] = 'Create control';
$GLOBALS['TL_LANG']['tl_leaflet_control']['new'][1] = 'Create new control';
$GLOBALS['TL_LANG']['tl_leaflet_control']['edit'][0] = 'Edit control';
$GLOBALS['TL_LANG']['tl_leaflet_control']['edit'][1] = 'Edit control ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_control']['copy'][0] = 'Copy control';
$GLOBALS['TL_LANG']['tl_leaflet_control']['copy'][1] = 'Copy control ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_control']['delete'][0] = 'Delete control';
$GLOBALS['TL_LANG']['tl_leaflet_control']['delete'][1] = 'Delete control ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_control']['toggle'][0] = 'Toggle activation';
$GLOBALS['TL_LANG']['tl_leaflet_control']['toggle'][1] = 'Toggle activation of control ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_control']['show'][0] = 'Show details';
$GLOBALS['TL_LANG']['tl_leaflet_control']['show'][1] = 'Show control ID %s details';
$GLOBALS['TL_LANG']['tl_leaflet_control']['pastenew'][0] = 'Copy control';
$GLOBALS['TL_LANG']['tl_leaflet_control']['pastenew'][1] = 'Create new copy of control ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_control']['title'][0] = 'Title';
$GLOBALS['TL_LANG']['tl_leaflet_control']['title'][1] = 'Title of the control.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['alias'][0] = 'Alias';
$GLOBALS['TL_LANG']['tl_leaflet_control']['alias'][1] = 'Alias of the control.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['type'][0] = 'Type';
$GLOBALS['TL_LANG']['tl_leaflet_control']['type'][1] = 'Choose the control type.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['position'][0] = 'Position';
$GLOBALS['TL_LANG']['tl_leaflet_control']['position'][1] = 'Position of the control.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomInText'][0] = 'Zoom in text';
$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomInText'][1] = 'The text set on the zoom in button. By default its the "+" sign. Leave empty for the default value';
$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomOutText'][0] = 'Zoom out text';
$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomOutText'][1] = 'The text set on the zoom out button. By default its the "-" sign. Leave empty for the default value';
$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomInTitle'][0] = 'Zoom in title';
$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomInTitle'][1] = 'The title set on the zoom in button.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomOutTitle'][0] = 'Zoom out title';
$GLOBALS['TL_LANG']['tl_leaflet_control']['zoomOutTitle'][1] = 'The title set on the zoom out button.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['active'][0] = 'Activate control';
$GLOBALS['TL_LANG']['tl_leaflet_control']['active'][1] = 'Activate control on the map.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['attributions'][0] = 'Attributions';
$GLOBALS['TL_LANG']['tl_leaflet_control']['attributions'][1] = 'Add attribution texts. HTML is allowed here.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['prefix'][0] = 'Attribution prefix';
$GLOBALS['TL_LANG']['tl_leaflet_control']['prefix'][1] = 'Customize the attribution prefix. By default it\'s the Leaflet link. HTML is allowed here.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['maxWidth'][0] = 'Max width';
$GLOBALS['TL_LANG']['tl_leaflet_control']['maxWidth'][1] = 'Maximum width of the control in pixels. The width is set dynamically to show round values (e.g. 100, 200, 500).';
$GLOBALS['TL_LANG']['tl_leaflet_control']['metric'][0] = 'Metric scale';
$GLOBALS['TL_LANG']['tl_leaflet_control']['metric'][1] = 'Whether to show the metric scale line (m/km).';
$GLOBALS['TL_LANG']['tl_leaflet_control']['imperial'][0] = 'Imperial scale';
$GLOBALS['TL_LANG']['tl_leaflet_control']['imperial'][1] = 'Whether to show the imperial scale line (mi/ft).';
$GLOBALS['TL_LANG']['tl_leaflet_control']['updateWhenIdle'][0] = 'Update when idle';
$GLOBALS['TL_LANG']['tl_leaflet_control']['updateWhenIdle'][1] = 'If true, the control is updated on moveend, otherwise it\'s always up-to-date (updated on move).';
$GLOBALS['TL_LANG']['tl_leaflet_control']['layers'][0] = 'Layers';
$GLOBALS['TL_LANG']['tl_leaflet_control']['layers'][1] = 'Add layers to the control.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['layer'][0] = 'Layer';
$GLOBALS['TL_LANG']['tl_leaflet_control']['layer'][1] = 'Choose a layer. Each layer can only be added once.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['layerMode'][0] = 'Mode';
$GLOBALS['TL_LANG']['tl_leaflet_control']['layerMode'][1] = 'Add layer as baselayer or overlay.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['collapsed'][0] = 'Collapsed';
$GLOBALS['TL_LANG']['tl_leaflet_control']['collapsed'][1] = 'If true, the control will be collapsed into an icon and expanded on mouse hover or touch.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['autoZIndex'][0] = 'Auto zIndex';
$GLOBALS['TL_LANG']['tl_leaflet_control']['autoZIndex'][1] = 'If true, the control will assign zIndexes in increasing order to all of its layers so that the order is preserved when switching them on/off.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['bottomleft'][0] = 'Bottom left';
$GLOBALS['TL_LANG']['tl_leaflet_control']['bottomleft'][1] = 'Bottom left of the map.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['topleft'][0] = 'Top left';
$GLOBALS['TL_LANG']['tl_leaflet_control']['topleft'][1] = 'Top left of the map.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['bottomright'][0] = 'Bottom right';
$GLOBALS['TL_LANG']['tl_leaflet_control']['bottomright'][1] = 'Bottom right of the map.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['topright'][0] = 'Top right';
$GLOBALS['TL_LANG']['tl_leaflet_control']['topright'][1] = 'Top right of the map.';
$GLOBALS['TL_LANG']['tl_leaflet_control']['base'][0] = 'Base layer';
$GLOBALS['TL_LANG']['tl_leaflet_control']['base'][1] = 'Base layers will be switched with radio buttons. Note that all base layers should be passed in the base layers object, but only one should be added to the map during map instantiation';
$GLOBALS['TL_LANG']['tl_leaflet_control']['overlay'][0] = 'Overlay';
$GLOBALS['TL_LANG']['tl_leaflet_control']['overlay'][1] = 'Overlays will be switched with checkboxes.';

View File

@@ -0,0 +1,36 @@
<?php
$GLOBALS['TL_LANG']['tl_leaflet_layer']['title_legend'] = 'Layer';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['active_legend'] = 'Activation';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['map'][0] = 'Manage maps';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['map'][1] = 'Manage leaflet maps';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['new'][0] = 'Create layer';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['new'][1] = 'Create new layer';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['edit'][0] = 'Edit layer';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['edit'][1] = 'Edit layer ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['copy'][0] = 'Copy layer';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['copy'][1] = 'Copy layer ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['delete'][0] = 'Delete layer';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['delete'][1] = 'Delete layer ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['toggle'][0] = 'Toggle activation';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['toggle'][1] = 'Toggle activation of layer ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['show'][0] = 'Show details';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['show'][1] = 'Show layer ID %s details';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['cut'][0] = 'Move layer';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['cut'][1] = 'Move layer ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['title'][0] = 'Title';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['title'][1] = 'Title of the layer.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['alias'][0] = 'Alias';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['alias'][1] = 'Alias of the layer.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['type'][0] = 'Type';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['type'][1] = 'Choose the layer type.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider'][0] = 'Tile provider';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider'][1] = 'Choose the layer type.';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider_variant'][0] = 'Tile variant';
$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']['markerCluster'][0] = 'Marker cluster';
$GLOBALS['TL_LANG']['tl_leaflet_layer']['markerCluster'][1] = 'Choose a marker cluster layer so that markers get clustered.';

View File

@@ -5,6 +5,7 @@ $GLOBALS['TL_LANG']['tl_leaflet_map']['interaction_legend'] = 'Interaction contr
$GLOBALS['TL_LANG']['tl_leaflet_map']['zoom_legend'] = 'Center and zoom';
$GLOBALS['TL_LANG']['tl_leaflet_map']['controls_legend'] = 'Control widgets';
$GLOBALS['TL_LANG']['tl_leaflet_map']['expert_legend'] = 'Expert settings';
$GLOBALS['TL_LANG']['tl_leaflet_map']['behaviour_legend'] = 'Behaviour';
$GLOBALS['TL_LANG']['tl_leaflet_map']['layersBtn'][0] = 'Manage layers';
$GLOBALS['TL_LANG']['tl_leaflet_map']['layersBtn'][1] = 'Manage leaflet layers';
@@ -14,6 +15,8 @@ $GLOBALS['TL_LANG']['tl_leaflet_map']['edit'][0] = 'Edit map';
$GLOBALS['TL_LANG']['tl_leaflet_map']['edit'][1] = 'Edit map ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_map']['copy'][0] = 'Copy map';
$GLOBALS['TL_LANG']['tl_leaflet_map']['copy'][1] = 'Copy map ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_map']['controls'][0] = 'Manage controls';
$GLOBALS['TL_LANG']['tl_leaflet_map']['controls'][1] = 'Manage controls of map ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_map']['delete'][0] = 'Delete map';
$GLOBALS['TL_LANG']['tl_leaflet_map']['delete'][1] = 'Delete map ID %s';
$GLOBALS['TL_LANG']['tl_leaflet_map']['show'][0] = 'Show details';

7
module/public/.htaccess Normal file
View File

@@ -0,0 +1,7 @@
<IfModule !mod_authz_core.c>
Order allow,deny
Allow from all
</IfModule>
<IfModule mod_authz_core.c>
Require all granted
</IfModule>

11
module/public/geojson.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
use Netzmacht\Contao\Leaflet\Controller\GeoJsonController;
define('TL_MODE', 'FE');
require(dirname(dirname(dirname(dirname($_SERVER['SCRIPT_FILENAME'])))) . '/initialize.php');
$container = $GLOBALS['container'];
$controller = new GeoJsonController($container['leaflet.map.service'], $container['input']);
echo $controller->execute();

View File

@@ -0,0 +1,41 @@
<?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\Controller;
use Netzmacht\Contao\Leaflet\MapService;
class GeoJsonController
{
/**
* @var MapService
*/
private $mapService;
/**
* @var \Input
*/
private $input;
public function __construct(MapService $mapService, \Input $input)
{
$this->mapService = $mapService;
$this->input = $input;
}
public function execute()
{
$collection = $this->mapService->getFeatureCollection(\Input::get('id'));
return json_encode($collection);
}
}

View File

@@ -12,6 +12,9 @@
namespace Netzmacht\Contao\Leaflet\Dca;
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
class Layer
{
private $layers;
@@ -19,7 +22,10 @@ class Layer
public function __construct()
{
$this->layers = &$GLOBALS['LEAFLET_LAYERS'];
\Controller::loadLanguageFile('leaflet_layer');
}
public function getVariants($dataContainer)
{
if ($dataContainer->activeRecord
@@ -32,6 +38,48 @@ class Layer
return array();
}
public function generateRow($row, $label)
{
$alt = empty($GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][0])
? $row['type']
: $GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][0];
$title = empty($GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][1])
? $row['type']
: $GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][1];
if (!empty($this->layers[$row['type']]['icon'])) {
$icon = \Image::getHtml($this->layers[$row['type']]['icon'], $alt, sprintf('title="%s"', $title));
} else {
$icon = \Image::getHtml('iconPLAIN.gif', $alt, sprintf('title="%s"', $title));
}
return $icon . ' ' . $label;
}
public function getMarkerClusterLayers()
{
$types = array_keys(
array_filter(
$GLOBALS['LEAFLET_LAYERS'],
function ($item) {
return !empty($item['markerCluster']);
}
)
);
$collection = LayerModel::findMultipleByTypes($types);
$builder = OptionsBuilder::fromCollection(
$collection,
'id',
function($row) {
return sprintf('%s [%s]', $row['title'], $row['type']);
}
);
return $builder->getOptions();
}
// Call paste_button_callback (&$dc, $row, $table, $cr, $childs, $previous, $next)
public function getPasteButtons($dataContainer, $row, $table, $whatever, $children)
{
@@ -76,4 +124,18 @@ class Layer
return $buffer;
}
public function generateMarkersButton($row, $href, $label, $title, $icon, $attributes)
{
if (empty($this->layers[$row['type']]['markers'])) {
return '';
}
return sprintf(
'<a href="%s" title="%s">%s</a> ',
\Backend::addToUrl($href . '&amp;id=' . $row['id']),
$title,
\Image::getHtml($icon, $label, $attributes)
);
}
}

View File

@@ -0,0 +1,22 @@
<?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\Dca;
class Marker
{
public function generateRow($row)
{
return $row['title'];
}
}

View File

@@ -12,6 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Event;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Symfony\Component\EventDispatcher\Event;
/**
@@ -37,16 +38,25 @@ class BuildDefinitionEvent extends Event
*/
private $model;
/**
* Optional bounds where elements should be in.
*
* @var LatLngBounds
*/
private $bounds;
/**
* Construct.
*
* @param Definition $definition The leaflet definition.
* @param \Model $model The definition model.
* @param Definition $definition The leaflet definition.
* @param \Model $model The definition model.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*/
public function __construct(Definition $definition, \Model $model)
public function __construct(Definition $definition, \Model $model, LatLngBounds $bounds = null)
{
$this->definition = $definition;
$this->model = $model;
$this->model = $model;
$this->bounds = $bounds;
}
/**
@@ -68,4 +78,14 @@ class BuildDefinitionEvent extends Event
{
return $this->model;
}
/**
* Get the bounds.
*
* @return LatLngBounds|null
*/
public function getBounds()
{
return $this->bounds;
}
}

View File

@@ -52,7 +52,7 @@ class LeafletMapElement extends \ContentElement
{
try {
$mapId = 'map_' . ($this->cssID[0] ?: $this->id);
$map = $this->mapService->getJavascript($this->leaflet_map, $mapId);
$map = $this->mapService->getJavascript($this->leaflet_map, null, $mapId);
$GLOBALS['TL_BODY'][] = '<script>' . $map .'</script>';

View File

@@ -13,9 +13,13 @@ namespace Netzmacht\Contao\Leaflet;
use Netzmacht\Contao\Leaflet\Event\GetJavascriptEvent;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\LeafletPHP\Assets;
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollectionAggregate;
use Netzmacht\LeafletPHP\Definition\Map;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Leaflet;
use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatcher;
@@ -61,16 +65,17 @@ class MapService
/**
* Get map definition.
*
* @param int $mapId The map database id.
* @param string $elementId Optional element id. If none given the mapId or alias is used.
* @param int $mapId The map database id.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
* @param string $elementId Optional element id. If none given the mapId or alias is used.
*
* @return Map
*/
public function getDefinition($mapId, $elementId = null)
public function getDefinition($mapId, LatLngBounds $bounds = null, $elementId = null)
{
$model = $this->getModel($mapId);
return $this->mapper->handle($model, $elementId);
return $this->mapper->handle($model, $bounds, $elementId);
}
/**
@@ -96,16 +101,15 @@ class MapService
/**
* Get map javascript.
*
* @param int $mapId The map id.
* @param string $elementId Optional element id. If none given the mapId or alias is used.
* @param int $mapId The map id.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
* @param string $elementId Optional element id. If none given the mapId or alias is used.
*
* @return string
*
* @throws \Exception If an error occurred in the process.
*/
public function getJavascript($mapId, $elementId = null)
public function getJavascript($mapId, LatLngBounds $bounds = null, $elementId = null)
{
$definition = $this->getDefinition($mapId, $elementId);
$definition = $this->getDefinition($mapId, $bounds, $elementId);
$assets = new ContaoAssets();
$javascript = $this->leaflet->build($definition, $assets);
@@ -114,4 +118,23 @@ class MapService
return $event->getJavascript();
}
/**
* Get feature collection of a layer.
*
* @param int $layerId The layer id.
* @param LatLngBounds $bounds Filter features in the bounds.
*
* @return FeatureCollection
*/
public function getFeatureCollection($layerId, LatLngBounds $bounds = null)
{
$model = LayerModel::findByPK($layerId);
if (!$model || !$model->active) {
throw new \InvalidArgumentException(sprintf('Could not find layer "%s"', $layerId));
}
return $this->mapper->handleGeoJson($model, $bounds);
}
}

View File

@@ -12,6 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Class AbstractBuilder.
@@ -148,13 +149,13 @@ abstract class AbstractMapper implements Mapper
/**
* {@inheritdoc}
*/
public function handle(\Model $model, DefinitionMapper $builder)
public function handle(\Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{
$definition = $this->createInstance($model, $builder);
$definition = $this->createInstance($model, $builder, $bounds);
$this->buildOptions($definition, $model);
$this->buildConditionals($definition, $model);
$this->doBuild($definition, $model, $builder);
$this->doBuild($definition, $model, $builder, $bounds);
return $definition;
}
@@ -182,14 +183,19 @@ abstract class AbstractMapper implements Mapper
/**
* Use for specific build methods.
*
* @param Definition $definition The definition being built.
* @param \Model $model The model.
* @param DefinitionMapper $builder The definition builder.
* @param Definition $definition The definition being built.
* @param \Model $model The model.
* @param DefinitionMapper $builder The definition builder.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return void
*/
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder)
{
protected function doBuild(
Definition $definition,
\Model $model,
DefinitionMapper $builder,
LatLngBounds $bounds = null
) {
}
/**
@@ -197,13 +203,14 @@ abstract class AbstractMapper implements Mapper
*
* @param \Model $model The model.
* @param DefinitionMapper $mapper The definition mapper.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return Definition
*/
protected function createInstance(\Model $model, DefinitionMapper $mapper)
protected function createInstance(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$reflector = new \ReflectionClass(static::$definitionClass);
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper));
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $bounds));
return $instance;
}
@@ -213,10 +220,11 @@ abstract class AbstractMapper implements Mapper
*
* @param \Model $model The model.
* @param DefinitionMapper $mapper The definition mapper.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return array
*/
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper)
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
return array(
$model->alias ?: (str_replace('tl_leaflet_', '', $model->getTable()) . '_' . $model->id)

View File

@@ -14,6 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Control\Attribution;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* AttributionControlMapper maps the the attribution database definition to the definition class.
@@ -49,7 +50,7 @@ class AttributionControlMapper extends AbstractControlMapper
/**
* {@inheritdoc}
*/
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder)
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{
if (!$definition instanceof Attribution) {
return;

View File

@@ -14,6 +14,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
class LayersControlMapper extends AbstractControlMapper
{
@@ -31,9 +32,9 @@ class LayersControlMapper extends AbstractControlMapper
*/
protected static $type = 'layers';
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper)
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$arguments = parent::buildConstructArguments($model, $mapper);
$arguments = parent::buildConstructArguments($model, $mapper, $bounds);
$arguments[1] = array();
$arguments[2] = array();
@@ -44,7 +45,7 @@ class LayersControlMapper extends AbstractControlMapper
foreach ($collection as $layer) {
$argument = ($definition[$layer->id] === 'overlay') ? 2 : 1;
$arguments[$argument][] = $mapper->handle($layer);
$arguments[$argument][] = $mapper->handle($layer, $bounds);
}
}

View File

@@ -13,6 +13,9 @@ namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\Contao\Leaflet\Event\BuildDefinitionEvent;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\GeoJson\Feature;
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatcher;
/**
@@ -70,6 +73,8 @@ class DefinitionMapper
{
$this->builders[$priority][] = $builder;
ksort($this->builders);
return $this;
}
@@ -86,12 +91,13 @@ class DefinitionMapper
/**
* Build a model.
*
* @param \Model $model The definition model.
* @param string $elementId Optional element id. If none given the mapId or alias is used.
* @param \Model $model The definition model.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
* @param string $elementId Optional element id. If none given the mapId or alias is used.
*
* @return Definition
*/
public function handle(\Model $model, $elementId = null)
public function handle(\Model $model, LatLngBounds $bounds = null, $elementId = null)
{
$hash = $model->getTable() . '.' . $model->{$model->getPk()};
@@ -99,16 +105,14 @@ class DefinitionMapper
return $this->mapped[$hash];
}
krsort($this->builders);
$this->mapId = $elementId ?: ($model->alias ?: ('map_' . $model->id));
foreach ($this->builders as $builders) {
foreach($builders as $builder) {
if ($builder->match($model)) {
$definition = $builder->handle($model, $this);
$definition = $builder->handle($model, $this, $bounds);
$event = new BuildDefinitionEvent($definition, $model);
$event = new BuildDefinitionEvent($definition, $model, $bounds);
$this->eventDispatcher->dispatch($event::NAME, $event);
$this->mapped[$hash] = $definition;
@@ -126,4 +130,43 @@ class DefinitionMapper
)
);
}
/**
* Build a model.
*
* @param \Model $model The definition model.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return FeatureCollection|Feature
*/
public function handleGeoJson(\Model $model, LatLngBounds $bounds = null)
{
foreach ($this->builders as $builders) {
foreach ($builders as $builder) {
if (!$builder->match($model)) {
continue;
}
if ($builder instanceof GeoJsonMapper) {
return $builder->handleGeoJson($model, $this, $bounds);
}
throw new \RuntimeException(
sprintf(
'Builder for model "%s::%s" is not a GeoJsonMapper',
$model->getTable(),
$model->{$model->getPk()}
)
);
}
}
throw new \RuntimeException(
sprintf(
'Could not build geo json of model "%s::%s". No matching builders found.',
$model->getTable(),
$model->{$model->getPk()}
)
);
}
}

View File

@@ -0,0 +1,26 @@
<?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;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
interface GeoJsonMapper
{
/**
* @param \Model $model
* @param DefinitionMapper $mapper
* @param LatLngBounds $bounds
*
* @return mixed
*/
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null);
}

View File

@@ -0,0 +1,24 @@
<?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\AbstractTypeMapper;
class AbstractLayerMapper extends AbstractTypeMapper
{
/**
* Class of the model being build.
*
* @var string
*/
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel';
}

View File

@@ -0,0 +1,90 @@
<?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\Mapper\GeoJsonMapper;
use Netzmacht\Contao\Leaflet\Model\MarkerModel;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\UI\Marker;
class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Group\GeoJson';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'markers';
protected function doBuild(
Definition $definition,
\Model $model,
DefinitionMapper $builder,
LatLngBounds $bounds = null
) {
if ($definition instanceof LayerGroup) {
$collection = MarkerModel::findBy(
array('active=1', 'pid=?'),
array($model->id)
);
if ($collection) {
foreach ($collection as $item) {
$marker = new Marker('marker_' . $item->id, $item->coordinates);
$marker->setTitle($item->tooltip);
$definition->addLayer($marker);
}
}
}
}
/**
* @param \Model $model
* @param DefinitionMapper $mapper
* @param LatLngBounds $bounds
*
* @return mixed
*/
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$feature = new FeatureCollection();
$collection = MarkerModel::findBy(
array('active=1', 'pid=?'),
array($model->id)
);
if ($collection) {
foreach ($collection as $item) {
$marker = new Marker('marker_' . $item->id, $item->coordinates);
$marker->setTitle($item->tooltip);
$feature->addFeature($marker->getFeature());
}
}
return $feature;
}
}

View File

@@ -11,20 +11,12 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
class ProviderLayerMapper extends AbstractTypeMapper
class ProviderLayerMapper extends AbstractLayerMapper
{
/**
* Class of the model being build.
*
* @var string
*/
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel';
/**
* Class of the definition being created.
*
@@ -61,7 +53,7 @@ class ProviderLayerMapper extends AbstractTypeMapper
/**
* {@inheritdoc}
*/
protected function createInstance(\Model $model, DefinitionMapper $mapper)
protected function createInstance(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
if (isset($this->providers[$model->tile_provider]['class'])) {
$class = $this->providers[$model->tile_provider]['class'];
@@ -70,7 +62,7 @@ class ProviderLayerMapper extends AbstractTypeMapper
}
$reflector = new \ReflectionClass($class);
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper));
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $bounds));
return $instance;
}
@@ -78,7 +70,7 @@ class ProviderLayerMapper extends AbstractTypeMapper
/**
* {@inheritdoc}
*/
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder)
protected function doBuild(Definition $definition, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{
if (!empty($this->providers[$model->tile_provider]['options'])) {
$this->applyOptions(
@@ -92,7 +84,7 @@ class ProviderLayerMapper extends AbstractTypeMapper
/**
* {@inheritdoc}
*/
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper)
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
return array(
$model->alias ?: ('layer_' . $model->id),

View File

@@ -16,6 +16,7 @@ use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Map;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Plugins\LeafletProviders\Provider;
class MapMapper extends AbstractMapper
@@ -50,19 +51,19 @@ class MapMapper extends AbstractMapper
/**
* @inheritdoc
*/
protected function doBuild(Definition $map, \Model $model, DefinitionMapper $builder)
protected function doBuild(Definition $map, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{
if ($map instanceof Map && $model instanceof MapModel) {
$this->buildCustomOptions($map, $model);
$this->buildControls($map, $model, $builder);
$this->buildLayers($map, $model, $builder);
$this->buildControls($map, $model, $builder, $bounds);
$this->buildLayers($map, $model, $builder, $bounds);
}
}
/**
* @inheritdoc
*/
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper)
protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
return array(
$mapper->getMapId(),
@@ -91,8 +92,9 @@ class MapMapper extends AbstractMapper
* @param Map $map The map being built.
* @param MapModel $model The map model.
* @param DefinitionMapper $mapper The definition mapper.
* @param LatLngBounds $bounds Optional bounds.
*/
private function buildControls(Map $map, MapModel$model, DefinitionMapper $mapper)
private function buildControls(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$collection = ControlModel::findBy(
array('pid=?', 'active=1'),
@@ -102,7 +104,7 @@ class MapMapper extends AbstractMapper
if ($collection) {
foreach ($collection as $control) {
$control = $mapper->handle($control);
$control = $mapper->handle($control, $bounds);
$map->addControl($control);
}
}
@@ -114,16 +116,22 @@ class MapMapper extends AbstractMapper
* @param Map $map The map being built.
* @param MapModel $model The map model.
* @param DefinitionMapper $mapper Definition mapper.
* @param LatLngBounds $bounds Optional bounds.
*/
private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper)
private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$ids = deserialize($model->layers, true);
$collection = LayerModel::findMultipleByIds($ids);
if ($collection) {
foreach ($collection as $layer) {
if (!$layer->active) {
continue;
}
$layer = $mapper->handle($layer, $bounds);
/** @var Provider $layer */
$layer = $mapper->handle($layer);
$map->addLayer($layer);
}
}

View File

@@ -12,21 +12,23 @@
namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
interface Mapper
{
/**
* Map model to the definition.
*
* @param \Model $model The model being built.
* @param DefinitionMapper $builder The definition builder.
* @param \Model $model The model being built.
* @param DefinitionMapper $mapper The definition builder.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return Definition
*/
public function handle(\Model $model, DefinitionMapper $builder);
public function handle(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null);
/**
* Check if builder is responsible for the model.
* Check if mapper is responsible for the model.
*
* @param \Model $model The model being build.
*

View File

@@ -16,4 +16,21 @@ class LayerModel extends \Model
{
protected static $strTable = 'tl_leaflet_layer';
public static function findMultipleByTypes(array $types, $options = array())
{
if (empty($types)) {
return null;
}
$options['column'] = array(
sprintf(
'type IN (%s)',
substr(str_repeat('?,', count($types)), 0, -1)
)
);
$options['value'] = $types;
return static::find($options);
}
}

View File

@@ -0,0 +1,19 @@
<?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\Model;
class MarkerModel extends \Model
{
protected static $strTable = 'tl_leaflet_marker';
}