1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
export class MarkerService {
constructor(private http: HttpClient, private router:Router) { }
public makeStationMarkers(map: L.Map): void {
const that = this;
fetch('https://api.jcdecaux.com/vls/v1/stations?contract=cergy-pontoise&apiKey=c90a137bb16a557c0dc0362a3606b71ce06515fe')
.then((resp) => resp.json())
.then(function(data) {
for(let coords of data){
L.marker([coords.position.lat, coords.position.lng])
.bindPopup(`
<h3>${coords.name}</h3>
<p>${coords.address}</p>
<p>${coords.available_bikes}</p>
<button id="toto">Réserver un vélo</button>
`)
.on('click',()=>{
console.log('click!!!!')
map.flyTo([coords.position.lat,coords.position.lng]);
}).addTo(map);
}
});
document.getElementById("toto") ?.addEventListener('click', function(){
console.log("test3");
that.router.navigate(['app-bookink', {id: this.id}]);
});
}
} |