mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-28 19:13:55 +01:00
Support geojson and topojson as file types for the file layer.
This commit is contained in:
@@ -38,6 +38,13 @@ parameters:
|
||||
- 'circle'
|
||||
- 'circleMarker'
|
||||
|
||||
netzmacht.contao_leaflet.file_formats:
|
||||
gpx: ['gpx']
|
||||
kml: ['kml']
|
||||
wkt: ['wkt']
|
||||
geojson: ['json', 'geojson']
|
||||
topojson: ['json', 'topojson']
|
||||
|
||||
# When creating a GeoJSON feature of a map object a feature.properties.model object is passed.
|
||||
# Define the properties you always want to set.
|
||||
#
|
||||
|
||||
@@ -39,6 +39,7 @@ services:
|
||||
- '%netzmacht.contao_leaflet.layers%'
|
||||
- '%netzmacht.contao_leaflet.providers%'
|
||||
- '%netzmacht.contao_leaflet.amenities%'
|
||||
- '%netzmacht.contao_leaflet.file_formats%'
|
||||
|
||||
netzmacht.contao_leaflet.listeners.dca.marker:
|
||||
class: Netzmacht\Contao\Leaflet\Listener\Dca\MarkerDcaListener
|
||||
|
||||
@@ -49,6 +49,10 @@ array_insert(
|
||||
]
|
||||
);
|
||||
|
||||
if (TL_MODE === 'BE') {
|
||||
$GLOBALS['TL_CSS'][] = 'bundles/netzmachtcontaoleaflet/css/backend_hacks.css';
|
||||
}
|
||||
|
||||
/*
|
||||
* Models.
|
||||
*/
|
||||
|
||||
@@ -219,7 +219,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [
|
||||
],
|
||||
|
||||
'file extends default' => [
|
||||
'+config' => ['file', 'boundsMode'],
|
||||
'+config' => ['boundsMode', 'fileFormat'],
|
||||
'+expert' => [
|
||||
'onEachFeature',
|
||||
'pointToLayer',
|
||||
@@ -235,6 +235,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [
|
||||
'MapBox' => ['tile_provider_key'],
|
||||
'HERE' => ['tile_provider_key', 'tile_provider_code'],
|
||||
],
|
||||
'fileFormat' => [
|
||||
'!' => ['file']
|
||||
]
|
||||
],
|
||||
|
||||
'metasubpalettes' => [
|
||||
@@ -861,15 +864,34 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [
|
||||
],
|
||||
'sql' => 'mediumtext NULL',
|
||||
],
|
||||
'fileFormat' => [
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormat'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'select',
|
||||
'filter' => true,
|
||||
'eval' => [
|
||||
'mandatory' => true,
|
||||
'tl_class' => 'w50',
|
||||
'includeBlankOption' => true,
|
||||
'submitOnChange' => true,
|
||||
'chosen' => true,
|
||||
'helpwizard' => true,
|
||||
],
|
||||
'options_callback' => ['netzmacht.contao_leaflet.listeners.dca.layer', 'getFileFormats'],
|
||||
'reference' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormats'],
|
||||
'sql' => "varchar(32) NOT NULL default ''",
|
||||
],
|
||||
'file' => [
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['file'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'fileTree',
|
||||
'load_callback' => [
|
||||
['netzmacht.contao_leaflet.listeners.dca.layer', 'prepareFileWidget'],
|
||||
],
|
||||
'eval' => [
|
||||
'filesOnly' => true,
|
||||
'fieldType' => 'radio',
|
||||
'mandatory' => true,
|
||||
'extensions' => 'gpx,kml,wkt',
|
||||
'tl_class' => 'clr',
|
||||
],
|
||||
'sql' => 'binary(16) NULL',
|
||||
|
||||
@@ -145,14 +145,27 @@ $GLOBALS['TL_LANG']['tl_leaflet_layer']['amenity'][0] = 'Amen
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['amenity'][1] = 'OSM amenity.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['amenityIcon'][1] = 'Icon';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['amenityIcon'][0] = 'Icon style';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormat'][0] = 'File formats';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormat'][1] = 'Choose which file format is used.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['file'][0] = 'File';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['file'][1] = 'Choose a file containing geodata. Supported formats are gpx,kml and wkt.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['file'][1] = 'Choose a file containing geodata. Supported formats are: %s.';
|
||||
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][0] = 'Layer group';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['layer'][1] = 'Basic layer group. <br> See <a href="http://leafletjs.com/reference.html#layergroup" target="_blank">http://leafletjs.com/reference.html#layergroup</a>';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['feature'][0] = 'Feature group';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['groupTypes']['feature'][1] = 'Extended layer group with events and popup support. <br>See <a href="http://leafletjs.com/reference.html#featuregroup" target="_blank">http://leafletjs.com/reference.html#featuregroup</a>';
|
||||
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormats']['gpx'][0] = 'GPX';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormats']['gpx'][1] = 'GPS Exchange format. <a href="https://github.com/mapbox/togeojson#gpx-feature-support" target="_blank">Read the documentation</a> for more information.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormats']['kml'][0] = 'KML';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormats']['kml'][1] = 'Keyhole Markup Language. <a href="https://github.com/mapbox/togeojson#kml-feature-support" target="_blank">Read the documentation</a> for more information.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormats']['wkt'][0] = 'WKT';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormats']['wkt'][1] = 'Well-known text <a href="https://github.com/mapbox/togeojson#kml-feature-support" target="_blank">Read the documentation</a> for more information.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormats']['topojson'][0] = 'TopoJSON';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormats']['topojson'][1] = 'TopoJSON is a topological geospatial data interchange format based on GeoJSON. <a href="https://github.com/topojson/topojson#api-reference" target="_blank">Read the documentation</a> for more information.';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormats']['geojson'][0] = 'GeoJSON';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['fileFormats']['geojson'][1] = 'GeoJSON is a format for encoding a variety of geographic data structures. <a href="https://github.com/mapbox/wellknown" target="_blank">Read the documentation</a> for more information.';
|
||||
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['pasteinto'][1] = 'Paste into layer %s';
|
||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['pasteafter'][1] = 'Paste after layer %s';
|
||||
|
||||
|
||||
3
src/Bundle/Resources/public/css/backend_hacks.css
Normal file
3
src/Bundle/Resources/public/css/backend_hacks.css
Normal file
@@ -0,0 +1,3 @@
|
||||
.tl_help_table a {
|
||||
color: #77ac45
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
namespace Netzmacht\Contao\Leaflet\Listener\Dca;
|
||||
|
||||
use Contao\Controller;
|
||||
use Contao\DataContainer;
|
||||
use Contao\Image;
|
||||
use Contao\RequestToken;
|
||||
use Contao\StringUtil;
|
||||
@@ -81,6 +82,13 @@ class LayerDcaListener extends AbstractListener
|
||||
*/
|
||||
private $labelRenderer;
|
||||
|
||||
/**
|
||||
* File formats.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $fileFormats;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
@@ -91,6 +99,7 @@ class LayerDcaListener extends AbstractListener
|
||||
* @param array $layers Leaflet layer configuration.
|
||||
* @param array $tileProviders Tile providers.
|
||||
* @param array $amenities OSM amenities.
|
||||
* @param array $fileFormats File formats.
|
||||
*/
|
||||
public function __construct(
|
||||
Manager $manager,
|
||||
@@ -99,7 +108,8 @@ class LayerDcaListener extends AbstractListener
|
||||
LayerLabelRenderer $labelRenderer,
|
||||
array $layers,
|
||||
array $tileProviders,
|
||||
array $amenities
|
||||
array $amenities,
|
||||
array $fileFormats
|
||||
) {
|
||||
parent::__construct($manager);
|
||||
|
||||
@@ -111,6 +121,7 @@ class LayerDcaListener extends AbstractListener
|
||||
$this->translator = $translator;
|
||||
$this->amenities = $amenities;
|
||||
$this->labelRenderer = $labelRenderer;
|
||||
$this->fileFormats = $fileFormats;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -424,6 +435,49 @@ class LayerDcaListener extends AbstractListener
|
||||
return $builder->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file formats.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFileFormats(): array
|
||||
{
|
||||
return array_keys($this->fileFormats);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the file widget.
|
||||
*
|
||||
* @param mixed $value Given value.
|
||||
* @param DataContainer $dataContainer Data container driver.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function prepareFileWidget($value, $dataContainer)
|
||||
{
|
||||
if ($dataContainer->activeRecord) {
|
||||
$fileFormat = $dataContainer->activeRecord->fileFormat;
|
||||
|
||||
if (isset($this->fileFormats[$fileFormat])) {
|
||||
$definition = $this->getDefinition();
|
||||
$definition->set(
|
||||
['fields', $dataContainer->field, 'eval', 'extensions'],
|
||||
implode(',', $this->fileFormats[$fileFormat])
|
||||
);
|
||||
|
||||
$definition->set(
|
||||
['fields', $dataContainer->field, 'label', 1],
|
||||
sprintf(
|
||||
$definition->get(['fields', $dataContainer->field, 'label', 1]),
|
||||
implode(', ', $this->fileFormats[$fileFormat])
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a button.
|
||||
*
|
||||
|
||||
@@ -22,9 +22,11 @@ use Netzmacht\JavascriptBuilder\Type\Expression;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\FeatureGroup;
|
||||
use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
|
||||
use Netzmacht\LeafletPHP\Plugins\Omnivore\GeoJson as OmnivoreGeoJson;
|
||||
use Netzmacht\LeafletPHP\Plugins\Omnivore\Gpx;
|
||||
use Netzmacht\LeafletPHP\Plugins\Omnivore\Kml;
|
||||
use Netzmacht\LeafletPHP\Plugins\Omnivore\OmnivoreLayer;
|
||||
use Netzmacht\LeafletPHP\Plugins\Omnivore\TopoJson;
|
||||
use Netzmacht\LeafletPHP\Plugins\Omnivore\Wkt;
|
||||
|
||||
/**
|
||||
@@ -80,17 +82,25 @@ class FileLayerMapper extends AbstractLayerMapper
|
||||
$layerId = $this->getElementId($model, $elementId);
|
||||
|
||||
if ($fileModel instanceof FilesModel && $fileModel->type === 'file') {
|
||||
switch ($fileModel->extension) {
|
||||
switch ($model->fileFormat) {
|
||||
case 'gpx':
|
||||
$layer = new Gpx($layerId, $fileModel->path, []);
|
||||
$layer = new Gpx($layerId, $fileModel->path);
|
||||
break;
|
||||
|
||||
case 'kml':
|
||||
$layer = new Kml($layerId, $fileModel->path, []);
|
||||
$layer = new Kml($layerId, $fileModel->path);
|
||||
break;
|
||||
|
||||
case 'wkt':
|
||||
$layer = new Wkt($layerId, $fileModel->path, []);
|
||||
$layer = new Wkt($layerId, $fileModel->path);
|
||||
break;
|
||||
|
||||
case 'geojson':
|
||||
$layer = new OmnivoreGeoJson($layerId, $fileModel->path);
|
||||
break;
|
||||
|
||||
case 'topojson':
|
||||
$layer = new TopoJson($layerId, $fileModel->path);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user