Implement caching for feature collections (#30) and maps (#4).

This commit is contained in:
David Molineus
2016-10-06 15:47:33 +02:00
parent 2e5139a756
commit 8c24f5e735
16 changed files with 398 additions and 75 deletions

View File

@@ -100,7 +100,7 @@ $GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\VectorsLa
$GLOBALS['LEAFLET_MAPPERS'][] = 'Netzmacht\Contao\Leaflet\Mapper\Layer\ReferenceLayerMapper';
$GLOBALS['LEAFLET_MAPPERS'][] = function () {
return new \Netzmacht\Contao\Leaflet\Mapper\Layer\MarkerClusterLayerMapper(
$GLOBALS['container'][\Netzmacht\Contao\Toolkit\DependencyInjection\Services::ASSETS_MANAGER]
$GLOBALS['container'][\Netzmacht\Contao\Leaflet\DependencyInjection\LeafletServices::MAP_ASSETS]
);
};

View File

@@ -9,6 +9,8 @@
*
*/
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\FilesystemCache;
use Interop\Container\ContainerInterface;
use Netzmacht\Contao\Leaflet\Alias\DefaultAliasFilter;
use Netzmacht\Contao\Leaflet\Boot;
@@ -16,6 +18,7 @@ use Netzmacht\Contao\Leaflet\ContaoAssets;
use Netzmacht\Contao\Leaflet\Dca\ControlCallbacks;
use Netzmacht\Contao\Leaflet\Dca\FrontendIntegration;
use Netzmacht\Contao\Leaflet\Dca\LayerCallbacks;
use Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks;
use Netzmacht\Contao\Leaflet\Dca\MapCallbacks;
use Netzmacht\Contao\Leaflet\Dca\Validator;
use Netzmacht\Contao\Leaflet\Dca\VectorCallbacks;
@@ -56,6 +59,7 @@ $container[LeafletServices::MAP_PROVIDER] = $container->share(function ($contain
$container[Services::EVENT_DISPATCHER],
$container[Services::INPUT],
$container[LeafletServices::MAP_ASSETS],
$container[LeafletServices::CACHE],
$GLOBALS['LEAFLET_FILTERS'],
\Config::get('debugMode') || \Config::get('displayErrors')
);
@@ -77,7 +81,7 @@ $container[LeafletServices::BOOT] = $container->share(function ($container) {
$container['leaflet.boot.subscriber'] = $container->share(function ($container) {
return new BootSubscriber(
$container[Services::ASSETS_MANAGER],
$container[LeafletServices::MAP_ASSETS],
$GLOBALS['LEAFLET_MAPPERS'],
$GLOBALS['LEAFLET_ENCODERS'],
$GLOBALS['LEAFLET_LIBRARIES']
@@ -144,6 +148,21 @@ $container[LeafletServices::FRONTEND_VALUE_FILTER] = $container->share(function(
return new ValueFilter($container[Services::INSERT_TAG_REPLACER]);
});
/**
* Internal used leaflet cache.
*
* @var Cache
*/
$container[LeafletServices::CACHE] = $container->share(
function ($container) {
if ($container[Services::PRODUCTION_MODE]) {
return new FilesystemCache(TL_ROOT . '/system/cache/leaflet');
} else {
return new ArrayCache();
}
}
);
/**
* Leaflet alias generator.
*
@@ -266,6 +285,19 @@ $container['leaflet.dca.frontend-integration'] = $container->share(
}
);
/**
* Common callback helpers.
*
* @return LeafletCallbacks
*/
$container['leaflet.dca.common'] = $container->share(
function ($container) {
return new LeafletCallbacks(
$container[Services::FILE_SYSTEM]
);
}
);
/**
* Validator helper class.
*

View File

@@ -23,7 +23,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
'id' => 'primary',
'pid' => 'index',
)
)
),
'onsubmit_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
// List
@@ -211,7 +214,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_control'] = array
'inputType' => 'checkbox',
'filter' => true,
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
'sql' => "char(1) NOT NULL default ''",
'save_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'zoomInText' => array
(

View File

@@ -21,7 +21,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
'id' => 'primary',
'alias' => 'unique',
)
)
),
'onsubmit_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'list' => array
@@ -207,7 +210,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
'sql' => "char(1) NOT NULL default ''",
'save_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'iconImage' => array
(

View File

@@ -31,7 +31,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
function() {
\Controller::loadLanguageFile('leaflet');
}
)
),
'onsubmit_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'list' => array
(
@@ -150,7 +153,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'default' => array(
'title' => array('title', 'alias', 'type'),
'config' => array(),
'expert' => array(':hide'),
'expert' => array(':hide', 'cache'),
'active' => array('active'),
),
'markers extends default' => array(
@@ -224,7 +227,8 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
),
'metasubpalettes' => array(
'spiderfyOnMaxZoom' => array('spiderfyDistanceMultiplier')
'spiderfyOnMaxZoom' => array('spiderfyDistanceMultiplier'),
'cache' => array('cacheLifeTime')
),
'fields' => array
@@ -297,7 +301,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'inputType' => 'checkbox',
'filter' => true,
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
'sql' => "char(1) NOT NULL default ''",
'save_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'tile_provider' => array(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['tile_provider'],
@@ -468,7 +475,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['disableClusteringAtZoom'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'),
'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'),
'default' => '',
'eval' => array(
'maxlength' => 4,
@@ -566,7 +573,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['minZoom'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'),
'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'),
'eval' => array(
'maxlength' => 4,
'rgxp' => 'digit',
@@ -581,7 +588,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['maxZoom'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'),
'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'),
'eval' => array(
'maxlength' => 4,
'rgxp' => 'digit',
@@ -596,7 +603,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['maxNativeZoom'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'),
'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'),
'eval' => array(
'maxlength' => 4,
'rgxp' => 'digit',
@@ -757,5 +764,23 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
),
'sql' => "mediumblob NULL"
),
'cache' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['cache'],
'exclude' => true,
'inputType' => 'checkbox',
'default' => false,
'eval' => array('tl_class' => 'w50 m12', 'submitOnChange' => true),
'sql' => "char(1) NOT NULL default ''"
),
'cacheLifeTime' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['cacheLifeTime'],
'exclude' => true,
'inputType' => 'text',
'default' => null,
'eval' => array('maxlength' => 5, 'rgxp' => 'digit', 'tl_class' => 'w50', 'nullIfEmpty' => true),
'sql' => "int(9) NOT NULL default '0'"
),
)
);

View File

@@ -27,7 +27,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
function() {
\Controller::loadLanguageFile('leaflet');
}
)
),
'onsubmit_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'list' => array
@@ -114,6 +117,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
),
'expert' => array(
'options',
'cache',
)
),
),
@@ -135,6 +139,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
'locateMaximumAge',
'enableHighAccuracy'
),
'cache' => array(
'cacheLifeTime'
)
),
'fields' => array
@@ -183,7 +190,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
\Netzmacht\Contao\Leaflet\Dca\Validator::callback('validateCoordinates'),
),
'wizard' => array(
array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getGeocoder')
Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getGeocoder')
),
'eval' => array(
'maxlength' => 255,
@@ -232,7 +239,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['zoom'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'),
'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'),
'default' => '',
'eval' => array(
'maxlength' => 4,
@@ -257,7 +264,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['minZoom'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'),
'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'),
'eval' => array(
'maxlength' => 4,
'rgxp' => 'digit',
@@ -272,7 +279,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['maxZoom'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'),
'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'),
'eval' => array(
'maxlength' => 4,
'rgxp' => 'digit',
@@ -503,7 +510,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['locateMaxZoom'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getZoomLevels'),
'options_callback' => Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getZoomLevels'),
'eval' => array(
'maxlength' => 4,
'rgxp' => 'digit',
@@ -513,5 +520,23 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
),
'sql' => "int(4) NULL"
),
'cache' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['cache'],
'exclude' => true,
'inputType' => 'checkbox',
'default' => false,
'eval' => array('tl_class' => 'w50 m12', 'submitOnChange' => true),
'sql' => "char(1) NOT NULL default ''"
),
'cacheLifeTime' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_map']['cacheLifeTime'],
'exclude' => true,
'inputType' => 'text',
'default' => null,
'eval' => array('maxlength' => 5, 'rgxp' => 'digit', 'tl_class' => 'w50', 'nullIfEmpty' => true),
'sql' => "int(9) NOT NULL default '0'"
),
),
);

View File

@@ -28,7 +28,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
function() {
\Controller::loadLanguageFile('leaflet');
}
)
),
'onsubmit_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'list' => array
@@ -196,7 +199,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'loadCoordinates')
),
'wizard' => array(
array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getGeocoder')
Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getGeocoder')
),
'eval' => array(
'maxlength' => 255,
@@ -238,7 +241,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
'flag' => 12,
'inputType' => 'checkbox',
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
'sql' => "char(1) NOT NULL default ''",
'save_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'tooltip' => array
(

View File

@@ -21,7 +21,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_popup'] = array
'id' => 'primary',
'alias' => 'unique',
)
)
),
'onsubmit_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'list' => array
@@ -290,7 +293,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_popup'] = array
'search' => false,
'flag' => 12,
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
'sql' => "char(1) NOT NULL default ''",
'save_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
),
);

View File

@@ -20,7 +20,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array
'id' => 'primary',
'alias' => 'unique',
)
)
),
'onsubmit_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'list' => array
@@ -292,7 +295,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_style'] = array
'search' => false,
'flag' => 12,
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
'sql' => "char(1) NOT NULL default ''",
'save_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
),
);

View File

@@ -28,7 +28,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array
function() {
\Controller::loadLanguageFile('leaflet');
}
)
),
'onsubmit_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'list' => array
@@ -240,7 +243,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array
'search' => false,
'flag' => 12,
'eval' => array('tl_class' => 'w50'),
'sql' => "char(1) NOT NULL default ''"
'sql' => "char(1) NOT NULL default ''",
'save_callback' => [
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
],
),
'addPopup' => array
(
@@ -314,7 +320,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array
\Netzmacht\Contao\Leaflet\Dca\Validator::callback('validateCoordinates')
),
'wizard' => array(
array('Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks', 'getGeocoder')
Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getGeocoder')
),
'eval' => array(
'maxlength' => 255,