Improve handling of bounds calculation. Layers have to whitelist, vectors/markers can set themselves to ignore.

This commit is contained in:
David Molineus
2015-01-21 18:21:28 +01:00
parent 5d1ccb1d54
commit b3eb4c8e61
12 changed files with 130 additions and 93 deletions

View File

@@ -87,6 +87,8 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper
$GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet-markercluster/MarkerCluster.Default.css||static';
}
$definition->setOption('affectBounds', (bool) $model->affectBounds);
$collection = LayerModel::findBy(
array('pid=?', 'active=1'),
array($model->id),

View File

@@ -66,9 +66,10 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
) {
if ($model->deferred) {
if ($model->pointToLayer) {
if ($model->pointToLayer || $model->affectBounds) {
$layer = new GeoJson($this->getElementId($model, $elementId));
$layer->setPointToLayer(new Expression($model->pointToLayer));
$layer->setOption('affectBounds', (bool) $model->affectBounds);
return array($this->getElementId($model, $elementId), RequestUrl::create($model->id), array(), $layer);
}
@@ -89,6 +90,8 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
LatLngBounds $bounds = null,
Definition $parent = null
) {
$definition->setOption('affectBounds', (bool) $model->affectBounds);
if ($definition instanceof GeoJson) {
$collection = $this->loadMarkerModels($model);
@@ -98,7 +101,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
if ($marker instanceof Marker) {
$feature = $marker->toGeoJsonFeature();
$feature->setProperty('affectBounds', ($item->affectBounds));
$feature->setProperty('ignoreForBounds', ($item->ignoreForBounds));
$definition->addData($feature, true);
}

View File

@@ -80,6 +80,10 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
$options['onEachFeature'] = new Expression($model->onEachFeature);
}
if ($model->affectBounds) {
$options['affectBounds'] = (bool) $model->affectBounds;
}
if (!empty($options)) {
$layer = new GeoJson($this->getElementId($model, $elementId));
$layer->setOptions($options);
@@ -105,6 +109,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
) {
if ($definition instanceof GeoJson) {
$collection = $this->loadVectorModels($model);
$definition->setOption('affectBounds', (bool) $model->affectBounds);
if ($collection) {
foreach ($collection as $item) {
@@ -114,7 +119,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
$feature = $vector->toGeoJsonFeature();
if ($feature instanceof Feature) {
$feature->setProperty('affectBounds', (bool) $item->affectBounds);
$feature->setProperty('ignoreForBounds', (bool) $item->ignoreForBounds);
}
$definition->addData($feature, true);
@@ -150,7 +155,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
if ($vector instanceof GeoJsonFeature) {
if ($vector instanceof Feature) {
$vector->setProperty('affectBounds', (bool) $item->affectBounds);
$vector->setProperty('ignoreForBounds', (bool) $item->ignoreForBounds);
}
$feature->addFeature($vector);