Commit cc697243 authored by Thomas Frion's avatar Thomas Frion

[FEAT] Get all Gendarmerie units

* Get all units and show them
parent 2aa3f2ee
import { Component, OnInit } from '@angular/core';
import { HttpClient } from "@angular/common/http";
import * as L from 'leaflet';
import * as models from '../services/api/models/models';
......@@ -27,24 +28,23 @@ export class MapComponent implements OnInit {
private map;
private baseMap;
private marker;
private tiles;
private gendarmeries;
constructor(private auth : AuthGuard, private serviceApi : ServiceApi) {
constructor(
private auth : AuthGuard,
private serviceApi : ServiceApi,
private http : HttpClient
) {
this.unit = new models.UnitModel(
JSON.parse(localStorage.getItem(environment.localStorage.unit))
);
);
let coordinates = this.getCoor(this.unit.geom);
this.marker = L.marker(coordinates);
this.marker.bindPopup("<b>" + this.unit.name + "</b> (" + this.unit.code + ") <br>"+
"<a href='mailto:" + this.unit.email + "'>" + this.unit.email + "</a><br><br>" +
"<b>Lat: </b>"+ coordinates[0] +", <b>Lon: </b>" + coordinates[1] + "<br>" +
MapComponent.ddToDMS(coordinates[0],coordinates[1]));
// //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,
// });
}
ngOnInit(): void {
......@@ -56,7 +56,7 @@ export class MapComponent implements OnInit {
if(elem.name != 'IGN'){
this.baseMap[elem.name] = L.tileLayer(elem.baseUrl,{
maxZoom: 19,
attribution: setting.getSetting('attribution')
attribution: setting.getSetting('attribution').value
})
}
// DON'T REMOVE THE COMMENTED CODE BELOW
......@@ -79,6 +79,8 @@ export class MapComponent implements OnInit {
layers: [this.baseMap['OTM']]
});
this.getGendarmeries();
L.control.layers(this.baseMap).addTo(this.map);
this.marker.addTo(this.map);
this.marker.openPopup();
......@@ -144,4 +146,27 @@ export class MapComponent implements OnInit {
return deg + "° " + min + "' " + sec+"''";
}
private getGendarmeries() : void {
const url = "https://static.data.gouv.fr/resources/liste-des-unites-de-gendarmerie-accueillant-du-public-comprenant-leur-geolocalisation-et-leurs-horaires-douverture/20200525-050031/export-gn2.csv";
this.http.get(url,{responseType: 'text'}).subscribe(data => {
let csvRows = data.split("\n");
for(let i = 1; i < csvRows.length - 1; i++){
const row = csvRows[i].split(';').map(this.removeQuote);
let marker = L.marker([row[13], row[12]]);
marker.bindPopup(
"<b>" + row[1] + "</b><br><br>" + row[3] + "<br>" + row[2]
);
marker.addTo(this.map);
}
},
err => {
console.log(err);
})
}
private removeQuote(str : string ) : string {
return str.split('"').join("");
}
}
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