mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-11-30 12:03:44 +01:00
Support geojson and topojson as file types for the file layer.
This commit is contained in:
@@ -38,6 +38,13 @@ parameters:
|
|||||||
- 'circle'
|
- 'circle'
|
||||||
- 'circleMarker'
|
- '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.
|
# When creating a GeoJSON feature of a map object a feature.properties.model object is passed.
|
||||||
# Define the properties you always want to set.
|
# Define the properties you always want to set.
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ services:
|
|||||||
- '%netzmacht.contao_leaflet.layers%'
|
- '%netzmacht.contao_leaflet.layers%'
|
||||||
- '%netzmacht.contao_leaflet.providers%'
|
- '%netzmacht.contao_leaflet.providers%'
|
||||||
- '%netzmacht.contao_leaflet.amenities%'
|
- '%netzmacht.contao_leaflet.amenities%'
|
||||||
|
- '%netzmacht.contao_leaflet.file_formats%'
|
||||||
|
|
||||||
netzmacht.contao_leaflet.listeners.dca.marker:
|
netzmacht.contao_leaflet.listeners.dca.marker:
|
||||||
class: Netzmacht\Contao\Leaflet\Listener\Dca\MarkerDcaListener
|
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.
|
* Models.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [
|
|||||||
],
|
],
|
||||||
|
|
||||||
'file extends default' => [
|
'file extends default' => [
|
||||||
'+config' => ['file', 'boundsMode'],
|
'+config' => ['boundsMode', 'fileFormat'],
|
||||||
'+expert' => [
|
'+expert' => [
|
||||||
'onEachFeature',
|
'onEachFeature',
|
||||||
'pointToLayer',
|
'pointToLayer',
|
||||||
@@ -235,6 +235,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [
|
|||||||
'MapBox' => ['tile_provider_key'],
|
'MapBox' => ['tile_provider_key'],
|
||||||
'HERE' => ['tile_provider_key', 'tile_provider_code'],
|
'HERE' => ['tile_provider_key', 'tile_provider_code'],
|
||||||
],
|
],
|
||||||
|
'fileFormat' => [
|
||||||
|
'!' => ['file']
|
||||||
|
]
|
||||||
],
|
],
|
||||||
|
|
||||||
'metasubpalettes' => [
|
'metasubpalettes' => [
|
||||||
@@ -861,15 +864,34 @@ $GLOBALS['TL_DCA']['tl_leaflet_layer'] = [
|
|||||||
],
|
],
|
||||||
'sql' => 'mediumtext NULL',
|
'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' => [
|
'file' => [
|
||||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['file'],
|
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_layer']['file'],
|
||||||
'exclude' => true,
|
'exclude' => true,
|
||||||
'inputType' => 'fileTree',
|
'inputType' => 'fileTree',
|
||||||
|
'load_callback' => [
|
||||||
|
['netzmacht.contao_leaflet.listeners.dca.layer', 'prepareFileWidget'],
|
||||||
|
],
|
||||||
'eval' => [
|
'eval' => [
|
||||||
'filesOnly' => true,
|
'filesOnly' => true,
|
||||||
'fieldType' => 'radio',
|
'fieldType' => 'radio',
|
||||||
'mandatory' => true,
|
'mandatory' => true,
|
||||||
'extensions' => 'gpx,kml,wkt',
|
|
||||||
'tl_class' => 'clr',
|
'tl_class' => 'clr',
|
||||||
],
|
],
|
||||||
'sql' => 'binary(16) NULL',
|
'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']['amenity'][1] = 'OSM amenity.';
|
||||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['amenityIcon'][1] = 'Icon';
|
$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']['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'][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'][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']['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'][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']['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']['pasteinto'][1] = 'Paste into layer %s';
|
||||||
$GLOBALS['TL_LANG']['tl_leaflet_layer']['pasteafter'][1] = 'Paste after 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;
|
namespace Netzmacht\Contao\Leaflet\Listener\Dca;
|
||||||
|
|
||||||
use Contao\Controller;
|
use Contao\Controller;
|
||||||
|
use Contao\DataContainer;
|
||||||
use Contao\Image;
|
use Contao\Image;
|
||||||
use Contao\RequestToken;
|
use Contao\RequestToken;
|
||||||
use Contao\StringUtil;
|
use Contao\StringUtil;
|
||||||
@@ -81,6 +82,13 @@ class LayerDcaListener extends AbstractListener
|
|||||||
*/
|
*/
|
||||||
private $labelRenderer;
|
private $labelRenderer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File formats.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $fileFormats;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct.
|
* Construct.
|
||||||
*
|
*
|
||||||
@@ -91,6 +99,7 @@ class LayerDcaListener extends AbstractListener
|
|||||||
* @param array $layers Leaflet layer configuration.
|
* @param array $layers Leaflet layer configuration.
|
||||||
* @param array $tileProviders Tile providers.
|
* @param array $tileProviders Tile providers.
|
||||||
* @param array $amenities OSM amenities.
|
* @param array $amenities OSM amenities.
|
||||||
|
* @param array $fileFormats File formats.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Manager $manager,
|
Manager $manager,
|
||||||
@@ -99,7 +108,8 @@ class LayerDcaListener extends AbstractListener
|
|||||||
LayerLabelRenderer $labelRenderer,
|
LayerLabelRenderer $labelRenderer,
|
||||||
array $layers,
|
array $layers,
|
||||||
array $tileProviders,
|
array $tileProviders,
|
||||||
array $amenities
|
array $amenities,
|
||||||
|
array $fileFormats
|
||||||
) {
|
) {
|
||||||
parent::__construct($manager);
|
parent::__construct($manager);
|
||||||
|
|
||||||
@@ -111,6 +121,7 @@ class LayerDcaListener extends AbstractListener
|
|||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
$this->amenities = $amenities;
|
$this->amenities = $amenities;
|
||||||
$this->labelRenderer = $labelRenderer;
|
$this->labelRenderer = $labelRenderer;
|
||||||
|
$this->fileFormats = $fileFormats;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -424,6 +435,49 @@ class LayerDcaListener extends AbstractListener
|
|||||||
return $builder->getOptions();
|
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.
|
* Generate a button.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ use Netzmacht\JavascriptBuilder\Type\Expression;
|
|||||||
use Netzmacht\LeafletPHP\Definition;
|
use Netzmacht\LeafletPHP\Definition;
|
||||||
use Netzmacht\LeafletPHP\Definition\Group\FeatureGroup;
|
use Netzmacht\LeafletPHP\Definition\Group\FeatureGroup;
|
||||||
use Netzmacht\LeafletPHP\Definition\Group\GeoJson;
|
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\Gpx;
|
||||||
use Netzmacht\LeafletPHP\Plugins\Omnivore\Kml;
|
use Netzmacht\LeafletPHP\Plugins\Omnivore\Kml;
|
||||||
use Netzmacht\LeafletPHP\Plugins\Omnivore\OmnivoreLayer;
|
use Netzmacht\LeafletPHP\Plugins\Omnivore\OmnivoreLayer;
|
||||||
|
use Netzmacht\LeafletPHP\Plugins\Omnivore\TopoJson;
|
||||||
use Netzmacht\LeafletPHP\Plugins\Omnivore\Wkt;
|
use Netzmacht\LeafletPHP\Plugins\Omnivore\Wkt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,17 +82,25 @@ class FileLayerMapper extends AbstractLayerMapper
|
|||||||
$layerId = $this->getElementId($model, $elementId);
|
$layerId = $this->getElementId($model, $elementId);
|
||||||
|
|
||||||
if ($fileModel instanceof FilesModel && $fileModel->type === 'file') {
|
if ($fileModel instanceof FilesModel && $fileModel->type === 'file') {
|
||||||
switch ($fileModel->extension) {
|
switch ($model->fileFormat) {
|
||||||
case 'gpx':
|
case 'gpx':
|
||||||
$layer = new Gpx($layerId, $fileModel->path, []);
|
$layer = new Gpx($layerId, $fileModel->path);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'kml':
|
case 'kml':
|
||||||
$layer = new Kml($layerId, $fileModel->path, []);
|
$layer = new Kml($layerId, $fileModel->path);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'wkt':
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user