Work on vectors integration.

This commit is contained in:
David Molineus
2015-01-07 17:59:56 +01:00
parent 84d29b07ec
commit d9f12eff2d
14 changed files with 988 additions and 10 deletions

View File

@@ -0,0 +1,21 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Dca;
class Vector
{
public function generateRow($row)
{
return sprintf('%s <span class="tl_gray">[%s]</span>', $row['title'], $row['type']);
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper;
use Netzmacht\Contao\Leaflet\Model\MarkerModel;
use Netzmacht\Contao\Leaflet\Model\VectorModel;
use Netzmacht\Contao\Leaflet\Request\RequestUrl;
use Netzmacht\Javascript\Type\Value\Reference;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\GeoJson\FeatureCollection;
use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax;
class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Group\GeoJson';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'vectors';
/**
* {@inheritdoc}
*/
protected function createInstance(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
if ($model->deferred) {
$reflector = new \ReflectionClass('Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax');
$instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $bounds));
return $instance;
}
return parent::createInstance($model, $mapper, $bounds);
}
/**
* {@inheritdoc}
*/
protected function doBuild(
Definition $definition,
\Model $model,
DefinitionMapper $mapper,
LatLngBounds $bounds = null
) {
if ($definition instanceof GeoJsonAjax) {
$definition->setUrl(RequestUrl::create($model->id));
} elseif ($definition instanceof LayerGroup) {
$collection = $this->loadVectorModels($model);
if ($collection) {
foreach ($collection as $item) {
$definition->addLayer($mapper->handle($item));
}
}
}
if ($definition instanceof GeoJson) {
$definition->setOnEachFeature(new Reference('ContaoLeaflet.onEachFeature', 'ContaoLeaflet'));
$definition->setPointToLayer(new Reference('ContaoLeaflet.pointToLayer', 'ContaoLeaflet'));
}
}
/**
* @param \Model $model
* @param DefinitionMapper $mapper
* @param LatLngBounds $bounds
*
* @return mixed
*/
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
$feature = new FeatureCollection();
$collection = $this->loadVectorModels($model);
if ($collection) {
foreach ($collection as $item) {
$feature->addFeature($mapper->handle($item)->toGeoJson());
}
}
return $feature;
}
/**
* @param \Model $model
*
* @return \Model\Collection|null
*/
protected function loadVectorModels(\Model $model)
{
$collection = VectorModel::findBy(
array('active=1', 'pid=?'),
array($model->id),
array('order' => 'sorting')
);
return $collection;
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Path;
class AbstractVectorMapper extends AbstractTypeMapper
{
/**
* Class of the model being build.
*
* @var string
*/
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\VectorModel';
protected function initialize()
{
parent::initialize();
$this
->addOptions('stroke', 'weight', 'opacity', 'clickable', 'className')
->addConditionalOption('color')
->addConditionalOption('lineCap')
->addConditionalOption('lineJoin')
->addConditionalOption('dashArray')
->addConditionalOptions('fill', array('fill', 'fillColor', 'fillOpacity'))
;
}
protected function doBuild(
Definition $definition,
\Model $model,
DefinitionMapper $builder,
LatLngBounds $bounds = null
) {
parent::doBuild($definition, $model, $builder, $bounds);
if ($definition instanceof Path) {
if ($model->addPopup) {
$definition->bindPopup($model->popupContent);
}
}
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Circle;
class CircleMapper extends AbstractVectorMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Circle';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'circle';
protected function initialize()
{
parent::initialize();
$this->addOption('radius');
}
protected function doBuild(
Definition $definition,
\Model $model,
DefinitionMapper $builder,
LatLngBounds $bounds = null
) {
parent::doBuild($definition, $model, $builder, $bounds);
if ($definition instanceof Circle) {
$definition->setLatLng(LatLng::fromString($model->coordinates));
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Circle;
class CircleMarkerMapper extends CircleMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\CircleMarker';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'circleMarker';
}

View File

@@ -0,0 +1,60 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\MultiPolygon;
class MultiPolygonMapper extends MultiPolylineMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\MultiPolygon';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'multiPolygon';
protected function doBuild(
Definition $definition,
\Model $model,
DefinitionMapper $builder,
LatLngBounds $bounds = null
) {
parent::doBuild($definition, $model, $builder, $bounds);
if ($definition instanceof MultiPolygon) {
$latLngs = array();
foreach (deserialize($model->multiData, true) as $data) {
$latLngs[] = array_map(
function ($row) {
return LatLng::fromString($row);
},
explode("\n", $data)
);
}
$definition->setLatLngs($latLngs);
}
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\MultiPolyline;
use Netzmacht\LeafletPHP\Definition\Vector\Polyline;
class MultiPolylineMapper extends AbstractVectorMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\MultiPolyline';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'multiPolyline';
protected function doBuild(
Definition $definition,
\Model $model,
DefinitionMapper $builder,
LatLngBounds $bounds = null
) {
parent::doBuild($definition, $model, $builder, $bounds);
if ($definition instanceof MultiPolyline) {
$latLngs = array();
foreach (deserialize($model->multiData, true) as $data) {
$latLngs[] = array_map(
function ($row) {
return LatLng::fromString($row);
},
explode("\n", $data)
);
}
$definition->setLatLngs($latLngs);
}
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
class PolygonMapper extends PolylineMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Polygon';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'polygon';
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Polyline;
class PolylineMapper extends AbstractVectorMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Vector\Polyline';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'polyline';
protected function doBuild(
Definition $definition,
\Model $model,
DefinitionMapper $builder,
LatLngBounds $bounds = null
) {
parent::doBuild($definition, $model, $builder, $bounds);
if ($definition instanceof Polyline) {
array_map(
function ($row) use ($definition) {
$definition->addLatLng(LatLng::fromString($row));
},
explode("\n", $model->data)
);
}
}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2015 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Model;
class VectorModel extends \Model
{
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_vector';
}