diff --git a/src/Netzmacht/Contao/Leaflet/Filter/BboxFilter.php b/src/Netzmacht/Contao/Leaflet/Filter/BboxFilter.php new file mode 100644 index 0000000..2f76a5d --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Filter/BboxFilter.php @@ -0,0 +1,72 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Filter; + +use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; + +/** + * The Bounds box filter. + * + * @package Netzmacht\Contao\Leaflet\Filter + */ +class BboxFilter implements Filter +{ + /** + * The bounds. + * + * @var LatLngBounds + */ + private $bounds; + + /** + * Construct. + * + * @param LatLngBounds $bounds The bounds. + */ + public function __construct(LatLngBounds $bounds) + { + + $this->bounds = $bounds; + } + + /** + * {@inheritdoc} + */ + public static function getName() + { + return 'bbox'; + } + + /** + * {@inheritdoc} + */ + public static function fromRequest($request) + { + return new static(LatLngBounds::fromString($request)); + } + + /** + * {@inheritdoc} + */ + public function toRequest() + { + return $this->bounds->toString(true); + } + + /** + * {@inheritdoc} + */ + public function getValues() + { + return array('bounds' => $this->bounds); + } +} diff --git a/src/Netzmacht/Contao/Leaflet/Filter/DistanceFilter.php b/src/Netzmacht/Contao/Leaflet/Filter/DistanceFilter.php new file mode 100644 index 0000000..1e06706 --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Filter/DistanceFilter.php @@ -0,0 +1,95 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Filter; + +use Netzmacht\LeafletPHP\Definition\Type\LatLng; + +/** + * Class DistanceFilter filters by a coordinate the the distance from it. + * + * @package Netzmacht\Contao\Leaflet\Filter + */ +class DistanceFilter implements Filter +{ + /** + * The center coordinates. + * + * @var LatLng + */ + private $center; + + /** + * The radius in meters. + * + * @var int + */ + private $radius; + + /** + * Construct. + * + * @param LatLng $center The center coordinates. + * @param int $radius The radius in meters. + */ + public function __construct(LatLng $center, $radius) + { + $this->center = $center; + $this->radius = (int) $radius; + } + + + /** + * {@inheritdoc} + */ + public static function getName() + { + return 'distance'; + } + + /** + * {@inheritdoc} + * + * @throws \InvalidArgumentException If the value could not be parsed. + */ + public static function fromRequest($request) + { + $values = explode(',', $request, 3); + + if (count($values) !== 3) { + throw new \InvalidArgumentException(sprintf('Invalid request value "%s"', $request)); + } + + return new static( + new LatLng($values[0], $values[1]), + $values[2] + ); + } + + /** + * {@inheritdoc} + */ + public function toRequest() + { + return $this->center->toString(true) . ',' . $this->radius; + } + + /** + * {@inheritdoc} + */ + public function getValues() + { + return array( + 'radius' => $this->radius, + 'center' => $this->center + ); + } +} diff --git a/src/Netzmacht/Contao/Leaflet/Filter/Filter.php b/src/Netzmacht/Contao/Leaflet/Filter/Filter.php new file mode 100644 index 0000000..4f3b89e --- /dev/null +++ b/src/Netzmacht/Contao/Leaflet/Filter/Filter.php @@ -0,0 +1,52 @@ + + * @copyright 2015 netzmacht creative David Molineus + * @license LGPL 3.0 + * @filesource + * + */ + +namespace Netzmacht\Contao\Leaflet\Filter; + +/** + * Interface Filter is designed for filter a data request. It just contains the filter information. + * + * Each layer has it own responsibility to apply the filter to their provided data. + * + * @package Netzmacht\Contao\Leaflet\Filter + */ +interface Filter +{ + /** + * Get the name of the filter. + * + * @return string + */ + public static function getName(); + + /** + * Create the filter from a request string. + * + * @param string $request The request. + * + * @return Filter + */ + public static function fromRequest($request); + + /** + * Create request string representation. + * + * @return string + */ + public function toRequest(); + + /** + * Get the param values. + * + * @return array + */ + public function getValues(); +}