var map; var mgr; var icons = {}; var allmarkers = []; var cameras = []; function loadGoogleMap(latitude, longitude, zoomLevel, tousLesAvis) { //(latitude:String, longitude:String, zoomLevel:Integer, tousLesAvis:Boolean) if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("map")); //Si une position GPS est fournie, centre la sur la carte, sinon utilise la position par défaut if ((latitude != "aucun") && (longitude != "aucun")) { var positionVoulue = new GLatLng(latitude, longitude); map.setCenter(positionVoulue, zoomLevel); } else map.setCenter(new GLatLng(46.3554800,-72.5991480), 11); //----- Prépare les paramètres par défaut de la carte var optionsDirection = { zoomInBtnTitle : "Rapprocher", zoomOutBtnTitle : "Éloigner", moveNorthBtnTitle : "Déplacer la carte vers le nord", moveSouthBtnTitle : "Déplacer la carte vers le sud", moveEastBtnTitle : "Déplacer la carte vers l'est", moveWestBtnTitle : "Déplacer la carte vers l'ouest", homeBtnTitle : "Retourner au point d'origine" }; if (tousLesAvis) var extLargeMapControl = new ExtLargeMapControl(optionsDirection); else var extLargeMapControl = new ExtLargeMapControl({type : "small", zoomInBtnTitle : "Rapprocher", zoomOutBtnTitle : "Éloigner"}); //map.enableDoubleClickZoom(); //map.enableScrollWheelZoom(); //map.addControl(new GMapTypeControl()); //Impossible d'utiliser "extLargeMapControl" avec Sattelite ou Mixed Mode map.addControl(extLargeMapControl); //map.addControl(new GLargeMapControl()); map.addControl(new MoreControl()); map.getContainer().appendChild(document.getElementById("box")); window.setTimeout("setupAvisDeTravaux(" + tousLesAvis + ")", 0); } } function getIcon(images, typeIcone) { var icon = null; if (images) { if (icons[images[0]]) { icon = icons[images[0]]; } else { icon = new GIcon(G_DEFAULT_ICON); icon.image = "/google_maps/icones_carte/" + images[0] + ".png"; var size = iconData[images[0]]; icon.iconSize = new GSize(size.width, size.height); icon.iconAnchor = new GPoint(size.width >> 1, size.height >> 1); if (typeIcone == "avis") { icon.shadow = null; icon.infoWindowAnchor = new GPoint(9, 2); } else if (typeIcone == "secteur") { var hauteur = size.height - 1; var largeur = size.width - 1; icon.imageMap = [0,hauteur, largeur,hauteur, largeur,0, 0,0]; //Dans Firefox, pour que l'icone soit cliquable en entier icon.shadow = null; } else if (typeIcone == "camera") { size = iconData[images[1]]; icon.shadow = "/google_maps/icones_carte/" + images[1] + ".png"; icon.shadowSize = new GSize(size.width, size.height); } else { icon.shadow = null; } icons[images[0]] = icon; } } return icon; } function setupAvisDeTravaux(tousLesAvis) { mgr = new MarkerManager(map, {trackMarkers:false}); var listeAvis; //Si on veut tous les avis de travaux, prendre le fichier complet, sinon le fichier avec un avis unique if (tousLesAvis) listeAvis = avisDeTravaux; else listeAvis = unAvisDeTravaux; allmarkers.length = 0; cameras.length = 0; for (var i in listeAvis) { var layer = listeAvis[i]; var markers = []; for (var j in layer["places"]) { var place = layer["places"][j]; var title = place["name"]; var typeIcone = place["type"]; var icon = getIcon(place["icon"], typeIcone); var infoBulle = place["info"]; var nivZoom = place["niveauZoom"]; var posn = new GLatLng(place["posn"][0], place["posn"][1]); var marker = createMarker(typeIcone,posn,title,icon,infoBulle,nivZoom); //Pour utiliser le bouton PLUS... correctement, il faut utiliser addOverlay if (typeIcone == "camera") map.addOverlay(marker); else { markers.push(marker); allmarkers.push(marker); } } mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]); } mgr.refresh(); if (!tousLesAvis) //Si c'est un avis unique, affiche son info-bulle par défaut { map.openInfoWindowHtml(map.getCenter(), infoBulle, {pixelOffset: new GSize(0, -7)}); } toggleCameras(); } function createMarker(typeIcone, posn, title, icon, infoBulle, nivZoom) { var marker = new GMarker(posn, {title: title, icon: icon, draggable:false }); if (typeIcone == "ville") { GEvent.addListener(marker, 'click', function() { map.setCenter(GLatLng(46.3554800,-72.5991480), nivZoom); }); } else if (typeIcone == "secteur") { GEvent.addListener(marker, 'click', function() { map.setCenter(posn,nivZoom); }); } else if (typeIcone == "camera") { cameras.push(marker); } if (infoBulle != "") { GEvent.addListener(marker, 'click', function() { //var tab1 = new GInfoWindowTab("Infos", "ceci est du blabla du tab Info"); //var tab2 = new GInfoWindowTab("Savoir plus", "ceci est aussi du blabla du tab En Savoir plus"); //marker.openInfoWindowTabs(new Array(tab1, tab2)); marker.openInfoWindowHtml(infoBulle); }); } return marker; } function toggleCameras() { for (var i = 0; i < cameras.length; i++) { var marker = cameras[i]; if (marker.isHidden()) { marker.show(); } else { marker.hide(); } } }