mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-30 03:54:10 +01:00
Add loading indicator.
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
|
||||
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\Leaflet\Model\ControlModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
|
||||
class Control
|
||||
@@ -38,4 +40,11 @@ class Control
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getZoomControls()
|
||||
{
|
||||
$collection = ControlModel::findBy('type', 'zoom', array('order' => 'title'));
|
||||
|
||||
return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
<?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\Control;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\ControlModel;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Control\Zoom;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Plugins\Loading\LoadingControl;
|
||||
use Netzmacht\LeafletPHP\Plugins\Loading\SpinJsLoadingControl;
|
||||
|
||||
class LoadingControlMapper extends AbstractControlMapper
|
||||
{
|
||||
/**
|
||||
* Class of the definition being created.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $definitionClass = 'Netzmacht\LeafletPHP\Plugins\Loading\LoadingControl';
|
||||
|
||||
/**
|
||||
* Layer type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $type = 'loading';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getClassName(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
{
|
||||
if ($model->spinjs) {
|
||||
return 'Netzmacht\LeafletPHP\Plugins\Loading\SpinJsLoadingControl';
|
||||
}
|
||||
|
||||
return parent::getClassName($model, $mapper, $bounds);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
$this->addOption('separate');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
LatLngBounds $bounds = null
|
||||
) {
|
||||
parent::build($definition, $model, $mapper, $bounds);
|
||||
|
||||
if ($definition instanceof SpinJsLoadingControl && $model->spin) {
|
||||
$config = json_decode($model->spin, true);
|
||||
|
||||
if (is_array($config)) {
|
||||
$definition->setSpin($config);
|
||||
}
|
||||
}
|
||||
|
||||
if ($definition instanceof LoadingControl && !$definition->isSeparate() && $model->zoomControl ) {
|
||||
// Only assign if zoom control is activated and part of the map.
|
||||
$control = ControlModel::findOneBy(
|
||||
array('active=1', 'type=?', 'pid=?', 'id=?'),
|
||||
array('zoom', $model->pid, $model->zoomControl)
|
||||
);
|
||||
|
||||
if ($control) {
|
||||
$control = $mapper->handle($control);
|
||||
|
||||
if ($control instanceof Zoom) {
|
||||
// By default the loading control overrides the position of the zoom control. Deactivate it by
|
||||
// overriding the position.
|
||||
$definition->setPosition($control->getPosition());
|
||||
$definition->setZoomControl($control);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user