2018-11-26 07:26:29 +08:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-03-03 17:30:12 +08:00
|
|
|
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';
|
2019-07-21 01:52:47 +08:00
|
|
|
import MapLayers = ClientConfig.MapLayers;
|
2018-11-26 07:26:29 +08:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class MapService {
|
2019-07-21 01:52:47 +08:00
|
|
|
private static readonly OSMLAYERS = [{name: 'street', url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'}];
|
|
|
|
private static MAPBOXLAYERS: MapLayers[] = [];
|
2018-11-26 07:26:29 +08:00
|
|
|
|
|
|
|
constructor(private networkService: NetworkService) {
|
2019-07-21 01:52:47 +08:00
|
|
|
MapService.MAPBOXLAYERS = [{
|
|
|
|
name: 'street', url: 'https://api.tiles.mapbox.com/v4/mapbox.streets/{z}/{x}/{y}.png?access_token='
|
|
|
|
+ Config.Client.Map.mapboxAccessToken
|
|
|
|
}, {
|
|
|
|
name: 'satellite', url: 'https://api.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png?access_token='
|
|
|
|
+ Config.Client.Map.mapboxAccessToken
|
|
|
|
}, {
|
|
|
|
name: 'hybrid', url: 'https://api.tiles.mapbox.com/v4/mapbox.streets-satellite/{z}/{x}/{y}.png?access_token='
|
|
|
|
+ Config.Client.Map.mapboxAccessToken
|
2018-11-26 07:26:29 +08:00
|
|
|
}
|
2019-07-21 01:52:47 +08:00
|
|
|
];
|
2018-11-26 07:26:29 +08:00
|
|
|
}
|
|
|
|
|
2018-12-08 18:28:56 +08:00
|
|
|
public get ShortAttributions(): string[] {
|
|
|
|
const yaga = '<a href="https://yagajs.org" title="YAGA">YAGA</a>';
|
|
|
|
const lf = '<a href="https://leaflet-ng2.yagajs.org" title="Leaflet in Angular2">leaflet-ng2</a>';
|
|
|
|
const OSM = '<a href="https://www.openstreetmap.org/copyright">OSM</a>';
|
|
|
|
const MB = '<a href="https://www.mapbox.com/">Mapbox</a>';
|
|
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2018-12-08 05:06:13 +08:00
|
|
|
public get Attributions(): string[] {
|
2018-12-08 18:28:56 +08:00
|
|
|
const yagalf = '<a href="https://yagajs.org" title="YAGA">YAGA</a> | ' +
|
|
|
|
'<a href="https://leaflet-ng2.yagajs.org" title="Leaflet in Angular2">leaflet-ng2</a>';
|
|
|
|
const OSM = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>';
|
|
|
|
const MB = '© <a href="https://www.mapbox.com/">Mapbox</a>';
|
|
|
|
|
|
|
|
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];
|
2018-12-08 05:06:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public get MapLayer(): string {
|
2019-07-21 01:52:47 +08:00
|
|
|
return this.Layers[0].url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get Layers(): { name: string, url: string }[] {
|
|
|
|
switch (Config.Client.Map.mapProvider) {
|
|
|
|
case ClientConfig.MapProviders.Custom:
|
|
|
|
return Config.Client.Map.customLayers;
|
|
|
|
case ClientConfig.MapProviders.Mapbox:
|
|
|
|
return MapService.MAPBOXLAYERS;
|
|
|
|
case ClientConfig.MapProviders.OpenStreetMap:
|
|
|
|
return MapService.OSMLAYERS;
|
2018-12-08 05:06:13 +08:00
|
|
|
}
|
2019-07-21 01:52:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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({
|
|
|
|
lat: parseFloat(elements[i].getAttribute('lat')),
|
|
|
|
lng: parseFloat(elements[i].getAttribute('lon'))
|
|
|
|
});
|
2018-12-08 18:28:56 +08:00
|
|
|
}
|
2019-07-21 01:52:47 +08:00
|
|
|
return points;
|
2018-12-08 05:06:13 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|