#571: Don't subclass Geometry.Point from LonLat, and all neccesary associated

changes. Reviewed by tschaub (thx)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@2943 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-03-31 18:30:56 +00:00
parent 45da80f8ad
commit 4aec64aa67
10 changed files with 67 additions and 110 deletions

View File

@@ -4,21 +4,12 @@
/**
* @class
*
* The Point class is a subclass of Geometry and also a subclass of the
* non-vector OpenLayers.LonLat class. The basic functionality that this adds
* is the ability to switch between lon/lat and x/y at will, as well some
* convenience functions to create a Bounds from a point and measure the
* distance between two points.
*
* getX() and setX() should be used to access the x or lon variables.
*
* @requires OpenLayers/BaseTypes.js
* @requires OpenLayers/Geometry.js
*/
OpenLayers.Geometry.Point = OpenLayers.Class.create();
OpenLayers.Geometry.Point.prototype =
OpenLayers.Class.inherit(OpenLayers.Geometry, OpenLayers.LonLat, {
OpenLayers.Class.inherit(OpenLayers.Geometry, {
/** @type float */
x: null,
@@ -34,10 +25,9 @@ OpenLayers.Geometry.Point.prototype =
*/
initialize: function(x, y) {
OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
OpenLayers.LonLat.prototype.initialize.apply(this, arguments);
this.x = this.lon;
this.y = this.lat;
this.x = parseFloat(x);
this.y = parseFloat(y);
},
/**
@@ -55,46 +45,12 @@ OpenLayers.Geometry.Point.prototype =
return obj;
},
/**
* Sets the x coordinate
*
* @param {float} x
*/
setX: function(x) {
this.lon = x;
this.x = x;
},
/**
* Sets the y coordinate
*
* @param {float} y
*/
setY: function(y) {
this.lat = y;
this.y = y;
},
/**
* @type float
*/
getX: function() {
return this.lon;
},
/**
* @type float
*/
getY: function() {
return this.lat;
},
/** Create a new Bounds based on the lon/lat
*
*/
calculateBounds: function () {
this.bounds = new OpenLayers.Bounds(this.lon, this.lat,
this.lon, this.lat);
this.bounds = new OpenLayers.Bounds(this.x, this.y,
this.x, this.y);
},
/**
@@ -111,6 +67,23 @@ OpenLayers.Geometry.Point.prototype =
}
return distance;
},
/**
* @param {OpenLayers.Geometry} xy
* @returns Boolean value indicating whether the passed-in
* OpenLayers.Geometryobject has the same components as this
* note that if ll passed in is null, returns false
*
* @type bool
*/
equals:function(geom) {
var equals = false;
if (geom != null) {
equals = ((this.x == geom.x && this.y == geom.y) ||
(isNaN(this.x) && isNaN(this.y) && isNaN(geom.x) && isNaN(geom.y)));
}
return equals;
},
/**
* @returns the coordinates as a string
@@ -120,14 +93,23 @@ OpenLayers.Geometry.Point.prototype =
return this.toShortString();
},
/**
* @return Shortened String representation of Point object.
* (ex. <i>"5, 42"</i>)
* @type String
*/
toShortString: function() {
return (this.x + ", " + this.y);
},
/**
* Moves a point in place
* @param {Float} x
* @param {Float} y
*/
move: function(x, y) {
this.setX(this.x + x);
this.setY(this.y + y);
this.x = this.x + x;
this.y = this.y + y;
},
/** @final @type String */