var map; var elemDetails=new Array(); var elemTrack=new Array(); var polyline_id=null; var polyline_w=null; function GPXParser(xmlDoc) { this.xmlDoc = xmlDoc; } GPXParser.prototype.getTrackpoints = function () { var tracks = this.xmlDoc.documentElement.getElementsByTagName("trk"); var points = new Array(); for (var i=0; i < tracks.length; i++) { var track = tracks[i]; var segments = track.getElementsByTagName("trkseg"); for (var i=0; i < segments.length; i++) { var trackSegment = segments[i]; var trackpoints = trackSegment.getElementsByTagName("trkpt"); if (trackpoints.length == 0) { continue; } for (var i=0; i < trackpoints.length; i++) { var lon = parseFloat(trackpoints[i].getAttribute("lon")); var lat = parseFloat(trackpoints[i].getAttribute("lat")); points.push(new google.maps.LatLng(lat,lon)); } } } return points; } function initGGMaps() { directionsDisplay = new google.maps.DirectionsRenderer(); geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(46.830134,1.7570801); var options = { mapTypeControl: true, navigationControl: true, center: latlng, mapTypeId: google.maps.MapTypeId.TERRAIN }; map = new google.maps.Map(document.getElementById("map_canvas"), options); loadTrack(); } function loadTrack(idTrace) { var xhr_object = null; if(window.XMLHttpRequest) { // Firefox xhr_object = new XMLHttpRequest(); xhr_object.overrideMimeType('text/xml'); } else if(window.ActiveXObject) // IE xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); if(xhr_object != null) { xhr_object = new XMLHttpRequest(); xhr_object.onreadystatechange = function() { if (xhr_object.readyState == 4) { //Chargement OK var parser = new GPXParser(xhr_object.responseXML); var data = parser.getTrackpoints(); elemTrack[idTrace]=data; displayTrack(idTrace); } }; xhr_object.open("GET", "" , true); xhr_object.send(null); } } function displayTrack(elemid) { if (elemTrack[elemid]) { displayTrackImpl(elemid); } else { loadTrack(elemid); } } function displayTrackImpl(elemid) { if (polyline_w) { polyline_w.setMap(null); polyline_w=null; } //line params var lineColor="#0033FF"; var polyline = new google.maps.Polyline({ path: elemTrack[elemid], strokeColor: lineColor, strokeOpacity: 0.8, strokeWeight: 4 }); polyline.setMap(map); polyline_id=elemid; polyline_w=polyline; map.fitBounds(getBounds(elemTrack[elemid])); } function getBounds(latLngArray) { var i; var minLat = latLngArray[0].lat(); var maxLat = latLngArray[0].lat(); var minLng = latLngArray[0].lng(); var maxLng = latLngArray[0].lng(); for (i=1 ; i ll.lat()) minLat = ll.lat(); else if (maxLat < ll.lat()) maxLat = ll.lat(); if (minLng > ll.lng()) minLng = ll.lng(); else if (maxLng < ll.lng()) maxLng = ll.lng(); } var ne = new google.maps.LatLng(minLat,minLng); var sw = new google.maps.LatLng(maxLat,maxLng); return new google.maps.LatLngBounds(ne,sw); }