1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-12-01 22:52:06 +02:00

Fix map author loading

This commit is contained in:
Patrik J. Braun
2025-08-01 23:08:40 +02:00
parent c7fc2ea5ba
commit 1738befff0
2 changed files with 27 additions and 8 deletions

View File

@@ -657,8 +657,9 @@ export class GalleryMapLightboxComponent implements OnChanges, OnDestroy {
mkr.setIcon(pathLayer.icon);
// Setting popup info
mkr.bindPopup(file.name + ': ' + parsedGPX.name);
// Setting popup info with improved formatting
const popupText = `${file.name}: ${parsedGPX.name}${parsedGPX.author ? '<br/>Author: ' + parsedGPX.author : ''}${parsedGPX.description ? '<br/>Description: ' + parsedGPX.description : ''}`;
mkr.bindPopup(popupText);
//add arch for long paths
parsedGPX.path.forEach(p => {
@@ -718,4 +719,3 @@ export interface MapPhoto {
thumbnail: Thumbnail;
};
}

View File

@@ -100,7 +100,7 @@ export class MapService {
public async getMapCoordinates(
file: FileDTO
): Promise<{ name: string, path: LatLngLiteral[][]; markers: LatLngLiteral[] }> {
): Promise<{ name: string, author?: string, description?: string, path: LatLngLiteral[][]; markers: LatLngLiteral[] }> {
const filePath = Utils.concatUrls(
file.directory.path,
file.directory.name,
@@ -109,6 +109,23 @@ export class MapService {
const gpx = await this.networkService.getXML(
'/gallery/content/' + filePath + '/bestFit'
);
// Look for name in metadata first, then in track
let name = '';
const metadata = gpx.getElementsByTagName('metadata')?.[0];
// Only look for direct name children of metadata, don't include author>name
const metadataName = Array.from(metadata?.children || [])
.find(child => child.tagName === 'name')?.textContent;
const trkName = gpx.getElementsByTagName('trk')?.[0]?.getElementsByTagName('name')?.[0]?.textContent;
name = metadataName || trkName || '';
// Get author from metadata
const author = gpx.getElementsByTagName('metadata')?.[0]?.getElementsByTagName('author')?.[0]?.getElementsByTagName('name')?.[0]?.textContent;
// Get description from metadata
const description = Array.from(metadata?.children || [])
.find(child => child.tagName === 'desc')?.textContent;
const getCoordinates = (inputElement: Document, tagName: string): LatLngLiteral[] => {
const elements = inputElement.getElementsByTagName(tagName);
const ret: LatLngLiteral[] = [];
@@ -123,19 +140,21 @@ export class MapService {
};
const trksegs = gpx.getElementsByTagName('trkseg');
if (!trksegs) {
return {
name: gpx.getElementsByTagName('name')?.[0]?.textContent || '',
name,
author,
description,
path: [getCoordinates(gpx, 'trkpt')],
markers: getCoordinates(gpx, 'wpt'),
};
}
const trksegArr = [].slice.call(trksegs);
return {
name: gpx.getElementsByTagName('name')?.[0]?.textContent || '',
name,
author,
description,
path: [...trksegArr].map(t => getCoordinates(t, 'trkpt')),
markers: getCoordinates(gpx, 'wpt'),
};
}
}