forked from Snck3rs/contao-leaflet-maps
Code style.
This commit is contained in:
@@ -142,6 +142,7 @@ class DefinitionMapper
|
|||||||
* @param mixed $model The corresponding definition model.
|
* @param mixed $model The corresponding definition model.
|
||||||
*
|
*
|
||||||
* @return GeoJsonFeature
|
* @return GeoJsonFeature
|
||||||
|
* @throws \RuntimeException If a definition type is not supported.
|
||||||
*/
|
*/
|
||||||
public function convertToGeoJsonFeature(Definition $definition, $model)
|
public function convertToGeoJsonFeature(Definition $definition, $model)
|
||||||
{
|
{
|
||||||
@@ -150,7 +151,12 @@ class DefinitionMapper
|
|||||||
} elseif ($definition instanceof ConvertsToGeoJsonFeature) {
|
} elseif ($definition instanceof ConvertsToGeoJsonFeature) {
|
||||||
$feature = $definition->toGeoJsonFeature();
|
$feature = $definition->toGeoJsonFeature();
|
||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException('Unsupported definition');
|
throw new \RuntimeException(
|
||||||
|
sprintf(
|
||||||
|
'Definition of class "%s" could not be converted to a geo json feature.',
|
||||||
|
get_class($definition)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$event = new ConvertToGeoJsonEvent($definition, $feature, $model);
|
$event = new ConvertToGeoJsonEvent($definition, $feature, $model);
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ use Netzmacht\LeafletPHP\Definition\Vector\Circle;
|
|||||||
use Netzmacht\LeafletPHP\Definition\Vector\CircleMarker;
|
use Netzmacht\LeafletPHP\Definition\Vector\CircleMarker;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class GeoJsonSubscriber provides subscribers when a definition is converted to a geo json feature.
|
||||||
|
*
|
||||||
|
* @package Netzmacht\Contao\Leaflet\Subscriber
|
||||||
|
*/
|
||||||
class GeoJsonSubscriber implements EventSubscriberInterface
|
class GeoJsonSubscriber implements EventSubscriberInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +70,11 @@ class GeoJsonSubscriber implements EventSubscriberInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ConvertToGeoJsonEvent $event
|
* Enrich marker with feature data and bounds information.
|
||||||
|
*
|
||||||
|
* @param ConvertToGeoJsonEvent $event The subscribed event.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function enrichMarker(ConvertToGeoJsonEvent $event)
|
public function enrichMarker(ConvertToGeoJsonEvent $event)
|
||||||
{
|
{
|
||||||
@@ -74,24 +83,17 @@ class GeoJsonSubscriber implements EventSubscriberInterface
|
|||||||
$model = $event->getModel();
|
$model = $event->getModel();
|
||||||
|
|
||||||
if ($definition instanceof Marker && $model instanceof MarkerModel && $feature instanceof Feature) {
|
if ($definition instanceof Marker && $model instanceof MarkerModel && $feature instanceof Feature) {
|
||||||
if ($model->featureData) {
|
$this->setDataProperty($model, $feature);
|
||||||
$feature->setProperty('data', json_decode($model->featureData, true));
|
$this->setBoundsInformation($model, $feature);
|
||||||
}
|
|
||||||
|
|
||||||
if ($model->ignoreForBounds) {
|
|
||||||
$feature->setProperty('ignoreForBounds', true);
|
|
||||||
} else {
|
|
||||||
$parent = LayerModel::findByPk($model->pid);
|
|
||||||
|
|
||||||
if ($parent && !$parent->affectBounds) {
|
|
||||||
$feature->setProperty('ignoreForBounds', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ConvertToGeoJsonEvent $event
|
* Enrich vector with feature data and bounds information.
|
||||||
|
*
|
||||||
|
* @param ConvertToGeoJsonEvent $event The subscribed event.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function enrichVector(ConvertToGeoJsonEvent $event)
|
public function enrichVector(ConvertToGeoJsonEvent $event)
|
||||||
{
|
{
|
||||||
@@ -100,19 +102,8 @@ class GeoJsonSubscriber implements EventSubscriberInterface
|
|||||||
$model = $event->getModel();
|
$model = $event->getModel();
|
||||||
|
|
||||||
if ($definition instanceof Vector && $model instanceof VectorModel && $feature instanceof Feature) {
|
if ($definition instanceof Vector && $model instanceof VectorModel && $feature instanceof Feature) {
|
||||||
if ($model->featureData) {
|
$this->setDataProperty($model, $feature);
|
||||||
$feature->setProperty('data', json_decode($model->featureData, true));
|
$this->setBoundsInformation($model, $feature);
|
||||||
}
|
|
||||||
|
|
||||||
if ($model->ignoreForBounds) {
|
|
||||||
$feature->setProperty('ignoreForBounds', true);
|
|
||||||
} else {
|
|
||||||
$parent = LayerModel::findByPk($model->pid);
|
|
||||||
|
|
||||||
if ($parent && !$parent->affectBounds) {
|
|
||||||
$feature->setProperty('ignoreForBounds', true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +111,7 @@ class GeoJsonSubscriber implements EventSubscriberInterface
|
|||||||
* Enrich the the circle with constructor arguments.
|
* Enrich the the circle with constructor arguments.
|
||||||
*
|
*
|
||||||
* @param ConvertToGeoJsonEvent $event The subscribed events.
|
* @param ConvertToGeoJsonEvent $event The subscribed events.
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function enrichCircle(ConvertToGeoJsonEvent $event)
|
public function enrichCircle(ConvertToGeoJsonEvent $event)
|
||||||
@@ -136,7 +128,9 @@ class GeoJsonSubscriber implements EventSubscriberInterface
|
|||||||
* Pass configured properties on an model to the properties.model key.
|
* Pass configured properties on an model to the properties.model key.
|
||||||
*
|
*
|
||||||
* @param ConvertToGeoJsonEvent $event The subscribed events.
|
* @param ConvertToGeoJsonEvent $event The subscribed events.
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
* @SuppressWarnings(PHPMD.Superglobals)
|
||||||
*/
|
*/
|
||||||
public function setModelData(ConvertToGeoJsonEvent $event)
|
public function setModelData(ConvertToGeoJsonEvent $event)
|
||||||
{
|
{
|
||||||
@@ -205,4 +199,40 @@ class GeoJsonSubscriber implements EventSubscriberInterface
|
|||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the bounds information.
|
||||||
|
*
|
||||||
|
* @param \Model $model The model.
|
||||||
|
* @param Feature $feature The feature.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function setBoundsInformation($model, $feature)
|
||||||
|
{
|
||||||
|
if ($model->ignoreForBounds) {
|
||||||
|
$feature->setProperty('ignoreForBounds', true);
|
||||||
|
} else {
|
||||||
|
$parent = LayerModel::findByPk($model->pid);
|
||||||
|
|
||||||
|
if ($parent && !$parent->affectBounds) {
|
||||||
|
$feature->setProperty('ignoreForBounds', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the data property.
|
||||||
|
*
|
||||||
|
* @param \Model $model The model.
|
||||||
|
* @param Feature $feature The feature.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function setDataProperty($model, $feature)
|
||||||
|
{
|
||||||
|
if ($model->featureData) {
|
||||||
|
$feature->setProperty('data', json_decode($model->featureData, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user