Commit 124ab4a4 authored by Thomas Frion's avatar Thomas Frion

[FEAT] Try go get IGN MAP

* Update api module to get the token (synchronize)
* Get all module
parent 7b116931
import { Component, OnInit } from '@angular/core';
import * as L from 'leaflet';
import { UnitSetting, UnitModel } from '../services/api/models/unit';
import { environment } from '../../environments/environment'
import * as models from '../services/api/models/models';
import { ServiceApi } from '../services/api/clients/service.api';
import { AuthGuard } from '../services/auth-guard.service';
import { environment } from '../../environments/environment';
/**
* @MapComponent:
......@@ -14,43 +16,54 @@ import { environment } from '../../environments/environment'
styleUrls: ['./map.component.scss']
})
export class MapComponent implements OnInit {
//<img style="height: 25px; width: 25px;" title="Institut national de l\'information géographique et forestière" src="http://wxs.ign.fr/static/logos/IGN/IGN.gif">
private readonly attributions = {
ign: 'Choucas | <a href="http://www.ign.fr/" target="_blank">'+'<img style="height: 25px; width: 25px;" title="Institut national de l\'information géographique et forestière" src="http://wxs.ign.fr/static/logos/IGN/IGN.gif"></a>',
ign: 'Choucas | <a href="http://www.ign.fr/" target="_blank">IGN-F/Geoportail</a>',
osm: '&copy; <a href="http://www.openstreetmap.org/copyright" target="_blank"> OpenStreetMap</a> contributors | Choucas',
otm: '&copy; <a href="http://garmin.opentopomap.org/#right">OpentTopoMap</a> | Choucas'
};
private unit : models.UnitModel;
private service : models.Service[];
private map;
private unit : UnitModel;
private tiles;
constructor() {
this.unit = new UnitModel(
constructor(private auth : AuthGuard, private serviceApi : ServiceApi) {
this.unit = new models.UnitModel(
JSON.parse(localStorage.getItem(environment.localStorage.unit))
);
// https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png
this.tiles = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: this.attributions.osm + ' | ' + this.attributions.otm,
// this.tiles = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
// maxZoom: 19,
// attribution: this.attributions.osm + ' | ' + this.attributions.otm,
});
// });
}
ngOnInit(): void {
let marker = L.marker(this.getCoor(this.unit.geom));
this.map = L.map('map', {
center: this.getCoor(this.unit.geom),
zoom: this.unit.getSetting(UnitSetting.SettingName.Zoom).value, //unit.settings[0].value,
minZoom: 4,
maxZoom: 17,
worldCopyJump: true
});
marker.bindPopup("<b>" + this.unit.code + "</b> <br>" + this.unit.name);
this.tiles.addTo(this.map);
marker.addTo(this.map);
this.serviceApi.all().then((res) => {
let url : string;
url = res[0].baseUrl.replace('{key}', res[0].key) + "?layer=" + res[0].serviceSettings[2].value + res[0].serviceSettings[0].value;
this.tiles = L.tileLayer(url, {
maxZoom: 19,
attribution: this.attributions.osm + ' | ' + this.attributions.otm,
});
let marker = L.marker(this.getCoor(this.unit.geom));
this.map = L.map('map', {
center: this.getCoor(this.unit.geom),
zoom: this.unit.getSetting(models.UnitSetting.SettingName.Zoom).value, //unit.settings[0].value,
minZoom: 4,
maxZoom: 17,
worldCopyJump: true
});
marker.bindPopup("<b>" + this.unit.code + "</b> <br>" + this.unit.name);
this.tiles.addTo(this.map);
marker.addTo(this.map);
});
}
private getCoor(geom : string) : number[] {
......
......@@ -17,13 +17,15 @@ export abstract class ApiService<T> {
*/
protected defaultHeaders : HttpHeaders;
constructor(protected http: HttpClient, protected authGuard ?: AuthGuard) {
constructor(protected http: HttpClient, protected authGuard : AuthGuard) {
this.defaultHeaders = new HttpHeaders({
'Content-Type':'application/json',
});
if(authGuard !== undefined){
this.defaultHeaders = this.defaultHeaders.append('Authorization', 'Bearer ' + this.authGuard.getToken());
this.authGuard.getToken().then((token) => {
this.defaultHeaders = this.defaultHeaders.append('Authorization', 'Bearer ' + token);
});
}
}
......@@ -35,7 +37,7 @@ export abstract class ApiService<T> {
protected get(resource : string, headers? : HttpHeaders) : Promise<T[]> {
if(headers !== undefined)
this.defaultHeaders = headers;
return this.http.get<T[]>(
this.baseUrl + resource,
{headers: this.defaultHeaders}
......
......@@ -8,7 +8,7 @@ import { ApiService } from '../api.service';
export class TokenApi extends ApiService<models.Token> {
constructor(protected http: HttpClient) {
super(http);
super(http, undefined);
this.defaultHeaders = new HttpHeaders({
'Content-Type':'application/json'
......
......@@ -24,16 +24,8 @@ export class AuthGuard implements CanActivate {
}
}
getToken() : string {
let res : string;
this.authService.getToken().then(
(r) => {
res = r;
}
)
return res;
async getToken() : Promise<string> {
return await this.authService.getToken();
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment