Updated event_osm to v0.3.5 (#121)

* preloading fixed

* added missing php 7.0 dependency

* osm bugfix for "no categories"

* count distance only once

* performance updates

* more understandable translations

* plugin dependencies added

* updated event_osm to v0.3.5

Co-authored-by: surrim <surrim@happyhydro.org>
This commit is contained in:
surrim 2021-01-11 15:45:40 +01:00 committed by GitHub
parent 729d154d1b
commit e5c22e6d0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 83 additions and 57 deletions

View file

@ -1,3 +1,14 @@
0.3.5:
---
* Plugin dependencies added
* More understandable translations
* Performance updates
* Count distances only once
* Bugfix for "no categories"
* Added missing php 7.0 dependency
* Preloading fixed
0.3.4:
---

View file

@ -1,21 +1,23 @@
<?php
@define('PLUGIN_EVENT_OSM_NAME', 'OpenStreetMap Integration');
@define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Bietet eine interaktive Karte für *.gpx Uploads und Blogs mit Geo-Daten.');
@define('PLUGIN_EVENT_OSM_NOSHOW', ' (Wird nie auf Seite(n) angezeigt.)');
@define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Bietet eine interaktive Karte für *.gpx Uploads und Blogs mit Geo-Daten');
@define('PLUGIN_EVENT_OSM_NOT_SHOWN', 'Wird nicht auf der Webseite angezeigt');
@define('PLUGIN_EVENT_STATIC_OSM_NAME', 'OpenStreetMap Statische Dateien');
@define('PLUGIN_EVENT_STATIC_OSM_DESCRIPTION', 'Fügt Scripte und Stylesheets für OpenStreetMap ein.');
@define('PLUGIN_EVENT_STATIC_OSM_DESCRIPTION', 'Fügt Scripte und Stylesheets für OpenStreetMap ein');
@define('PLUGIN_EVENT_STATIC_OSM_COMPRESS_GPX', 'GPX-Dateien komprimieren');
@define('PLUGIN_EVENT_STATIC_OSM_COMPRESS_GPX_DESCRIPTION', 'Entfernt alle nicht benötigten Daten aus den GPX-Dateien beim Upload');
@define('PLUGIN_EVENT_OSM_CATEGORY', 'Kategorie');
@define('PLUGIN_EVENT_OSM_CATEGORY_DESCRIPTION', 'Karte wird für diese Kategorie angezeigt');
@define('PLUGIN_EVENT_OSM_CATEGORY_WITHOUT', 'Ohne');
@define('PLUGIN_EVENT_OSM_CATEGORY_ANY', 'Beliebig');
@define('PLUGIN_EVENT_OSM_PATH', 'Pfad');
@define('PLUGIN_EVENT_OSM_PATH_DESCRIPTION', 'Pfad für GPX-Dateien');
@define('PLUGIN_EVENT_OSM_LAT', 'Breitengrad (Lat.)');
@define('PLUGIN_EVENT_OSM_LAT_DESCRIPTION', 'Breitengrad für die Mitte der Karte.');
@define('PLUGIN_EVENT_OSM_LAT_DESCRIPTION', 'Breitengrad für die Mitte der Karte');
@define('PLUGIN_EVENT_OSM_LONG', 'Längengrad (Lon.)');
@define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Längengrad für die Mitte der Karte.');
@define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Längengrad für die Mitte der Karte');
@define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom');
@define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom Level der Karte.');
@define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom Level der Karte');
@define('PLUGIN_EVENT_OSM_HEIGHT', 'Kartenhöhe');
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Die Höhe der Karte.');
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Die Höhe der Karte');
?>

View file

@ -1,21 +1,23 @@
<?php
@define('PLUGIN_EVENT_OSM_NAME', 'OpenStreetMap Integration');
@define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Bietet eine interaktive Karte für *.gpx Uploads und Blogs mit Geo-Daten.');
@define('PLUGIN_EVENT_OSM_NOSHOW', ' (Wird nie auf Seite(n) angezeigt.)');
@define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Bietet eine interaktive Karte für *.gpx Uploads und Blogs mit Geo-Daten');
@define('PLUGIN_EVENT_OSM_NOT_SHOWN', 'Wird nicht auf der Webseite angezeigt');
@define('PLUGIN_EVENT_STATIC_OSM_NAME', 'OpenStreetMap Statische Dateien');
@define('PLUGIN_EVENT_STATIC_OSM_DESCRIPTION', 'Fügt Scripte und Stylesheets für OpenStreetMap ein.');
@define('PLUGIN_EVENT_STATIC_OSM_DESCRIPTION', 'Fügt Scripte und Stylesheets für OpenStreetMap ein');
@define('PLUGIN_EVENT_STATIC_OSM_COMPRESS_GPX', 'GPX-Dateien komprimieren');
@define('PLUGIN_EVENT_STATIC_OSM_COMPRESS_GPX_DESCRIPTION', 'Entfernt alle nicht benötigten Daten aus den GPX-Dateien beim Upload');
@define('PLUGIN_EVENT_OSM_CATEGORY', 'Kategorie');
@define('PLUGIN_EVENT_OSM_CATEGORY_DESCRIPTION', 'Karte wird für diese Kategorie angezeigt');
@define('PLUGIN_EVENT_OSM_CATEGORY_WITHOUT', 'Ohne');
@define('PLUGIN_EVENT_OSM_CATEGORY_ANY', 'Beliebig');
@define('PLUGIN_EVENT_OSM_PATH', 'Pfad');
@define('PLUGIN_EVENT_OSM_PATH_DESCRIPTION', 'Pfad für GPX-Dateien');
@define('PLUGIN_EVENT_OSM_LAT', 'Breitengrad (Lat.)');
@define('PLUGIN_EVENT_OSM_LAT_DESCRIPTION', 'Breitengrad für die Mitte der Karte.');
@define('PLUGIN_EVENT_OSM_LAT_DESCRIPTION', 'Breitengrad für die Mitte der Karte');
@define('PLUGIN_EVENT_OSM_LONG', 'Längengrad (Lon.)');
@define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Längengrad für die Mitte der Karte.');
@define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Längengrad für die Mitte der Karte');
@define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom');
@define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom Level der Karte.');
@define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom Level der Karte');
@define('PLUGIN_EVENT_OSM_HEIGHT', 'Kartenhöhe');
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Die Höhe der Karte.');
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'Die Höhe der Karte');
?>

View file

@ -1,21 +1,23 @@
<?php
@define('PLUGIN_EVENT_OSM_NAME', 'OpenStreetMap integration');
@define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Provides an interactive map with *.gpx uploads and tagged geo data.');
@define('PLUGIN_EVENT_OSM_NOSHOW', ' (It does not show up on the actual page.)');
@define('PLUGIN_EVENT_OSM_DESCRIPTION', 'Provides an interactive map with *.gpx uploads and tagged geo data');
@define('PLUGIN_EVENT_OSM_NOT_SHOWN', 'Not shows on webpage');
@define('PLUGIN_EVENT_STATIC_OSM_NAME', 'OpenStreetMap static files');
@define('PLUGIN_EVENT_STATIC_OSM_DESCRIPTION', 'Includes scripts and stylesheets for OpenStreetMap support.');
@define('PLUGIN_EVENT_STATIC_OSM_DESCRIPTION', 'Includes scripts and stylesheets for OpenStreetMap support');
@define('PLUGIN_EVENT_STATIC_OSM_COMPRESS_GPX', 'Compress GPX-files');
@define('PLUGIN_EVENT_STATIC_OSM_COMPRESS_GPX_DESCRIPTION', 'Remove not needed information from GPX-files when uploading');
@define('PLUGIN_EVENT_OSM_CATEGORY', 'Category');
@define('PLUGIN_EVENT_OSM_CATEGORY_DESCRIPTION', 'Map will be shown for this category');
@define('PLUGIN_EVENT_OSM_CATEGORY_WITHOUT', 'Without');
@define('PLUGIN_EVENT_OSM_CATEGORY_ANY', 'Any');
@define('PLUGIN_EVENT_OSM_PATH', 'Path');
@define('PLUGIN_EVENT_OSM_PATH_DESCRIPTION', 'Path for GPX-files');
@define('PLUGIN_EVENT_OSM_LAT', 'Latitude');
@define('PLUGIN_EVENT_OSM_LAT_DESCRIPTION', 'Latitude of the center of the map.');
@define('PLUGIN_EVENT_OSM_LAT_DESCRIPTION', 'Latitude of the center of the map');
@define('PLUGIN_EVENT_OSM_LONG', 'Longitude');
@define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Longitude of the center of the map.');
@define('PLUGIN_EVENT_OSM_LONG_DESCRIPTION', 'Longitude of the center of the map');
@define('PLUGIN_EVENT_OSM_ZOOM', 'Zoom');
@define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom level of the map.');
@define('PLUGIN_EVENT_OSM_ZOOM_DESCRIPTION', 'Zoom level of the map');
@define('PLUGIN_EVENT_OSM_HEIGHT', 'Map height');
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'The height of the map.');
@define('PLUGIN_EVENT_OSM_HEIGHT_DESCRIPTION', 'The height of the map');
?>

View file

@ -1,4 +1,4 @@
<?php
@define('PLUGIN_EVENT_OSM_VERSION', '0.3.4');
@define('PLUGIN_EVENT_OSM_VERSION', '0.3.5');
@define('PLUGIN_EVENT_OSM_AUTHOR', 'Martin Sewelies');
?>

View file

@ -27,12 +27,9 @@ window.addEventListener("load", () => {
const osmSource = new ol.source.OSM();
const layers = [
new ol.layer.Tile({source: osmSource}),
new ol.layer.Tile({source: osmSource, preload: Infinity}),
new ol.layer.Vector({
source: new ol.source.Vector({
features: features,
preload: Infinity
}),
source: new ol.source.Vector({features: features}),
style: feature => {
const id = feature.getId();
const entry = entries[id];
@ -49,30 +46,27 @@ window.addEventListener("load", () => {
})
];
for (const upload of uploads) {
const source = new ol.source.Vector({
url: upload.url,
format: new ol.format.GPX()
});
source.on("featuresloadend", event => {
upload.length = event.features
.filter(feature => feature.getGeometry().getType() === "MultiLineString")
.map(feature => ol.sphere.getLength(feature.getGeometry()))
.reduce((a, b) => a + b, 0);
});
const layer = new ol.layer.Vector({
source: new ol.source.Vector({
url: upload.url,
format: new ol.format.GPX()
}),
style: feature => {
if (feature.getGeometry().getType() === "MultiLineString") {
upload.length = ol.sphere.getLength(feature.getGeometry());
if (!uploads.some(u => u.length === undefined)) {
const distance = uploads.map(u => u.length).reduce((a, b) => a + b, 0);
document.querySelectorAll("span.distance-counter[data-category=\"" + data.category + "\"]").forEach(span => {
span.innerHTML = Math.round(distance / 1000);
});
}
return new ol.style.Style({
stroke: new ol.style.Stroke({
color: dateToColor(new Date(upload.date * 1000)),
width: 3,
lineDash: upload.date * 1000 > Date.now() ? [3, 6] : undefined
})
});
}
return undefined;
}
source: source,
style: feature => feature.getGeometry().getType() === "MultiLineString"
? new ol.style.Style({
stroke: new ol.style.Stroke({
color: dateToColor(new Date(upload.date * 1000)),
width: 3,
lineDash: upload.date * 1000 > Date.now() ? [3, 6] : undefined
})
})
: undefined
});
layers.push(layer);
}
@ -101,7 +95,7 @@ window.addEventListener("load", () => {
zoom: data.zoom
})
});
map.on("singleclick", event => {
const makeItem = object => {
const title = document.createTextNode(object.title);
@ -161,5 +155,11 @@ window.addEventListener("load", () => {
const hit = map.hasFeatureAtPixel(pixel, {hitTolerance: 10});
divMap.style.cursor = hit ? "pointer" : "";
});
map.on("rendercomplete", event => {
const distance = uploads.map(u => u.length).reduce((a, b) => a + b, 0);
document.querySelectorAll("span.distance-counter[data-category=\"" + data.category + "\"]").forEach(span => {
span.innerHTML = (distance / 1000).toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 0});
});
});
});
});

View file

@ -18,10 +18,14 @@
$propbag->add('author', PLUGIN_EVENT_OSM_AUTHOR);
$propbag->add('version', PLUGIN_EVENT_OSM_VERSION);
$propbag->add('requirements', array(
'php' => '7.0.0',
'serendipity' => '2.3'
));
$propbag->add('stackable', true);
$propbag->add('groups', array('FRONTEND_ENTRY_RELATED'));
$this->dependencies = array(
'serendipity_event_geo_json' => 'keep'
);
}
function generate_content(&$title)
@ -42,7 +46,9 @@
return $serendipity['POST']['multiCat'] ?? [$vars['category']];
case 'plugin':
case 'start':
return [$vars['staticpage_related_category_id']];
return $vars['staticpage_related_category_id'] !== '0'
? [$vars['staticpage_related_category_id']]
: [];
}
return [];
}
@ -50,12 +56,12 @@
function event_hook($event, &$bag, &$eventData, $addData = null)
{
if ($event == 'entries_header') {
$category_id = $this->get_config('category_id', 'all');
$category_id = $this->get_config('category_id', 'any');
$page_categories = $this->get_page_categories();
if (
$category_id === 'all'
$category_id === 'any'
||
($category_id === 'none' && empty($page_categories))
($category_id === 'without' && empty($page_categories))
||
in_array($category_id, $page_categories)
) {
@ -66,7 +72,7 @@
function get_selectable_categories()
{
$categories = array('all' => ALL_CATEGORIES, 'none' => NO_CATEGORIES);
$categories = array('without' => PLUGIN_EVENT_OSM_CATEGORY_WITHOUT, 'any' => PLUGIN_EVENT_OSM_CATEGORY_ANY);
$cats = serendipity_fetchCategories();
if (is_array($cats)) {
$cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
@ -83,7 +89,7 @@
case 'title':
$propbag->add('type', 'string');
$propbag->add('name', TITLE);
$propbag->add('description', TITLE . PLUGIN_EVENT_OSM_NOSHOW);
$propbag->add('description', TITLE . ' (' . PLUGIN_EVENT_OSM_NOT_SHOWN . ')');
$propbag->add('default', PLUGIN_EVENT_OSM_NAME);
break;
case 'category_id':

View file

@ -25,6 +25,9 @@
));
$propbag->add('stackable', false);
$propbag->add('groups', array('FRONTEND_ENTRY_RELATED'));
$this->dependencies = array(
'serendipity_event_geo_osm' => 'keep'
);
}
function generate_content(&$title)