John Allen - GEO.Coordinate-0.01

Documentation | Source

NAME

GEO.Coordinate - Geographic coordinate manipulation class

SYNOPSIS

    // Import From JSAN
    JSAN.use( 'GEO.Coordinate' );

    var bigben = new GEO.Coordinate(51.5007);
        bigben.toDMS();

DESCRIPTION

GEO.Coordinate is a class for manipulating geographic corodinates.

Constructor

  var coord = new GEO.Coordinate(decimaldegrees);
  var coord = new GEO.Coordinate(degrees, decimalminutes);
  var coord = new GEO.Coordinate(degrees, minutes, seconds);

Returns a new GEO.Coordinate object. The following parameters can be passed to the constructor: - one parameter a coordinate in decimal degrees e.g. 51.5007 - two parameters are decimal minutes e.g. 51 30.04' - three parameters are degrees, minutes and seconds e.g. 51 30' 2.52"

METHODS

toDMS() This method will return the coordinate in degrees, minutes and seconds, the seconds will be returned at the specified precision.

Example: var coord = new GEO.Coordinate(51.5007); coord.toDMS(2);

Returns: 51 30' 2.52"

toDecDeg()

This method will return the coordinate in decimal degrees, the decimals will be returned at the specified precision.

Example: var coord = new GEO.Coordinate(51, 30, 2.52); coord.toDecDeg(2);

Returns: 51.50

toDecMin()

This method will return the coordinate in decimal minutes, the minute decimals will be returned at the specified precision.

Example: var coord = new GEO.Coordinate(51, 30, 2.52); coord.toDecDeg(2);

Returns: 51 30.04'

AUTHOR

John Allen <john@thoofooz.com>

COPYRIGHT

  Copyright (c) 2005 John Allen.  All rights reserved.
        This library is free software; you can redistribute it and/or modify
        it under the same terms as Perl.
/*
 * A JavaScript geographic coordinate manipulation class.
 * Version 0.01 Copyright (C) John Allen <john@thoofooz.com>.
 * Distributed under the Perl License
 */

/*

=head1 NAME

GEO.Coordinate - Geographic coordinate manipulation class

=head1 SYNOPSIS

    // Import From JSAN
    JSAN.use( 'GEO.Coordinate' );

    var bigben = new GEO.Coordinate(51.5007);
	bigben.toDMS();

=head1 DESCRIPTION

GEO.Coordinate is a class for manipulating geographic corodinates.
	
=head1 Constructor

  var coord = new GEO.Coordinate(decimaldegrees);
  var coord = new GEO.Coordinate(degrees, decimalminutes);
  var coord = new GEO.Coordinate(degrees, minutes, seconds);

Returns a new C<GEO.Coordinate> object. The following parameters can be
passed to the constructor:
- one parameter a coordinate in decimal degrees e.g. 51.5007
- two parameters are decimal minutes e.g. 51 30.04'
- three parameters are degrees, minutes and seconds e.g. 51 30' 2.52"

=cut

*/

if (!GEO) var GEO = {};

GEO.Coordinate = function (p1, p2, p3) {
	if (p1 && p2 && p3) {
		this._deg = p1;
		this._min = p2;
		this._sec = p3;
		this._dmstodecdeg();
		this._dmstodecmin();
	} else {
		if (p1 && p2) {
			this._decmin_deg = p1;
			this._decmin_min = p2;
			this._decmintodecdeg();
			this._decdegtodms();
		} else {
			this._dec_deg_deg = p1;
			this._decdegtodms();
			this._dmstodecmin();
		}
	}
};

GEO.Coordinate.EXPORT = [ 'fOne' ];

GEO.Coordinate.fOne = function (list) {
}

GEO.Coordinate.VERSION = '0.01';

GEO.Coordinate.prototype = {
	_deg: null,
	_min: null,
	_sec: null,
	_decmin_deg: null,
	_decmin_min: null,
	_dec_deg_deg: null,

	_dmstodecdeg: function () {
		if (this._deg >= 0) {
			this._dec_deg_deg = this._deg + this._min/60 + this._sec/3600;
		} else {
			this._dec_deg_deg = this._deg - this._min/60 - this._sec/3600;
		}
	},

	_dmstodecmin: function () {
		this._decmin_deg = parseInt(this._dec_deg_deg);
		var d = Math.abs(this._dec_deg_deg - this._deg) * 3600;
		this._decmin_min = d / 60;
	},

	_decmintodecdeg: function () {
		if (this._decmin_deg >= 0) {
			this._dec_deg_deg = this._decmin_deg + this._decmin_min/60;
		} else {
			this._dec_deg_deg = this._decmin_deg - this._decmin_min/60;
		}
	},

	_decdegtodms: function () {
		this._deg = parseInt(this._dec_deg_deg);
		var d = Math.abs(this._dec_deg_deg - this._deg) * 3600;
		this._min = parseInt(d / 60);
		this._sec = d - (this._min * 60);
	},

/*

=head1 METHODS

=head2 toDMS()
This method will return the coordinate in degrees, minutes and seconds, the 
seconds will be returned at the specified precision.

Example:
	var coord = new GEO.Coordinate(51.5007);
	coord.toDMS(2);

Returns:
	51 30' 2.52"

=head2 toDecDeg()

This method will return the coordinate in decimal degrees, the 
decimals will be returned at the specified precision.

Example:
	var coord = new GEO.Coordinate(51, 30, 2.52);
	coord.toDecDeg(2);

Returns:
	51.50

=head2 toDecMin()

This method will return the coordinate in decimal minutes, the 
minute decimals will be returned at the specified precision.

Example:
	var coord = new GEO.Coordinate(51, 30, 2.52);
	coord.toDecDeg(2);

Returns:
	51 30.04'

=cut

*/
	toDMS: function (precision) {
		var p = precision || 0;
		return this._deg + ' ' + this._min + '\' ' + this._sec.toFixed(p) + '"';
	},

	toDecDeg: function (precision) {
		var p = precision || 0;
		return this._dec_deg_deg.toFixed(p);
	},

	toDecMin: function (precision) {
		var p = precision || 0;
		return this._decmin_deg + ' ' + this._decmin_min.toFixed(p) + '\'';
	}

};

/*

=head1 AUTHOR

John Allen <F<john@thoofooz.com>>

=head1 COPYRIGHT

  Copyright (c) 2005 John Allen.  All rights reserved.
	This library is free software; you can redistribute it and/or modify
	it under the same terms as Perl.

=cut

*/