2018-11-26 07:26:29 +08:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {NetworkService} from '../../model/network/network.service';
|
|
|
|
import {FileDTO} from '../../../../common/entities/FileDTO';
|
|
|
|
import {Utils} from '../../../../common/Utils';
|
2018-12-08 05:06:13 +08:00
|
|
|
import {OSM_TILE_LAYER_URL} from '@yaga/leaflet-ng2';
|
|
|
|
import {Config} from '../../../../common/config/public/Config';
|
|
|
|
import {ClientConfig} from '../../../../common/config/public/ConfigClass';
|
2018-11-26 07:26:29 +08:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class MapService {
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private networkService: NetworkService) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async getMapPath(file: FileDTO): Promise<MapPath[]> {
|
|
|
|
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({
|
2018-12-08 05:06:13 +08:00
|
|
|
lat: parseFloat(elements[i].getAttribute('lat')),
|
|
|
|
lng: parseFloat(elements[i].getAttribute('lon'))
|
2018-11-26 07:26:29 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
2018-12-08 05:06:13 +08:00
|
|
|
|
|
|
|
public get Attributions(): string[] {
|
|
|
|
return ['© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public get MapLayer(): string {
|
|
|
|
if (Config.Client.Map.mapProvider === ClientConfig.MapProviders.Custom) {
|
|
|
|
return Config.Client.Map.tileUrl;
|
|
|
|
}
|
|
|
|
return OSM_TILE_LAYER_URL;
|
|
|
|
}
|
|
|
|
|
2018-11-26 07:26:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface MapPath {
|
2018-12-08 05:06:13 +08:00
|
|
|
lat: number;
|
|
|
|
lng: number;
|
2018-11-26 07:26:29 +08:00
|
|
|
}
|