import {Injectable} from '@angular/core'; import {NetworkService} from '../../model/network/network.service'; import {FileDTO} from '../../../../common/entities/FileDTO'; import {Utils} from '../../../../common/Utils'; import {Config} from '../../../../common/config/public/Config'; import {ClientConfig} from '../../../../common/config/public/ConfigClass'; @Injectable() export class MapService { constructor(private networkService: NetworkService) { } public async getMapPath(file: FileDTO): Promise { const filePath = Utils.concatUrls(file.directory.path, file.directory.name, file.name); const gpx = await this.networkService.getXML('/gallery/content/' + filePath); const elements = gpx.getElementsByTagName('trkpt'); const points: MapPath[] = []; for (let i = 0; i < elements.length; i++) { points.push({ lat: parseFloat(elements[i].getAttribute('lat')), lng: parseFloat(elements[i].getAttribute('lon')) }); } return points; } public get ShortAttributions(): string[] { const yaga = 'YAGA'; const lf = 'leaflet-ng2'; const OSM = 'OSM'; const MB = 'Mapbox'; if (Config.Client.Map.mapProvider === ClientConfig.MapProviders.OpenStreetMap) { return [yaga + ' | © ' + OSM]; } if (Config.Client.Map.mapProvider === ClientConfig.MapProviders.Mapbox) { return [yaga + ' | ' + OSM + ' | ' + MB]; } return [yaga + ' | ' + lf]; } public get Attributions(): string[] { const yagalf = 'YAGA | ' + 'leaflet-ng2'; const OSM = '© OpenStreetMap'; const MB = '© Mapbox'; if (Config.Client.Map.mapProvider === ClientConfig.MapProviders.OpenStreetMap) { return [yagalf + ' | ' + OSM]; } if (Config.Client.Map.mapProvider === ClientConfig.MapProviders.Mapbox) { return [yagalf + ' | ' + OSM + ' | ' + MB]; } return [yagalf]; } public get MapLayer(): string { if (Config.Client.Map.mapProvider === ClientConfig.MapProviders.Custom) { return Config.Client.Map.tileUrl; } if (Config.Client.Map.mapProvider === ClientConfig.MapProviders.Mapbox) { return 'https://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.png?access_token=' + Config.Client.Map.mapboxAccessToken; } return 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; } } export interface MapPath { lat: number; lng: number; }