mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-30 20:13:49 +01:00
Implement user locate.
This commit is contained in:
@@ -13,6 +13,8 @@ namespace Netzmacht\Contao\Leaflet\Mapper;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Model\ControlModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
use Netzmacht\JavascriptBuilder\Type\AnonymousFunction;
|
||||
use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Control;
|
||||
use Netzmacht\LeafletPHP\Definition\Layer;
|
||||
@@ -68,6 +70,7 @@ class MapMapper extends AbstractMapper
|
||||
$this->buildControls($map, $model, $mapper, $bounds);
|
||||
$this->buildLayers($map, $model, $mapper, $bounds);
|
||||
$this->buildBoundsCalculation($map, $model);
|
||||
$this->buildLocate($map, $model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,4 +179,46 @@ class MapMapper extends AbstractMapper
|
||||
$map->calculateFeatureBounds();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build map bounds calculations.
|
||||
*
|
||||
* @param Map $map The map being built.
|
||||
* @param MapModel $model The map model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function buildLocate(Map $map, MapModel $model)
|
||||
{
|
||||
if ($model->locate) {
|
||||
$options = array();
|
||||
|
||||
$mapping = array(
|
||||
'setView' => 'locateSetView',
|
||||
'watch' => 'locateWatch',
|
||||
'enableHighAccuracy' => 'enableHighAccuracy',
|
||||
);
|
||||
|
||||
foreach ($mapping as $option => $property) {
|
||||
if ($model->$property) {
|
||||
$options[$option] = (bool) $model->$property;
|
||||
}
|
||||
}
|
||||
|
||||
$mapping = array(
|
||||
'maxZoom' => 'locateMaxZoom',
|
||||
'timeout' => 'locateTimeout',
|
||||
'maximumAge' => 'locateMaximumAge',
|
||||
);
|
||||
|
||||
foreach ($mapping as $option => $property) {
|
||||
if ($model->$property) {
|
||||
$options[$option] = (int) $model->$property;
|
||||
}
|
||||
}
|
||||
|
||||
$map->locate($options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ use Model\Collection;
|
||||
/**
|
||||
* Class MapModel for the tl_leaflet_map table.
|
||||
*
|
||||
* @property mixed|null locate
|
||||
* @package Netzmacht\Contao\Leaflet\Model
|
||||
*/
|
||||
class MapModel extends \Model
|
||||
|
||||
Reference in New Issue
Block a user