mapIntervalID = null; function refreshMap(){ if(mapIntervalID!=null){ clearTimeout(mapIntervalID); } mapIntervalID = setTimeout("refreshMapTimeout('advertsGMaps')", 75); } xmlhttpRefreshMap=null; function refreshMapTimeout(func){ if (xmlhttpRefreshMap==null) xmlhttpRefreshMap = newAjax(); var fromCountry = document.getElementById("fromCountryGM").value; var fromProvince = document.getElementById("fromProvinceGM").value; var fromCity = document.getElementById("fromCityGM").value; var toCountry = document.getElementById("toCountryGM").value; var toProvince = document.getElementById("toProvinceGM").value; var toCity = document.getElementById("toCityGM").value; map.clearOverlays(); resetLimits(); var urlServlet = "sharelingServlet.php"; var paramsGET = "?func="+func+"&fromCountry="+fromCountry+"&fromProvince="+fromProvince+"&fromCity="+fromCity+"&toCountry="+toCountry+"&toProvince="+toProvince+"&toCity="+toCity; if(xmlhttpRefreshMap.readyState!=2 && xmlhttpRefreshMap.readyState!=3){ callAjax(callbackRefreshMap, paramsGET, urlServlet, xmlhttpRefreshMap); } } function callbackRefreshMap(xmlhttp){ var stretchsDemands = xmlhttp.responseXML.getElementsByTagName("demand"); drawStretchs(stretchsDemands, "#ffb100"); var stretchsOffers = xmlhttp.responseXML.getElementsByTagName("offer"); drawStretchs(stretchsOffers, "#19aea2"); var num = stretchsDemands.length + stretchsOffers.length; if(num==0){ map.setCenter(new google.maps.LatLng(40.416706, -3.703269), 1); }else{ showAllPoints(); } } function drawStretchs(stretchs, color){ for(i=0; i< stretchs.length; i++){ var fromLat = stretchs[i].getAttribute("fromLat"); var fromLng = stretchs[i].getAttribute("fromLng"); var toLat = stretchs[i].getAttribute("toLat"); var toLng = stretchs[i].getAttribute("toLng"); var pointA = new google.maps.LatLng(fromLat, fromLng); var pointB = new google.maps.LatLng(toLat, toLng); drawLine(pointA, pointB, color); } } function drawLine(pointA, pointB, color){ var linePoints = []; linePoints.push(pointA); linePoints.push(pointB); setLimits(pointA); setLimits(pointB); map.addOverlay(new google.maps.Polyline(linePoints, color, 2, 1)); }