- add code for quering sos api

This commit is contained in:
Arno Kaimbacher 2021-08-06 15:12:58 +02:00
parent 5f2dd2851b
commit 5740a5ddc3
11 changed files with 321 additions and 58 deletions

View file

@ -0,0 +1,53 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import * as L from 'leaflet';
// @Injectable({
// // declares that this service should be created
// // by the root application injector.
// providedIn: 'root'
// })
@Injectable()
export class MarkerService {
private capitalsUrl: string = 'https://raw.githubusercontent.com/do-community/angular-leaflet-example/master/src/assets/data/usa-capitals.geojson';
constructor(private http: HttpClient) {
// this.http = http;
}
static scaledRadius(val: number, maxVal: number): number {
return 20 * (val / maxVal);
}
// makeCapitalMarkers(map: L.map): void {
// this.http.get(this.capitalsUrl).subscribe((res: any) => {
// for (const c of res.features) {
// const lon = c.geometry.coordinates[0];
// const lat = c.geometry.coordinates[1];
// const marker = new L.marker([lat, lon]);
// marker.addTo(map);
// }
// });
// }
makeCapitalCircleMarkers(map: L.Map): void {
this.http.get(this.capitalsUrl).subscribe((res: any) => {
let maxPop = Math.max(...res.features.map(x => x.properties.population), 0);
for (const c of res.features) {
const lon = c.geometry.coordinates[0];
const lat = c.geometry.coordinates[1];
// const circle = L.circleMarker([lat, lon]);
let circle = L.circleMarker([lat, lon], {
radius: MarkerService.scaledRadius(c.properties.population, maxPop)
});
circle.addTo(map);
}
});
}
}