Skip to content
Snippets Groups Projects
Commit 2f8424e0 authored by Your Name's avatar Your Name
Browse files

added points from backend to the map

parent 553fbe28
No related branches found
No related tags found
1 merge request!120Resolve "Tentar fazer com que os pins sejam colocados dinamicamente"
......@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import * as L from 'leaflet';
import { PopUpService } from './pop-up.service';
import { HospitalService } from '../hospital.service';
@Injectable()
......@@ -10,22 +10,25 @@ export class MarkerService {
capitals: string = '/assets/data/usa-capitals.geojson';
constructor(private http: HttpClient,private popupService: PopUpService) {
constructor(private http: HttpClient,
private popupService: PopUpService,
private hospitalService: HospitalService) {
}
makeCapitalMarkers(map: L.map): void {
this.http.get(this.capitals).subscribe((res: any) => {
for (const c of res.features) {
const lat = c.geometry.coordinates[0];
const lon = c.geometry.coordinates[1];
const marker = L.marker([lon, lat]);
marker.bindPopup(this.popupService.makeCapitalPopup(c.properties));
marker.addTo(map);
}
});
this.hospitalService.getHospitals()
.subscribe(data => {
for (let hospital of data) {
let marker = L.marker([
hospital.geo_lat,
hospital.geo_long
])
let properties = {
name: hospital.hospital_name,
city: hospital.hospital_city
}
marker.bindPopup(this.popupService.makeCapitalPopup(properties));
marker.addTo(map);
}
})
}
}
......@@ -6,7 +6,7 @@ export class PopUpService {
constructor() { }
makeCapitalPopup(data: any): string {
return `` +
`<div>Hospital: ${ data.state }</div>` +
`<div>Cidade: ${ data.name }</div>` ;
`<div>Hospital: ${ data.name }</div>` +
`<div>Cidade: ${ data.city }</div>` ;
}
}
......@@ -14,7 +14,6 @@ import { FormBuilder, FormGroup } from '@angular/forms';
export class HospitalService {
private hospitalURL = environment.webserviceUrl+"/api/data";
//get: private hospitalURL = environment.webserviceUrl+"/api/data/listagents";
httpOptions = { headers: new HttpHeaders({ }) };
......@@ -45,6 +44,13 @@ export class HospitalService {
);
}
getHospitals(): Observable<any> {
return this.http.get(this.hospitalURL+"/listagents")
.pipe(
tap(_ => console.log('fetched hospitals')),
catchError(this.handleError<Observable<any>>()));
}
private handleError<T> (result?: T) {
return (error: any): Observable<T> => {
console.error(error);
......
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-49.238800,
-25.453400
]
},
"properties": {
"state": "Erasto Gaertner",
"name": "Curitiba",
"population": 350395
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-49.231700,
-25.4505
]
},
"properties": {
"state": "C3SL",
"name": "Curitiba",
"population": 350395
}
}
]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment