mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-02 13:03:43 +01:00
Implement boundsMode fit.
This commit is contained in:
@@ -11,6 +11,10 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Filter\BboxFilter;
|
||||
use Netzmacht\Contao\Leaflet\Filter\Filter;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class MarkerModel for the tl_leaflet_marker table.
|
||||
*
|
||||
@@ -24,4 +28,53 @@ class MarkerModel extends AbstractActiveModel
|
||||
* @var string
|
||||
*/
|
||||
protected static $strTable = 'tl_leaflet_marker';
|
||||
|
||||
/**
|
||||
* @param $pid
|
||||
* @param Filter $filter
|
||||
*
|
||||
* @return \Model\Collection|null
|
||||
*/
|
||||
public static function findByFilter($pid, Filter $filter = null)
|
||||
{
|
||||
if (!$filter) {
|
||||
return MarkerModel::findActiveBy('pid', $pid, array('order' => 'sorting'));
|
||||
}
|
||||
|
||||
switch ($filter->getName()) {
|
||||
case 'bbox':
|
||||
return static::findByBBoxFilter($pid, $filter);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pid
|
||||
* @param BboxFilter $filter
|
||||
*
|
||||
* @return \Model\Collection|null
|
||||
*/
|
||||
public static function findByBBoxFilter($pid, BboxFilter $filter)
|
||||
{
|
||||
$columns = array(
|
||||
'active=1',
|
||||
'pid=?',
|
||||
'latitude > ? AND latitude < ?',
|
||||
'longitude > ? AND longitude < ?'
|
||||
);
|
||||
|
||||
/** @var LatLngBounds $bounds */
|
||||
$bounds = $filter->getValues()['bounds'];
|
||||
$values = array(
|
||||
$pid,
|
||||
$bounds->getSouthWest()->getLatitude(),
|
||||
$bounds->getNorthEast()->getLatitude(),
|
||||
$bounds->getSouthWest()->getLongitude(),
|
||||
$bounds->getNorthEast()->getLongitude()
|
||||
);
|
||||
|
||||
return static::findBy($columns, $values, array('order' => 'sorting'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user