Files
contao-leaflet-maps/src/Netzmacht/Contao/Leaflet/Dca/Leaflet.php

97 lines
2.1 KiB
PHP
Raw Normal View History

2014-12-29 12:17:40 +01:00
<?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Dca;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\MapMapper;
2014-12-29 16:23:08 +01:00
use Netzmacht\Contao\Leaflet\Model\LayerModel;
2014-12-29 12:17:40 +01:00
use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
2015-01-12 19:03:29 +01:00
/**
* Class Leaflet is the base helper providing different methods.
*
* @package Netzmacht\Contao\Leaflet\Dca
*/
2014-12-29 12:17:40 +01:00
class Leaflet
{
/**
* Validate a coordinate.
*
2015-01-12 19:03:29 +01:00
* @param mixed $value The given value.
2014-12-29 12:17:40 +01:00
*
* @return mixed
*/
public function validateCoordinate($value)
{
if (!empty($value)) {
// Validate by creating latlng object. Throws an exception.
LatLng::fromString($value);
}
return $value;
}
2015-01-12 19:03:29 +01:00
/**
* Create the zoom range.
*
* @return array
*/
2014-12-29 12:17:40 +01:00
public function getZoomLevels()
{
return range(1, 20);
}
2015-01-12 19:03:29 +01:00
/**
* Get the geocoder wizard.
*
* @param \DataContainer $dataContainer The dataContainer driver.
*
* @return string
*/
2014-12-29 12:17:40 +01:00
public function getGeocoder($dataContainer)
{
2015-01-12 19:03:29 +01:00
$template = new \BackendTemplate('be_leaflet_geocode');
2014-12-29 12:17:40 +01:00
$template->field = 'ctrl_' . $dataContainer->field;
try {
2015-01-06 18:49:22 +01:00
$latLng = LatLng::fromString($dataContainer->value);
$template->marker = json_encode($latLng);
2015-01-12 19:03:29 +01:00
} catch (\Exception $e) {
// LatLng throws an exeption of value could not be created. Just let the value empty when.
2014-12-29 12:17:40 +01:00
}
return $template->parse();
}
2015-01-12 19:03:29 +01:00
/**
* Get all layers.
*
* @return array
*/
2014-12-29 16:23:08 +01:00
public function getLayers()
{
$options = array();
$collection = LayerModel::findBy('pid', '0', array('order' => 'title'));
if ($collection) {
foreach ($collection as $model) {
$options[$model->id] = $model->title;
}
}
return $options;
}
2014-12-29 12:17:40 +01:00
}