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
| <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>infoWindow.setContent()</title>
<style type="text/css">
html, body{
margin:0;
padding:0;
height:100%;
font-size : 1em;
font-family: verdana;
}
#map_canvas{
width:600px;
height:600px;
margin:50px auto;
border:1px solid #808080;
}
.infobulle{
font-size:.75em;
overflow-x:hidden;
}
.infobulle h1{
font-size : 2.0em;
color:#1F4E9E;
background-color:#A4C0EF;
border:1px solid #5E81BE;
margin:0;
padding:2px;
}
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="util.js"></script>
<script type="text/javascript" >
var infowindow;
var oMap;
function initCarte(){
var myLatlng = new google.maps.LatLng( 46.80, 1.70);
var myOptions = {
'zoom': 6,
'center': myLatlng,
'mapTypeId': google.maps.MapTypeId.ROADMAP
}
oMap = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
downloadUrl("moredata.xml", function(data) {
var markers = data.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var latlng = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng"))
);
// récupération du lien
var sInfo = markers[i].getAttribute("lien");
var sImage = markers[i].getAttribute("image");
var marker = createMarker( markers[i].getAttribute("name"), latlng, sInfo, sImage);
}
});
}
function createMarker( name, latlng, lien, image){
var oMarker = new google.maps.Marker({
'position': latlng,
'map': oMap
});
google.maps.event.addListener( oMarker, "click", function() {
if( infowindow){
infowindow.close();
}
// création du contenu HTML
var sTxt = name ? '<h1>' +name +'<\/h1>': '';
sTxt += image ? '<br><img src="' +image +'">' : '';
sTxt += lien ? '<br><a href="' +lien +'" target="__">' +lien +'<\/a>' : '';
infowindow = new google.maps.InfoWindow({
'content': '<div class="infobulle">' + sTxt +'<br> <\/div>'
});
infowindow.open( this.getMap(), this);
});
//changement sur le mouseover
google.maps.event.addListener( oMarker, 'mouseover', function(){
if( !this.flagIcon){
this.savIcon = this.getIcon(); // récupération de l'image via la méthode getIcon()
this.flagIcon = true;
}
this.setIcon( 'http://www.photos-et-panoramas.fr/sph/pictures/photo.png');
});
//restauration sur le mouseout
google.maps.event.addListener( oMarker, 'mouseout', function(){
this.setIcon( this.savIcon);
});
//fin changement icone
return oMarker;
}
// init lorsque la page est chargée
google.maps.event.addDomListener( window, 'load', initCarte);
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html> |
Partager