/* * Script d'affichage des markers sur la map google . Ce script est publié sous licence GPL * date : 2006-03-07 * http://www.gnu.org/copyleft/gpl.html * Vous pouvez le modifier librement et le redistribuer. * Merci de m'indiquer tout bug, incompatibilité, amélioration * à admins at ubuntu-fr */ // Create our "tiny" marker icon var baseIcon = new GIcon(); /*baseIcon.image = "user.png";*/ baseIcon.iconSize = new GSize(16, 16); baseIcon.shadowSize = new GSize(0, 0); baseIcon.iconAnchor = new GPoint(8, 15); baseIcon.infoWindowAnchor = new GPoint(8, 0); var map; var timeOut = 1; var i = 0; var markers; var geocoder; function onLoad() { map = new GMap2(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(47.4578,2.373047),5); geocoder = new GClientGeocoder(); var request = GXmlHttp.create(); request.open("GET", "/data.xml?dep=", true); request.onreadystatechange = function() { if (request.readyState == 4) { var xmlDoc = request.responseXML; markers = xmlDoc.documentElement.getElementsByTagName("marker"); mapMarkerRecursive(); request.onreadystatechange = processReqChange; } } request.send(null); } /* * Thanks Pyg de Framasoft pour celle la, bien jolie ;-) */ function mapMarkerRecursive() { document.getElementById('counter').innerHTML = i + " / " + markers.length; // Update the loading window document.getElementById("info_map").innerHTML = (i) ; if ( i < markers.length) { var marker = createMarker(markers[i]); // create point map.addOverlay(marker); // Draw point i++; window.setTimeout(mapMarkerRecursive,timeOut); } else { document.getElementById('loading').style.visibility='hidden'; // No more points to draw, // hide the loading window... map.setCenter(new GLatLng(47.4578,2.373047),5); } } function processReqChange() { response = req.responseXML.documentElement; method = response.getElementsByTagName('method')[0].firstChild.data; result = response.getElementsByTagName('result')[0].firstChild.data; alert(method + '(\'\', result)'); eval(method + '(\'\', result)'); } function isParam(attr,marker) { if ( marker.getAttribute(attr) ) { return marker.getAttribute(attr); } else { return ''; } } function createHtml(marker) { var nom = isParam("nom",marker); var prenom = isParam("prenom",marker); var type = isParam("type",marker); var ville = isParam("ville",marker); var titre = isParam("titre",marker); var pa = isParam("pa",marker); var annonce = isParam("annonce",marker); // Show this marker's index in the info window when it is clicked var html = "
"; html += "
" + titre + "
"; html += "
Annonce de : " + prenom + " " + nom + "
"; html += "
" + annonce + "...
Lire la suite
"; html += "
Ville : " + ville + "
"; // html += "
Ville : " + ville + "
"; html += "
"; return html; } // Creates a marker whose info window displays the given number function createMarker(m) { var icon = new GIcon(baseIcon); switch (m.getAttribute("type")) { case "demipension": icon.image = "/images/cross_dp.png"; break; case "divers": default: icon.image = "/images/cross_divers.png"; break; } var point = new GPoint(parseFloat(m.getAttribute("lng")),parseFloat(m.getAttribute("lat"))) var marker = new GMarker(point,icon); GEvent.addListener(marker, "click", function() { // If clicked print descr. marker.openInfoWindowHtml(createHtml(m)); }); return marker; } function showAddress(address) { // geocoder.getLatLng( geocoder.getLocations( address, function(data) { if (data.Status.code != 200) switch (data.Status.code) { case G_GEO_BAD_KEY: alert('Mauvaise Cle Google Maps'); break; case G_GEO_UNKNOWN_ADDRESS: alert('Ville incorrect'); break; default: alert('Error '+data.Status.code); } Point = new GLatLng(data.Placemark[0].Point.coordinates[1], data.Placemark[0].Point.coordinates[0]); if (!Point) { alert(address + " : inconnu ("+data.Status.code+")"); } else { map.setCenter(Point, 12); var marker = new GMarker(Point); map.addOverlay(marker); } } ); }