Source Code for JavaScript Mapping Tools: wayPointsManager.js

Source code of a graphical tool for drawing and computing distances over Google maps.

Run Tool | index.html | main.css | formatters.js | geoCircle.js | geoCode.js | geo.js | index.js | mapControls.js | tableManager.js | util.js | wayPoint.js | wayPointsManager.js


// Copyright 2006-2008 (c) Paul Demers  <paul@acscdg.com>

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA., or visit one 
// of the links here:
//  http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
//  http://www.acscdg.com/LICENSE.txt

//////////////////////////////////////////////////////////////////

//
// Map drawing and distance tools.
// Web site with this code running: http://www.acscdg.com/

//
//  Utility object to manage a list of way points.  Way points are the points
//   along a course with multiple segments.
//

//
////
function wayPointsManagerNumberOfPoints()
{
  var numberOfPoints = this.wayPointsList.length;

  return numberOfPoints;
}

//
////
function wayPointsManagerPushWayPoint(wayPoint)
{
  if (this.wayPointsList != null)
    return this.wayPointsList.push(wayPoint);

  return null;
}

//
////
function wayPointsManagerGetFirstWayPoint()
{
  var firstWayPoint = null;
  if (this.numberOfPoints() > 0)
    firstWayPoint = this.wayPointsList[0];
  return firstWayPoint;
}


//
////
function removeLastWayPoint()
{
  var lastWayPoint = null;
  if (this.numberOfPoints() > 0)
    lastWayPoint = this.wayPointsList.pop();
  return lastWayPoint;
}

//
////
function getLastWayPoint()
{
  var lastWayPoint = null;
  var wayPointCount = this.numberOfPoints();
  if (wayPointCount > 0)
    lastWayPoint = this.wayPointsList[wayPointCount-1];

  return lastWayPoint;
}

//
//// The element list (the actual table rows) is exposed because it is used for temporary display.
function addWayPointTableElement(wayPoint)
{
  this.tBodyElement.appendChild(wayPoint.tableRowElement);
}

//
////
function removeWayPointTableElement(wayPoint)
{
  if (wayPoint.tableRowElement != null)
    this.tBodyElement.removeChild(wayPoint.tableRowElement);
}

//
////
function wayPointsUpdateElements(distanceUnits)
{
  for (var d = 0; d < this.wayPointsList.length; d++)
  {
    var wayPoint = this.wayPointsList[d];
    wayPoint.tableRowElement = wayPoint.updateElement(distanceUnits, wayPoint.tableRowElement);
  }
}


//
//// Object to hold wayPointslist:
function WayPointsManager(courseNumber, tBodyElement)
{
  this.numberOfPoints = wayPointsManagerNumberOfPoints;
  this.pushWayPoint = wayPointsManagerPushWayPoint;
  this.getFirstWayPoint = wayPointsManagerGetFirstWayPoint;
  this.getLastWayPoint = getLastWayPoint;
  this.removeLastWayPoint = removeLastWayPoint;
  this.addWayPointTableElement = addWayPointTableElement;
  this.removeWayPointTableElement = removeWayPointTableElement;
  this.updateElement = wayPointsUpdateElements;

  this.courseNumber = courseNumber;
  this.wayPointsList = new Array();
  this.tBodyElement = tBodyElement;  // pointer to the containing tbody element in the table.
}