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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
import java.util.ArrayList;
import java.util.Arrays;
import com.google.gwt.core.client.JavaScriptObject;
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
public class Map {
/*
* initialise la map
*/
public native JavaScriptObject initMap() /*-{
var map;
var latlng = new $wnd.google.maps.LatLng(50.56, 4.25);
var myOptions = {
zoom : 9,
center : latlng,
mapTypeId : $wnd.google.maps.MapTypeId.ROADMAP
}
return map = new $wnd.google.maps.Map($doc.getElementById("map"), myOptions);
}-*/;
public native JavaScriptObject loadMarker(JavaScriptObject map /*, ArrayList <Parc> parcList*/) /*-{
//construit mon array de parcs
var parcIndex = 0;
//tableau de parcs
var parcList = new Array();
parcList[parcIndex++] = new Array ("50.49391", "5.057552");
//...
//...
parcList[parcIndex++] = new Array ("50.2562656", "4.422377");
//nombre total de parcs
var nbTotalDeParcs = parcList.length;
var homeLatLong; //coordonnées du point d'arrivee
var infowindow; //infobulle
var lIcon = "images/limite_petit.png"; //icone
var marker; //marker
var lHhtml; //contenu de l'infobulle
var myLatlng; //coordonnées des marqueurs
var from; //point de départ
//initialise l'infowindow
infowindow = new $wnd.google.maps.InfoWindow({
// content: lHhtml
});
//place le point d'arrivée en utilisant la géolocalisation
var address = "rue Auber, Paris"; //adress
var lIcon = "images/limite_petit.png"; //icone
// Déclaration et instanciation du geocoder
//PLACE LE MARKER DU POINT D'ARRIVEE
var geocoder;
geocoder = new $wnd.google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == $wnd.google.maps.GeocoderStatus.OK) {
// map.setCenter(results[0].geometry.location);
marker = new $wnd.google.maps.Marker({
map: map,
position: results[0].geometry.location,
icon : new $wnd.google.maps.MarkerImage(lIcon,
new $wnd.google.maps.Size(30, 30))
});
//sauvegarde de la position du point d'arrivée
homeLatLong = marker.position;
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
//icone en fonction de l'état, test à mettre en place
var imageNOTDispo = "images/NotClosed.png";
var imageDispo = "images/Closed.png";
var panel; //panel
//mettre la création du DirectionsRenderer aura pour effet de rendre possible la superposition de plusieurs itinéraires
var direction = new $wnd.google.maps.DirectionsRenderer({
map : map,
panel : panel
});
//ajout des marqueurs
for (var i = 0; i < nbTotalDeParcs; i++)
{
//récupère un objet donc un futur marqueur
var parc = parcList[i];
myLatlng = new $wnd.google.maps.LatLng( parc[0] , parc[1] );
//lattitude + longitude de mon point de départ donc d'un parc
from = "" + parc[0] + "," + parc[1];
//contenu de l'infobulle
lHhtml = '<div style="float:left;text-align:left;">'
+ '<font size="1" color="blue">' + parc[2] + '<br> '
+ parc[3] + ' ' + parc[4] + '<br>' + parc[5] + '</font>'
+ '</div>';
//crée le marqueur
marker = new $wnd.google.maps.Marker({
position: myLatlng,
map: map,
title: parc[2] + "\r\n" + parc[3] + "\r\n" + parc[5] ,
icon : new $wnd.google.maps.MarkerImage(imageDispo,
new $wnd.google.maps.Size(30, 30))
});
//EVENEMENT SUR CHAQUE MARQUEUR
// Stockage infowindow pour open sur click
marker._infowindow = infowindow;
//stocke le contenu de l'infowindow sélectionnée
marker._lHhtml = lHhtml;
//stockage du from
marker._from = from;
// ajoute l'action sur onclick
$wnd.google.maps.event.addListener(marker, 'click', function (){
//si une infowindow est ouverte, on la ferme
if (infowindow) {
infowindow.close();
// direction.suppressMarkers = true;
}
//puis set le contenu de l'infowindow sélectionnée
infowindow.setContent(this._lHhtml);
this._infowindow.open( map, this);
//CREE L'ITINERAIRE
var panel = panel;
origin = this._from; // Le point départ
destination = homeLatLong; // Le point d'arrivé - est marqué undefined
if(origin && destination){
var request = {
origin : origin,
destination : destination,
travelMode : $wnd.google.maps.DirectionsTravelMode.DRIVING // Type de transport
}
var directionsService = new $wnd.google.maps.DirectionsService(); // Service de calcul d'itinéraire
directionsService.route(request, function(response, status){ // Envoie de la requête pour calculer le parcours
if(status == $wnd.google.maps.DirectionsStatus.OK){
direction.setDirections(response); // Trace l'itinéraire sur la carte et les différentes étapes du parcours
direction.setPanel(document.getElementById("directionsPanel"));//panel
}
});
} //http://code.google.com/intl/fr-FR/apis/maps/documentation/javascript/reference.html#DirectionsRequest
});
}//FIN DE BOUCLE
}-*/;
} |
Partager