mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-01 20:43:52 +01:00
Implement as dynamic setting of the map bounds.
This commit is contained in:
@@ -96,7 +96,10 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
$marker = $mapper->handle($item);
|
||||
|
||||
if ($marker instanceof Marker) {
|
||||
$definition->addData($marker->toGeoJsonFeature(), true);
|
||||
$feature = $marker->toGeoJsonFeature();
|
||||
$feature->setProperty('affectBounds', ($item->affectBounds));
|
||||
|
||||
$definition->addData($feature, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use Netzmacht\Contao\Leaflet\Frontend\RequestUrl;
|
||||
use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\GeoJson\ConvertsToGeoJsonFeature;
|
||||
use Netzmacht\LeafletPHP\Definition\GeoJson\Feature;
|
||||
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
|
||||
use Netzmacht\LeafletPHP\Definition\GeoJson\GeoJsonFeature;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
|
||||
@@ -109,7 +110,13 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
$vector = $mapper->handle($item);
|
||||
|
||||
if ($vector instanceof ConvertsToGeoJsonFeature) {
|
||||
$definition->addData($vector->toGeoJsonFeature(), true);
|
||||
$feature = $vector->toGeoJsonFeature();
|
||||
|
||||
if ($feature instanceof Feature) {
|
||||
$feature->setProperty('affectBounds', (bool) $item->affectBounds);
|
||||
}
|
||||
|
||||
$definition->addData($feature, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,6 +148,10 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
}
|
||||
|
||||
if ($vector instanceof GeoJsonFeature) {
|
||||
if ($vector instanceof Feature) {
|
||||
$vector->setProperty('affectBounds', (bool) $item->affectBounds);
|
||||
}
|
||||
|
||||
$feature->addFeature($vector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ class MapMapper extends AbstractMapper
|
||||
$this->buildCustomOptions($map, $model);
|
||||
$this->buildControls($map, $model, $builder, $bounds);
|
||||
$this->buildLayers($map, $model, $builder, $bounds);
|
||||
$this->buildBoundsCalculation($map, $model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,4 +151,23 @@ class MapMapper extends AbstractMapper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build map bounds calculations.
|
||||
*
|
||||
* @param Map $map The map being built.
|
||||
* @param MapModel $model The map model.
|
||||
*/
|
||||
private function buildBoundsCalculation(Map $map, MapModel $model)
|
||||
{
|
||||
$adjustBounds = deserialize($model->adjustBounds, true);
|
||||
|
||||
if (in_array('deferred', $adjustBounds)) {
|
||||
$map->setOption('adjustBounds', true);
|
||||
}
|
||||
|
||||
if (in_array('load', $adjustBounds)) {
|
||||
$map->calculateFeatureBounds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user