"+dragMarkerMsg;
me.openInfoWindowHtml(""+homeDataStrings[0][0]+commuteString+" "+dragMarkerMsg;
(homeLocMarkers[addressNum]).openInfoWindowHtml(""+tmp+homeDataStrings[addressNum][0]+commuteString+" ');
infoWindow.document.write('
"+homeDataStrings[0][1]+dragMarkerString);
}
};
})(homeLocMarkers[0]));
GEvent.addListener(homeLocMarkers[0], "click", (function(me, locCenter) {
return function()
{
if (activateRouteListener == 0)
return;
var currPnt = me.getLatLng();
//user clicked again on the same point - ignore
if (currPnt.equals(latestRoute[latestRoute.length-1]))
return;
//add new stop to the array
latestRoute.push(locCenter);
latestRouteLabels.push("Home");
//create number icon
(numberMarkerArray[latestRoute.length]).setLatLng(currPnt);
map.addOverlay(numberMarkerArray[latestRoute.length]);
if (tmpPolyline)
map.removeOverlay(tmpPolyline);
tmpPolyline = new GPolyline(latestRoute, routeColors[(routeArray.length+1)%10], 2, 0.5);
map.addOverlay(tmpPolyline);
//assuming that all routes start and end at home -
//finish this route if we are back home
if (latestRoute.length == 1)//start new route
{
}
else if (latestRoute.length > 1)
{
stopCommuteRoute();
}
};
})(homeLocMarkers[0], locCenter));
GEvent.addListener(homeLocMarkers[0], "dragstart", (function(me) {
return function() {
me.closeInfoWindow();
if (circleLine)
map.removeOverlay(circleLine);
};
})(homeLocMarkers[0]));
GEvent.addListener(homeLocMarkers[0], "dragend", (function(me) {
return function() {
oph_status = 5;
var currPnt = me.getLatLng();
for(var i=0; i<3; i++)
homeDataStrings[0][i] = "";
reverseGeocode(currPnt);
mapBounds.extend(currPnt);
map.panTo(mapBounds.getCenter());
map.setZoom(map.getBoundsZoomLevel(mapBounds));
drawCircle(currPnt, 1);
computeDrivingDistGivenRoutes(currPnt, 0, false);
};
})(homeLocMarkers[0]));
(homeLocMarkers[0]).disableDragging();
map.addOverlay(homeLocMarkers[0]);
(homeLocMarkers[0]).openInfoWindowHtml("Central location
"+homeDataStrings[0][0]+"
"+homeDataStrings[0][1]+homeDataStrings[0][2]);
drawCircle(locCenter, 1);
//initialize weights array
weightsArray = [];
for (var i=0; i![]()
Central location most probably is not your Optimal Home Location. Please define your commute pattern to find the Optimal Home Location, which minimizes commute for your family.");
}
}
function addRoute() {
routeMarkConfusion = false;
oph_status = 3;
if (optimalLocationComputed)
{
if (confirm("Your Optimal Home Location has already been defined. Would you like us to return house icon back to the Central location so you can add routes for additional people to your commute and then recalculate your Optimal Home Location?"))
{
compOptRequestAttmpts = 0;
(homeLocMarkers[0]).setLatLng(locCenter);
for(var i=0; i<3; i++)
homeDataStrings[0][i] = "";
reverseGeocode(locCenter);
computeDrivingDistGivenRoutes(locCenter, 0, false);
}
else
return;
}
numCommuters++;
var msg = "Define route for Commuter #";
msg += numCommuters;
msg += "
Click on the map location icons in the order this person visits them.
Each route should start and end at home icon.
For example: Home -> School 1 -> Work 1 -> Home.";
alert(msg);
compOptRequestAttmpts = 0;
activateRouteListener = 1;
if (latestRoute.length >0)
{
stopCommuteRoute();
}
}
function computeOptimalHomeLocation(){
routeMarkConfusion = false;
if (!geocoder)
return;
if (routeArray.length == 0)
{
alert("Press Add new route button and define daily commutes for each member of your family. Optimal home location will minimize the total combined commute.");
return;
}
activateRouteListener = 0;
if (getNumValidLocations() == 0)
{
alert( "Please enter addresses that you will be commuting from (work, school, day care).");
return;
}
//remove control temporarily to disable zoom
map.removeControl(mapControl);
//allocate arrays
var num_locations = getNumValidLocations()+1;
var url = "ComputeLocation.php?";
var params = "num_locations=" + num_locations;
//call php script to compute
var validI = 0;
for(var i=0; i< locationArray.length; i++)
if (locationArray[i] != null)
{
validI++;
//var pel = map.fromLatLngToDivPixel(locationArray[i].getPoint());
var w_w = weightsArray[i];
params += "&w"+validI+"_x=" + locationArray[i].getPoint().lat() + "&w"+validI+"_y=" + locationArray[i].getPoint().lng() + "&w"+validI+"_w=" + w_w;
}
compOptRequestAttmpts++;
GDownloadUrl(url, function(data, responseCode)
{
if(responseCode == -1) {
var msg = "Your internet connection seems to be non-stable. Google Map request to draw driving routes has timed out.";
if (compOptRequestAttmpts==1)
msg += "We will try to repeat the request.";
alert(msg);
if (compOptRequestAttmpts==1)
computeOptimalHomeLocation();
} else if(responseCode != 200){
alert("Request resulted in error.");
return;
}
if (data.length > 1)
{
oph_status = 4;
optimalLocationComputed = true;
var string = data;
var split_string = string.split(" ");
var centerX = split_string[0];
var centerY = split_string[1];
var totalCommute = split_string[2];
var centralLocationCommute = split_string[3];
point = new GLatLng(parseFloat(centerX), parseFloat(centerY));
//add control back
map.addControl(mapControl);
if (!point)
{
alert( " Optimal location not found");
}
else
{
for (var i=0; i<3; i++)
homeDataStrings[0][i] = "";
reverseGeocode(point);
map.panTo(mapBounds.getCenter());
map.setZoom(map.getBoundsZoomLevel(mapBounds));
drawCircle(point, 1);
ophLatLng = point;
(homeLocMarkers[0]).setLatLng(point);
computeDrivingDistGivenRoutes(point, 0, true);
}
}
}, params);
}//end of function
//Given routes defined by the routeArray substitute each locCenter with locOptimal and sum driving distances
var routesComputed;
function computeDrivingDistGivenRoutes(currHomeLoc, addressNum, isOptimal){
for(var i = 0; i < polylineArray.length; i++)
{
map.removeOverlay(polylineArray[i]);
}
polylineArray = [];
routesComputed = 0;
homeDataStrings[addressNum][3] = 0;
homeCommuteDurations[addressNum] = 0;
for(var route=0; route< routeArray.length; route++)
{
var query = new Array();
for (var routeStop=0; routeStop ![]()
You can drag this icon to see commute for other possible home locations.
Proceed to Compare Commutes tab to preview and compare commutes from any real estate listings or use Area Details tab to map local attractions.");
}
else
{
var idString = "addressForm_"+addressNum;
document.getElementById(idString).innerHTML = ( " " + Math.round(homeDataStrings[addressNum][3]*0.0621371192237334)/100 + " miles.");
}
var tmp = new String("");
if (isOptimal)
{
tmp = "Your optimal home location
";
ophAreaAttractions();
}
else
tmp = "";
var commuteString = (homeDataStrings[addressNum][3]>0 ? ("
commute: "+Math.round(homeDataStrings[addressNum][3]*0.0621371192237334)/100 + " miles.") : "");
if (addressNum == 0 && oph_status == 4)
homeDataStrings[5][3] = homeDataStrings[0][3];
var dragMarkerString = "";
if(addressNum == 0)//only for optimal
dragMarkerString = "
"+homeDataStrings[addressNum][1]+homeDataStrings[addressNum][2]+dragMarkerString);
if(addressNum == 0)//only for optimal
(homeLocMarkers[addressNum]).enableDragging();
}
};
})(route, gdir));
GEvent.addListener(gdir, "error", handleErrorsOpt);
gdir.loadFromWaypoints(query, {preserveViewport:true, getPolyline:true});
}
if (isOptimal)
{
document.getElementById("news").style.display = 'none';
document.getElementById("top_report_link").style.display = 'block';
var params = "city=" + currCity[5] + "&state=" + currState[5];
//document.getElementById("rotating_space").innerHTML = '';
//document.getElementById("kw").innerHTML = '';
}
}
function showCommuteForAddress(address, addressNum, state){
if (address == "")
{
alert("No address entered.");
return;
}
if(routeArray.length == 0)
{
alert("You need to define locations you are visiting and your commute routes first.
Start with Your Life and Your Commute Tabs.");
return;
}
if (state == 2)//delete this home icon and commutes
{
//remove marker
map.removeOverlay(homeLocMarkers[addressNum]);
//remove driving routes
for(var i = 0; i < polylineArray.length; i++)
{
map.removeOverlay(polylineArray[i]);
}
polylineArray = [];
routesComputed = 0;
//clear text entry
var compFormObj = document.getElementById("CompareCommutesForm"+(addressNum.toString()));
compFormObj.home_address.value = "";
for(var i=0; i<3; i++)
homeDataStrings[addressNum][i] = "";
homeDataStrings[addressNum][3] =0;
var idString = "addressForm_"+addressNum;
document.getElementById(idString).innerHTML = "";
}
else
{
(homeLocMarkers[0]).closeInfoWindow();
if (geocoder) {
geocoder.getLocations(
address,
function(response) {
if (!response || response.Status.code != 200) {
alert("Sorry, address not found. Please check your submission and try again.");
} else {
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
homeDataStrings[addressNum] = new Array(4);
homeDataStrings[addressNum][0] = address;
homeDataStrings[addressNum][1] = new String("");
homeDataStrings[addressNum][2] = new String("");
homeDataStrings[addressNum][3] = 0;
var parsedAddressArray = address.split(" ");
currCity[addressNum] = new String("");
currState[addressNum] = new String("");
for (var i=parsedAddressArray.length-1; i>=0; i--)
if (parsedAddressArray[i].length > 1)
{
if (currState[addressNum] == "")
{
currState[addressNum] = parsedAddressArray[i];
continue;
}
if (currCity[addressNum] == "")
{
currCity[addressNum] = parsedAddressArray[i];
break;
}
}
formatAndCallDemographics(addressNum);
homeIcon.image = homeIconSrc+addressNum+".jpg";
homeIcon.printImage = homeIcon.image;
homeIcon.mozPrintImage = homeIcon.image;
var markerOptions = { icon:homeIcon, draggable:false };
if (homeLocMarkers[addressNum] != null)
{
map.removeOverlay(homeLocMarkers[addressNum]);
homeLocMarkers[addressNum] = null;
}
homeLocMarkers[addressNum] = new GMarker(point, markerOptions);
homeDataStrings[addressNum][1] = new String("");
GEvent.addListener(homeLocMarkers[addressNum], "click", (function(num) {
return function() {
var commuteString = (homeDataStrings[num][3]>0 ? ("
commute: "+Math.round(homeDataStrings[num][3]*0.0621371192237334)/100 + " miles.") : "");
(homeLocMarkers[num]).openInfoWindowHtml(""+homeDataStrings[num][0]+commuteString+"
"+homeDataStrings[num][1]+homeDataStrings[num][2]);
};
})(addressNum));
map.addOverlay(homeLocMarkers[addressNum]);
mapBounds.extend(point);
map.panTo(mapBounds.getCenter());
map.setZoom(map.getBoundsZoomLevel(mapBounds));
computeDrivingDistGivenRoutes(point, addressNum, false);
}
}
);
}
}
}
function debug(data){
//if (doDebug)
document.getElementById("debug").innerHTML += data;
}
//function that makes DIV hidden or visible
function toggleDIVVisibility(szDivID, iState) // 1 visible, 0 hidden
{
var obj = document.getElementById(szDivID);
if (iState == 1)
obj.style.display = 'block';
else
obj.style.display = 'none';
/* if(document.layers) //NN4+
{
document.layers[szDivID].visibility = iState ? "show" : "hide";
}
else if(document.getElementById) //gecko(NN6) + IE 5+
{
var obj = document.getElementById(szDivID);
obj.style.visibility = iState ? "visible" : "hidden";
}
else if(document.all) // IE 4
{
document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
}*/
}
function startRouteDescription(){
if (polylineArray.length>0 || latestRoute.length >0)
{
alert("Attention! Clearing existing routes.");
clearRouteDescription();
}
activateRouteListener = 1;
if (latestRoute.length >0)
{
latestRoute = [];
latestRouteLabels = [];
}
}
function clearLatestRoute(){
//if latest route has not been added to the array
if (latestRoute && latestRoute.length > 0)
{
for( var i =0; i < latestRoute.length; i++)
{
//remove number Marker
map.removeOverlay(numberMarkerArray[i+1]);
numberMarkerArray[i+1].setLatLng(new GLatLng(0,0));
}
if (tmpPolyline)
{
map.removeOverlay(tmpPolyline);
tmpPolyline = null;
}
}
else //if latest route has already been counted
{
if (polylineArray.length == 0)
return;
latestPolyline = polylineArray.pop();
latestRoute = routeArray.pop();
map.removeOverlay(latestPolyline);
//remove last route description line
var routeDescrMsg = document.getElementById("message").innerHTML;
var lastLineBreak = routeDescrMsg.lastIndexOf("Route");
if (lastLineBreak == 0)
document.getElementById("message").innerHTML = "";
else
{
var newRouteDescMsg = routeDescrMsg.substring(0, lastLineBreak-1);
document.getElementById("message").innerHTML = newRouteDescMsg;
}
//update segment weights
for(var i=0; i< latestRoute.length; i++)
if ((latestRoute[i]).equals(locCenter)) //segment to-from home
{
if (i-1 >0)
if (!((latestRoute[i-1]).equals(locCenter)))
{
reduceWeightToSegment(latestRoute[i-1]);
}
if (i+1 < latestRoute.length-1)
if (!((latestRoute[i+1]).equals(locCenter)))
{
reduceWeightToSegment(latestRoute[i+1]);
}
}
}
latestRoute = [];
latestRouteLabels = [];
numCommuters--;
activateRouteListener = 0;
optimalLocationComputed = false;
optLocationValid = true;
centralMarkerMoveAllowed = false;
for(var i=0; i<3; i++)
homeDataStrings[0][i] = "";
homeDataStrings[0][3] = 0;
(homeLocMarkers[0]).setLatLng(locCenter);
(homeLocMarkers[0]).closeInfoWindow();
drawCircle(locCenter, 1);
for (var i=1; i<5; i++)
if (homeLocMarkers[i])
map.removeOverlay(homeLocMarkers[i]);
}
function clearRouteDescription(){
oph_status = 2;
numCommuters = 0;
if (latestRoute && latestRoute.length > 0)
for( var i =0; i < latestRoute.length; i++)
{
//remove number Marker
map.removeOverlay(numberMarkerArray[i+1]);
numberMarkerArray[i+1].setLatLng(new GLatLng(0,0));
}
if (tmpPolyline)
{
map.removeOverlay(tmpPolyline);
tmpPolyline = null;
}
activateRouteListener = 0;
for(var i = 0; i < polylineArray.length; i++)
{
map.removeOverlay(polylineArray[i]);
}
polylineArray = [];
homeCommuteDurations[0] = 0;
optLocationValid = true;
centralMarkerMoveAllowed = false;
routeArray = [];
latestRoute = [];
latestRouteLabels = [];
setTab(2);
(homeLocMarkers[0]).disableDragging();
(homeLocMarkers[0]).closeInfoWindow();
for(var i=0; i<3; i++)
homeDataStrings[0][i] = "";
homeDataStrings[0][3] = 0;
(homeLocMarkers[0]).setLatLng(locCenter);
drawCircle(locCenter, 1);
for (var i=1; i<5; i++)
if (homeLocMarkers[i])
map.removeOverlay(homeLocMarkers[i]);
document.getElementById("message").innerHTML = ("");
optimalLocationComputed = false;
}
function stopCommuteRoute(){
var routeDescription = "Route #"+numCommuters+": ";
gdir = new GDirections();
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrorsCenter);
var query = new Array();
for( var i =0; i < latestRoute.length; i++)
{
query.push(latestRoute[i]);
routeDescription += latestRouteLabels[i];
if (i != latestRoute.length-1)
routeDescription += "->";
//remove number Marker
map.removeOverlay(numberMarkerArray[i+1]);
numberMarkerArray[i+1].setLatLng(new GLatLng(0,0));
}
gdir.loadFromWaypoints(query, {preserveViewport:true,getPolyline:true});
//add latest route to routeArray
routeArray.push(latestRoute);
document.getElementById("message").innerHTML += routeDescription+"
";
//update segment weights
for(var i=0; i< latestRoute.length; i++)
if ((latestRoute[i]).equals(locCenter)) //segment to-from home
{
if (i-1 >0)
if (!((latestRoute[i-1]).equals(locCenter)))
{
addWeightToSegment(latestRoute[i-1]);
}
if (i+1 < latestRoute.length-1)
if (!((latestRoute[i+1]).equals(locCenter)))
{
addWeightToSegment(latestRoute[i+1]);
}
}
//clear latestRoute array to prepare for new route
latestRoute = [];
latestRouteLabels = [];
routeMarkConfusion = true;
setTimeout("checkConfusion()", 15000);
}
function onGDirectionsLoad(){
//Display the route.
//remove temp polyline sketch before drawing actual route
if (tmpPolyline)
{
map.removeOverlay(tmpPolyline);
tmpPolyline = null;
}
latestPolyline = gdir.getPolyline();
latestPolyline.color = routeColors[routeArray.length%10];
map.addOverlay(latestPolyline);
polylineArray.push(latestPolyline);
homeDataStrings[0][3] += gdir.getDistance().meters;
homeCommuteDurations[0] += gdir.getDuration().seconds;
}
function checkConfusion() {
if (routeMarkConfusion)
{
alert("To enter additional route press Add route for new person button.
When you finished defining routes for each adult and kid in the family - press Compute Optimal Home Location button.");
}
}
function handleErrorsOpt() {
optLocationValid = false;
handleErrors();
}
function handleErrorsCenter() {
handleErrors();
//use tmpPolyline instead if Google map polyline is not available
latestPolyline = tmpPolyline;
latestPolyline.color = routeColors[routeArray.length%10];
tmpPolyline = null;
map.addOverlay(latestPolyline);
polylineArray.push(latestPolyline);
}
function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_KEY)
alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_UNKNOWN_DIRECTIONS)
{
//alert("Google driving route information that we rely upon unfortunately is not available for this route.")
}
else alert("An unknown error occurred.\n Error code: " + gdir.getStatus().code);
//clear latestRoute array to prepare for new route
latestRoute = [];
latestRouteLabels = [];
}
function addWeightToSegment(routePoint){
for (var i=0; i
If you would like more information, please see our About or Help Forms.
', 700);
}
function showReportSample(){
window.open('./reportSampleNew.html',"Report",'left=20,top=20,width=850,height=900,toolbar=0,resizable=Yes,scrollbars=1,menubar=1');
}
function showInfo(data, infoWinWidth){
var scrollOffsets = getScrollXY();
var winSize = getWinSize();
document.getElementById("info").innerHTML = data;
document.getElementById("infoWindow").style.width = infoWinWidth.toString() + "px";
document.getElementById("infoWindow").style.top = (scrollOffsets[1]+(winSize[1]-300) / 2).toString() + "px";
document.getElementById("infoWindow").style.left = (scrollOffsets[0]+(winSize[0] - infoWinWidth) / 2).toString() + "px";
document.getElementById("infoWindow").style.display = 'block';
}
function getWinSize() {
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
return [myWidth, myHeight];
}
function getScrollXY() {
var scrOfX = 0, scrOfY = 0;
if( typeof( window.pageYOffset ) == 'number' ) {
//Netscape compliant
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
//DOM compliant
scrOfY = document.body.scrollTop;
scrOfX = document.body.scrollLeft;
} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
//IE6 standards compliant mode
scrOfY = document.documentElement.scrollTop;
scrOfX = document.documentElement.scrollLeft;
}
return [ scrOfX, scrOfY ];
}
function drawCircle(centerPoint, radiusMiles)
{
var zoom = map.getZoom();
var normalProj = G_NORMAL_MAP.getProjection();
var centerPt = normalProj.fromLatLngToPixel(centerPoint, zoom);
var circlePoints = new Array();
with (Math) {
var radiusPix = radiusMiles * 10 * zoom;
for (var a = 0 ; a < 361 ; a+=10 ) {
var aRad = a*(PI/180);
var y = centerPt.y + radiusPix * sin(aRad)
var x = centerPt.x + radiusPix * cos(aRad)
var p = new GPoint(x,y);
circlePoints.push(normalProj.fromPixelToLatLng(p, zoom));
}
if (circleLine)
map.removeOverlay(circleLine);
circleLine = new GPolyline(circlePoints,"#b62020",10,0.5);
map.addOverlay(circleLine);
}
}
function closeInfo(data){
document.getElementById("infoWindow").style.display = 'none';
}
function showInfoOld(data){
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;
var w = Math.max(document.body.clientWidth / 2, 500);
var h = 200;
var xc = ( aw - w ) / 2;
var yc = ( ah - h ) / 2;
var infoWindow = window.open("","","directories=0,toolbar=0,menubar=0,location=0,titlebar=0,dependent=1,resizable=1,status=0,scrollbars=0,left="+xc+",top="+yc+",width="+w+",height="+h);
infoWindow.document.write('');
infoWindow.document.write('');
infoWindow.document.write('');
infoWindow.document.write('