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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
var url = 'https://opendata.paris.fr/api/records/1.0/search/?dataset=parcs-de-stationnement-concedes-de-la-ville-de-paris&rows=1000'
var tab = [];
// constructeur d'objet
function parkingSpot(geo, name, adress, tel, time, motorBike, bike){
this.geo = geo;
this.name = name;
this.adress = adress;
this.telephone = tel;
this.timeTable = time;
this.motorBikeAcces = motorBike;
this.bikeAcces = bike;
}
//Affiichage de la carte Bing Maps
function GetMap()
{
var myOptions = {
credentials: 'ApPosPKV1r####V9fpx_YULKyRhck#####Z2BT6XNNpeAC##UO7lN_m8L0Kp1e',
center: new Microsoft.Maps.Location(48.8534, 2.3488),
//mapTypeId: Microsoft.Maps.MapTypeId.aerial,
zoom: 12
}
map = new Microsoft.Maps.Map('#myMap', myOptions);
infobox = new Microsoft.Maps.Infobox(map.getCenter(), {
visible: false
});
infobox.setMap(map);
}
/Requete http
var request = new XMLHttpRequest();
request.open('GET', url);
request.responseType = 'JSON';
request.send();
request.onload = function(){
var req = JSON.parse(request.response);
//Récupération des informations du fichier json
for (var i = 0; i < test.records.length; i++){
tab.push(new parkingSpot(
req.records[i].fields["geo_point_2d"],
req.records[i].fields["nom_parc"],
req.records[i].fields["adress_ssc"],
req.records[i].fields["tel"],
req.records[i].fields["horaire_na"],
req.records[i].fields["acces_moto"],
req.records[i].fields["acces_velo"]
));
}
//Boucle permettant d'afficher les markeurs sur la carte
for (var i = 0; i < tab.length; i++){
center = new Microsoft.Maps.Location(tab[i].geo[0],tab[i].geo[1]);
pin = new Microsoft.Maps.Pushpin(center)
pin.metadata = {
title: tab[i].name,
description: tab[i].adress,
};
Microsoft.Maps.Events.addHandler(pin, 'click', pushpinClicked);
map.entities.push(pin)
}
// Affichage de l'infobox quand l'utilisateur clique sur un markeur
function pushpinClicked(e) {
if (e.target.metadata) {
infobox.setOptions({
location: e.target.getLocation(),
title: e.target.metadata.title,
description: e.target.metadata.adresse,
visible: true
});
}
}
}; |
Partager