category and path for osm plugin
This commit is contained in:
parent
3d667ae714
commit
1162e6b913
|
@ -2,12 +2,17 @@
|
|||
@define('PLUGIN_EVENT_OSM_NAME', 'OpenStreetMaps integration');
|
||||
@define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Provides an interactive map with *.gpx uploads and tagged geo data.');
|
||||
|
||||
@define('PLUGIN_EVENT_OSM_LONG', 'Longitude');
|
||||
@define('PLUGIN_EVENT_OSM_LONG_DESC', 'Longitude of the center of the map (entry editing), if the geodata are not set in the entry.');
|
||||
|
||||
@define('PLUGIN_EVENT_OSM_CATEGORY', 'Category');
|
||||
@define('PLUGIN_EVENT_OSM_CATEGORY_DESC', 'Map will be shown for this category');
|
||||
@define('PLUGIN_EVENT_OSM_PATH', 'Path');
|
||||
@define('PLUGIN_EVENT_OSM_PATH_DESC', 'Path for GPX-files');
|
||||
@define('PLUGIN_EVENT_OSM_LAT', 'Latitude');
|
||||
@define('PLUGIN_EVENT_OSM_LAT_DESC', 'Latitude of the center of the map (entry editing), if the geodata are not set in the entry.');
|
||||
@define('PLUGIN_EVENT_OSM_LAT_DESC', 'Latitude of the center of the map.');
|
||||
@define('PLUGIN_EVENT_OSM_LONG', 'Longitude');
|
||||
@define('PLUGIN_EVENT_OSM_LONG_DESC', 'Longitude of the center of the map.');
|
||||
@define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom');
|
||||
@define('PLUGIN_EVENT_OSM_ZOOM_DESC', 'Zoom of the map (entry editing). The higher the number the more details you will see.');
|
||||
@define('PLUGIN_EVENT_OSM_ZOOM_DESC', 'Zoom level of the map.');
|
||||
@define('PLUGIN_EVENT_OSM_HEIGHT', 'Map height');
|
||||
@define('PLUGIN_EVENT_OSM_HEIGHT_DESC', 'The height of the map.');
|
||||
?>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
$propbag->add('name', PLUGIN_EVENT_OSM_NAME);
|
||||
$propbag->add('description', PLUGIN_EVENT_OSM_DESCRIPTION);
|
||||
$propbag->add('copyright', 'GPL');
|
||||
$propbag->add('configuration', array('title', 'height', 'latitude', 'longitude', 'zoom'));
|
||||
$propbag->add('configuration', array('title', 'category_id', 'path', 'height', 'latitude', 'longitude', 'zoom'));
|
||||
$propbag->add('event_hooks', array('entries_header' => true));
|
||||
$propbag->add('author', 'Martin Sewelies');
|
||||
$propbag->add('version', '0.1');
|
||||
|
@ -28,14 +28,43 @@
|
|||
$title = $this->get_config('title');
|
||||
}
|
||||
|
||||
function get_page_categories()
|
||||
{
|
||||
global $serendipity;
|
||||
$vars = $serendipity['smarty']->get_template_vars();
|
||||
switch ($vars['view']) {
|
||||
case 'entry':
|
||||
return array_map(function($x) {
|
||||
return $x['categoryid'];
|
||||
}, $vars['entry']['categories']);
|
||||
case 'categories':
|
||||
return $serendipity['POST']['multiCat'] ?? [$vars['category']];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function event_hook($event, &$bag, &$eventData, $addData = null)
|
||||
{
|
||||
if ($event == 'entries_header') {
|
||||
echo ' <div id="map" style="height: '.$this->get_config('height', '463px').'" data-latitude="'.$this->get_config('latitude', 51.48165).'" data-longitude="'.$this->get_config('longitude', 7.21648).'" data-zoom="'.$this->get_config('zoom', 15).'"></div>'.PHP_EOL;
|
||||
echo ' <div id="popup" class="ol-popup"></div>'.PHP_EOL;
|
||||
if (in_array($this->get_config('category_id'), $this->get_page_categories())) {
|
||||
echo ' <div id="map" data-path="'.$this->get_config('path', '').'" data-latitude="'.$this->get_config('latitude', 51.48165).'" data-longitude="'.$this->get_config('longitude', 7.21648).'" data-zoom="'.$this->get_config('zoom', 15).'" style="height: '.$this->get_config('height', '463px').'"></div>'.PHP_EOL;
|
||||
echo ' <div id="popup" class="ol-popup"></div>'.PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function get_selectable_categories()
|
||||
{
|
||||
$res = serendipity_fetchCategories();
|
||||
$categories[0] = NO_CATEGORY;
|
||||
if (is_array($categories)) {
|
||||
foreach ($res as $category) {
|
||||
$categories[$category['categoryid']] = $category['category_name'];
|
||||
}
|
||||
}
|
||||
return $categories;
|
||||
}
|
||||
|
||||
function introspect_config_item($name, &$propbag)
|
||||
{
|
||||
switch($name) {
|
||||
|
@ -45,6 +74,19 @@
|
|||
$propbag->add('description', TITLE . PLUGIN_PAGE_NUGGET_NOSHOW);
|
||||
$propbag->add('default', PLUGIN_EVENT_OSM_NAME);
|
||||
break;
|
||||
case 'category_id':
|
||||
$propbag->add('type', 'select');
|
||||
$propbag->add('name', PLUGIN_EVENT_OSM_CATEGORY);
|
||||
$propbag->add('description', PLUGIN_EVENT_OSM_CATEGORY_DESCRIPTION);
|
||||
$propbag->add('select_values', $this->get_selectable_categories());
|
||||
$propbag->add('default', '');
|
||||
break;
|
||||
case 'path':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_EVENT_OSM_PATH);
|
||||
$propbag->add('description', PLUGIN_EVENT_OSM_PATH_DESC);
|
||||
$propbag->add('default', '');
|
||||
break;
|
||||
case 'height':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_EVENT_OSM_HEIGHT);
|
||||
|
|
|
@ -41,7 +41,8 @@ window.onload = () => {
|
|||
zIndex: Infinity
|
||||
})
|
||||
];
|
||||
for (const upload of geo.uploads) {
|
||||
const data = document.getElementById("map").dataset;
|
||||
for (const upload of geo.uploads.filter(x => x.url.startsWith(data.path))) {
|
||||
const layer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
url: upload.url,
|
||||
|
@ -57,7 +58,6 @@ window.onload = () => {
|
|||
});
|
||||
layers.push(layer);
|
||||
}
|
||||
const data = document.getElementById("map").dataset;
|
||||
const map = new ol.Map({
|
||||
controls: ol.control.defaults({rotate: false}).extend([
|
||||
new ol.control.FullScreen(),
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
$propbag->add('requirements', array(
|
||||
'serendipity' => '2.3'
|
||||
));
|
||||
$propbag->add('stackable', true);
|
||||
$propbag->add('stackable', false);
|
||||
$propbag->add('groups', array('FRONTEND_ENTRY_RELATED'));
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,8 @@
|
|||
{
|
||||
global $serendipity;
|
||||
if ($event == 'frontend_header') {
|
||||
echo ' <link rel="stylesheet" href="'.$this->getFile('ol.css', 'serendipityHTTPPath').'" type="text/css">'.PHP_EOL;
|
||||
echo ' <link rel="stylesheet" href="'.$this->getFile('osm.css', 'serendipityHTTPPath').'" type="text/css">'.PHP_EOL;
|
||||
echo ' <link rel="stylesheet" href="'.$this->getFile('ol.css', 'serendipityHTTPPath').'" type="text/css" />'.PHP_EOL;
|
||||
echo ' <link rel="stylesheet" href="'.$this->getFile('osm.css', 'serendipityHTTPPath').'" type="text/css" />'.PHP_EOL;
|
||||
echo ' <script src="'.$this->getFile('ol.js', 'serendipityHTTPPath').'"></script>'.PHP_EOL;
|
||||
echo ' <script src="'.$this->getFile('osm.js', 'serendipityHTTPPath').'"></script>'.PHP_EOL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue