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
| var map;
var geocoder;
var tableauPointsPolyline = [];
var tableauPointsPolylineFait = [];
$(document).ready(function(){
initialize();
getWPActu();
});
/**** GESTION DE GOOGLE MAP ****/
function initialize() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("ourTravelActu"),mapOptions);
}
/****************************************/
/**** AJOUTER UN MARQUEUR pour previ */
/****************************************/
function codeAddress(address) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
animation: google.maps.Animation.DROP,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function getLat(address) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
return results[0].geometry.location;
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
/****************************************/
/**** Récupération des WP de la BDD */
/****************************************/
function getWPActu(){
tableauPointsPolyline = [];
tableauPointsPolylineFait = [];
var jqxhr = $.getJSON("./ScriptAJAX/getWPActu.php",{date:new Date()}, function() {}).success(function(data) { fillInPoly(data) }).complete(function() { drawPoly();});
}
/* on charge les deux tableaux pour les polyline, un contenant les passages effectués, l'autre l'ensemble */
function fillInPoly(wp) {
// var wp = eval("(" + wep + ")");
for(var i=0;i<wp.length;i++){
if(wp[i].etat==1){
tableauPointsPolylineFait.push(new Array(wp[i].titre,wp[i].lat,wp[i].lng,wp[i].desc,wp[i].date,wp[i].lien));
}
tableauPointsPolyline.push(new Array(wp[i].titre,wp[i].lat,wp[i].lng,wp[i].desc,wp[i].date,wp[i].lien));
}
}
/* On dessin les lignes et Marqueurs */
function drawPoly()
{
var flightPlanCoordinates = new Array();
var flightPlanCoordinatesFait = new Array();
var oMarker, oInfo;
var i, j, nb = tableauPointsPolyline.length;
var nbFait = tableauPointsPolylineFait.length;
oInfo = new google.maps.InfoWindow();
map = new google.maps.Map(document.getElementById("ourTravelActu"),{
'zoom' : 4,
'mapTypeId' : google.maps.MapTypeId.ROADMAP
});
if(nb>0)
{
for( i = 0; i < nb; i++){
flightPlanCoordinates.push(new google.maps.LatLng(tableauPointsPolyline[i][1],tableauPointsPolyline[i][2]));
oMarker = new google.maps.Marker({
'position' : new google.maps.LatLng( tableauPointsPolyline[i][1], tableauPointsPolyline[i][2]),
'map' : map,
'title' : tableauPointsPolyline[i][0],
'desc' : tableauPointsPolyline[i][3],
'lien' : tableauPointsPolyline[i][5]
});
if(tableauPointsPolyline[i][3]!="" || tableauPointsPolyline[i][5]!=""){
google.maps.event.addListener( oMarker, 'mouseover', function() {
if(this.lien!="") oInfo.setContent("<div style=height:150px;min-width:400px;text-align:left><h3>"+this.title+"</h3><p>"+this.desc+"</p><a target='_blank' href='"+this.lien+"&k=pays'> Vous souhaitez en savoir plus sur ce pays? Cliquez ici</a></div>");
else oInfo.setContent("<div style=height:150px;min-width:400px;text-align:left><h3>"+this.title+"</h3><p>"+this.desc+"</p></div>");
oInfo.open( this.getMap(), this);
});
}
else{
google.maps.event.addListener( oMarker, 'mouseover', function() {
oInfo.close();
$(this).css('cursor','default');
});
}
}
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#0000FF",
strokeOpacity: 0.5,
strokeWeight: 1,
zIndex : 1
});
flightPath.setMap(map);
}
if(nbFait>0){
for( j = 0; j < nbFait; j++){
flightPlanCoordinatesFait.push(new google.maps.LatLng(tableauPointsPolylineFait[j][1],tableauPointsPolylineFait[j][2]));
}
var flightPathFait = new google.maps.Polyline({
path: flightPlanCoordinatesFait,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 4,
zIndex : 2
});
flightPathFait.setMap(map);
map.setCenter(new google.maps.LatLng( tableauPointsPolylineFait[nbFait-1][1], tableauPointsPolylineFait[nbFait-1][2]));
}
} |
Partager