Commit 29396548 authored by Thomas Frion's avatar Thomas Frion

[UPDF] Center of map

Now we center the map with the unit's coordinates of the user. The used zoom is the zoom define for the unit
parent 2491a040
import { Component, OnInit } from '@angular/core';
import * as L from 'leaflet';
import { Unit } from '../services/api/models/unit';
import { environment } from '../../environments/environment'
/**
* @MapComponent:
......@@ -17,9 +19,10 @@ export class MapComponent implements OnInit {
constructor() { }
ngOnInit(): void {
const unit : Unit = JSON.parse(localStorage.getItem(environment.localStorage.unit));
this.map = L.map('map', {
center: [ 45.21811, 5.85113 ],
zoom: 17
center: this.getCoor(unit.geom),
zoom: unit.settings[0].value
});
const tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
......@@ -29,4 +32,21 @@ export class MapComponent implements OnInit {
tiles.addTo(this.map);
}
private getCoor(geom : string) : number[] {
let parts = geom.split(';');
let center = [ 45.21811, 5.85113 ];
if(parts.length == 2){
parts = parts.pop().split(' ');
if(parts.length == 3){
center = [
Number(parts[2].substr(0,parts[2].length -1)),
Number(parts[1].substr(1)),
];
}
}
return center;
}
}
......@@ -31,7 +31,7 @@ export interface Unit{
code: string,
name: string,
email: string,
geoem: string,
geom: string,
dept: string,
settings: UnitSetting[]
}
\ No newline at end of file
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