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
| <!DOCTYPE html>
<html lang="fr">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>[Google Maps API V3] Placer plusieurs Markers #2</title>
<meta name="Author" content="NoSmoking">
<style type="text/css">
* {
font-family : Verdana, Arial;
font-size : 1em;
}
html, body {
height : 100%;
}
h1 {
color : #4488bb;
font-size : 1.3em;
margin : 0;
padding : 0.5em;
border : 1px solid #4488bb;
}
p {
font-size : 0.9em;
line-height : 1.5em;
margin : 5px;
margin-left : 1.0em;
padding : 0;
}
#page {
padding : 0.5em;
}
#div_main {
margin : auto;
width : 800px;
}
#div_map{
margin : auto;
margin-top : 1.0em;
width : 600px;
height: 600px;
border : 1px solid #c0c0c0;
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var tMarker = [
{ lat :45.767299, lon : 4.834329,
title : 'Lyon', info : '<b>Lyon<\/b><br>la suite du texte...'
},
{
lat : 48.856667, lon : 2.350987,
title : 'Paris', info : '<b>Paris<\/b><br>la suite du texte...'
},
{ lat : 44.837368, lon : -0.576144,
title : 'Bordeaux', info : '<b>Bordeaux<\/b><br>la suite du texte...'
},
{ lat :43.297612, lon : 5.381042,
title : 'Marseille', info : '<b onclick="alert(\'yes!\')">Marseille<\/b><br>la suite du texte...'
}
];
function initCarte(){
// init
var oCarte, oMarker, oInfo;
var i, nb = tMarker.length;
var mapOptions = {
backgroundColor : '#fff',
mapTypeControl : false,
streetViewControl : false,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
},
zoom : 6,
center : new google.maps.LatLng( 45.70, 3.0),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// creation de la carte
oCarte = new google.maps.Map(document.getElementById("div_map"), mapOptions);
// creation info bulle
oInfo = new google.maps.InfoWindow();
// creation des marqueurs
for( i = 0; i < nb; i++){
oMarker = new google.maps.Marker({
position : new google.maps.LatLng( tMarker[i].lat, tMarker[i].lon),
map : oCarte,
title : tMarker[i].title
});
// evenement sur click marker via fonction externe
setEventMarker( oMarker, oInfo, tMarker[i].info);
}
}
function setEventMarker( marker, infowindow, texte){
google.maps.event.addListener( marker, 'click', function() {
// affectation du texte
infowindow.setContent( texte);
// affichage InfoWindow
infowindow.open( this.getMap(), this);
});
}
google.maps.event.addDomListener(window, 'load', initCarte);
</script>
</head>
<body>
<div id="page">
<div id="div_main">
<h1>[Google Maps API V3] Placer plusieurs Markers #2</h1>
<p>
Le texte est passé en paramètre à une fonction externe.<br>
On affecte le texte à l'InfoWindow avant affichage.
</p>
<div id="div_map"></div>
</div>
</div>
</body>
</html> |
Partager