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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
class MapApi{
constructor(){
this.url = "https://api.jcdecaux.com/vls/v1/stations?contract=Lyon&apiKey=e1ed98cd909b60fcdc3c4093cfc1734ab8c95fb6";
this.get_url();
}
initMap(){
depart = {lat: 45.755547, lng: 4.836044};
map = new google.maps.Map(document.getElementById("map"), {
zoom:11,
center: depart
})};
get_url() {
$.get(this.url, this.afficher).done(function(){});
}
afficher(data){
data.forEach(function(element){
var infowindow = new google.maps.InfoWindow({
content:'<div class="fenetreinfo">' +
'<h1>' + element.name + '</h1>' +
'<p> Adresse :' + element.address + '</p>' +
'<p> Disponibilite : </p>' +
'<p> position : ' + Object.values(element.position) + '</p>' +
'</div>',
pixelOffset: new google.maps.Size(300,100)
});
var marker = new google.maps.Marker({
position: element.position,
map: map,
title: element.name
});
marker.addListener('click', function(){
infowindow.open(map,marker);
});
});
}
}
// Lyon : 45.755547, 4.836044
var map;
function initMap(){
var myLatLng = {lat: 45.755547, lng: 4.836044};
map = new google.maps.Map(document.getElementById("map"), {
zoom:11,
center: myLatLng
});
}
mapapi = new MapApi(); |
Partager