Commit 5a361e42 authored by Thomas Frion's avatar Thomas Frion

[UPDF] Display gendaremire markes at a specific zoom level

parent cc697243
......@@ -45,6 +45,7 @@ export class MapComponent implements OnInit {
"<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]));
this.getGendarmeries();
}
ngOnInit(): void {
......@@ -79,8 +80,7 @@ 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();
......@@ -107,6 +107,19 @@ export class MapComponent implements OnInit {
});
L.control.scale().addTo(this.map);
let gendLAyer = this.gendarmeries;
this.map.on("zoomend", function(){
if(this.getZoom() >= 12){
if(!this.hasLayer(gendLAyer)){
this.addLayer(gendLAyer);
}
}else{
if(this.hasLayer(gendLAyer)){
this.removeLayer(gendLAyer);
}
}
});
});
}
......@@ -148,6 +161,7 @@ export class MapComponent implements OnInit {
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.gendarmeries = L.layerGroup([]);
this.http.get(url,{responseType: 'text'}).subscribe(data => {
let csvRows = data.split("\n");
for(let i = 1; i < csvRows.length - 1; i++){
......@@ -156,12 +170,12 @@ export class MapComponent implements OnInit {
marker.bindPopup(
"<b>" + row[1] + "</b><br><br>" + row[3] + "<br>" + row[2]
);
marker.addTo(this.map);
this.gendarmeries.addLayer(marker);
}
},
err => {
console.log(err);
})
}
......
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