#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:
@@ -492,11 +492,14 @@ OpenLayers.Bounds.prototype = {
|
|||||||
var bounds = null;
|
var bounds = null;
|
||||||
if (object) {
|
if (object) {
|
||||||
switch(object.CLASS_NAME) {
|
switch(object.CLASS_NAME) {
|
||||||
case "OpenLayers.Geometry.Point":
|
|
||||||
case "OpenLayers.LonLat":
|
case "OpenLayers.LonLat":
|
||||||
bounds = new OpenLayers.Bounds(object.lon, object.lat,
|
bounds = new OpenLayers.Bounds(object.lon, object.lat,
|
||||||
object.lon, object.lat);
|
object.lon, object.lat);
|
||||||
break;
|
break;
|
||||||
|
case "OpenLayers.Geometry.Point":
|
||||||
|
bounds = new OpenLayers.Bounds(object.x, object.y,
|
||||||
|
object.x, object.y);
|
||||||
|
break;
|
||||||
|
|
||||||
case "OpenLayers.Bounds":
|
case "OpenLayers.Bounds":
|
||||||
bounds = object;
|
bounds = object;
|
||||||
|
|||||||
@@ -5,20 +5,11 @@
|
|||||||
/**
|
/**
|
||||||
* @class
|
* @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
|
* @requires OpenLayers/Geometry.js
|
||||||
*/
|
*/
|
||||||
OpenLayers.Geometry.Point = OpenLayers.Class.create();
|
OpenLayers.Geometry.Point = OpenLayers.Class.create();
|
||||||
OpenLayers.Geometry.Point.prototype =
|
OpenLayers.Geometry.Point.prototype =
|
||||||
OpenLayers.Class.inherit(OpenLayers.Geometry, OpenLayers.LonLat, {
|
OpenLayers.Class.inherit(OpenLayers.Geometry, {
|
||||||
|
|
||||||
/** @type float */
|
/** @type float */
|
||||||
x: null,
|
x: null,
|
||||||
@@ -34,10 +25,9 @@ OpenLayers.Geometry.Point.prototype =
|
|||||||
*/
|
*/
|
||||||
initialize: function(x, y) {
|
initialize: function(x, y) {
|
||||||
OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
|
OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
|
||||||
OpenLayers.LonLat.prototype.initialize.apply(this, arguments);
|
|
||||||
|
|
||||||
this.x = this.lon;
|
this.x = parseFloat(x);
|
||||||
this.y = this.lat;
|
this.y = parseFloat(y);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,46 +45,12 @@ OpenLayers.Geometry.Point.prototype =
|
|||||||
return obj;
|
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
|
/** Create a new Bounds based on the lon/lat
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
calculateBounds: function () {
|
calculateBounds: function () {
|
||||||
this.bounds = new OpenLayers.Bounds(this.lon, this.lat,
|
this.bounds = new OpenLayers.Bounds(this.x, this.y,
|
||||||
this.lon, this.lat);
|
this.x, this.y);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,6 +68,23 @@ OpenLayers.Geometry.Point.prototype =
|
|||||||
return distance;
|
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
|
* @returns the coordinates as a string
|
||||||
* @type String
|
* @type String
|
||||||
@@ -120,14 +93,23 @@ OpenLayers.Geometry.Point.prototype =
|
|||||||
return this.toShortString();
|
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
|
* Moves a point in place
|
||||||
* @param {Float} x
|
* @param {Float} x
|
||||||
* @param {Float} y
|
* @param {Float} y
|
||||||
*/
|
*/
|
||||||
move: function(x, y) {
|
move: function(x, y) {
|
||||||
this.setX(this.x + x);
|
this.x = this.x + x;
|
||||||
this.setY(this.y + y);
|
this.y = this.y + y;
|
||||||
},
|
},
|
||||||
|
|
||||||
/** @final @type String */
|
/** @final @type String */
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ OpenLayers.Handler.Path.prototype =
|
|||||||
*/
|
*/
|
||||||
modifyGeometry: function() {
|
modifyGeometry: function() {
|
||||||
var index = this.line.components.length - 1;
|
var index = this.line.components.length - 1;
|
||||||
this.line.components[index].setX(this.point.x);
|
this.line.components[index].x = this.point.x;
|
||||||
this.line.components[index].setY(this.point.y);
|
this.line.components[index].y = this.point.y;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -141,8 +141,8 @@ OpenLayers.Handler.Path.prototype =
|
|||||||
this.mouseDown = true;
|
this.mouseDown = true;
|
||||||
this.lastDown = evt.xy;
|
this.lastDown = evt.xy;
|
||||||
var lonlat = this.control.map.getLonLatFromPixel(evt.xy);
|
var lonlat = this.control.map.getLonLatFromPixel(evt.xy);
|
||||||
this.point.setX(lonlat.lon);
|
this.point.x = lonlat.lon;
|
||||||
this.point.setY(lonlat.lat);
|
this.point.y = lonlat.lat;
|
||||||
if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) {
|
if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) {
|
||||||
this.addPoint();
|
this.addPoint();
|
||||||
}
|
}
|
||||||
@@ -161,8 +161,8 @@ OpenLayers.Handler.Path.prototype =
|
|||||||
mousemove: function (evt) {
|
mousemove: function (evt) {
|
||||||
if(this.drawing) {
|
if(this.drawing) {
|
||||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||||
this.point.setX(lonlat.lon);
|
this.point.x = lonlat.lon;
|
||||||
this.point.setY(lonlat.lat);
|
this.point.y = lonlat.lat;
|
||||||
if(this.mouseDown && this.freehandMode(evt)) {
|
if(this.mouseDown && this.freehandMode(evt)) {
|
||||||
this.addPoint();
|
this.addPoint();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -188,8 +188,8 @@ OpenLayers.Handler.Point.prototype =
|
|||||||
this.lastDown = evt.xy;
|
this.lastDown = evt.xy;
|
||||||
this.drawing = true;
|
this.drawing = true;
|
||||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||||
this.point.setX(lonlat.lon);
|
this.point.x = lonlat.lon;
|
||||||
this.point.setY(lonlat.lat);
|
this.point.y = lonlat.lat;
|
||||||
this.drawGeometry();
|
this.drawGeometry();
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
@@ -204,8 +204,8 @@ OpenLayers.Handler.Point.prototype =
|
|||||||
mousemove: function (evt) {
|
mousemove: function (evt) {
|
||||||
if(this.drawing) {
|
if(this.drawing) {
|
||||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||||
this.point.setX(lonlat.lon);
|
this.point.x = lonlat.lon;
|
||||||
this.point.setY(lonlat.lat);
|
this.point.y = lonlat.lat;
|
||||||
this.drawGeometry();
|
this.drawGeometry();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ OpenLayers.Handler.Polygon.prototype =
|
|||||||
*/
|
*/
|
||||||
modifyGeometry: function() {
|
modifyGeometry: function() {
|
||||||
var index = this.line.components.length - 2;
|
var index = this.line.components.length - 2;
|
||||||
this.line.components[index].setX(this.point.x);
|
this.line.components[index].x = this.point.x;
|
||||||
this.line.components[index].setY(this.point.y);
|
this.line.components[index].y = this.point.y;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -333,8 +333,8 @@ OpenLayers.Renderer.VML.prototype =
|
|||||||
|
|
||||||
var path = "m";
|
var path = "m";
|
||||||
for (var i = 0; i < geometry.components.length; i++) {
|
for (var i = 0; i < geometry.components.length; i++) {
|
||||||
var x = (geometry.components[i].getX()/resolution);
|
var x = (geometry.components[i].x/resolution);
|
||||||
var y = (geometry.components[i].getY()/resolution);
|
var y = (geometry.components[i].y/resolution);
|
||||||
path += " " + x.toFixed() + "," + y.toFixed() + " l ";
|
path += " " + x.toFixed() + "," + y.toFixed() + " l ";
|
||||||
}
|
}
|
||||||
if (closeLine) {
|
if (closeLine) {
|
||||||
@@ -360,8 +360,8 @@ OpenLayers.Renderer.VML.prototype =
|
|||||||
|
|
||||||
path += "m";
|
path += "m";
|
||||||
for (var i = 0; i < linearRing.components.length; i++) {
|
for (var i = 0; i < linearRing.components.length; i++) {
|
||||||
var x = linearRing.components[i].getX() / resolution;
|
var x = linearRing.components[i].x / resolution;
|
||||||
var y = linearRing.components[i].getY() / resolution;
|
var y = linearRing.components[i].y / resolution;
|
||||||
path += " " + x.toFixed() + "," + y.toFixed();
|
path += " " + x.toFixed() + "," + y.toFixed();
|
||||||
if (i==0) {
|
if (i==0) {
|
||||||
path += " l";
|
path += " l";
|
||||||
@@ -399,8 +399,8 @@ OpenLayers.Renderer.VML.prototype =
|
|||||||
|
|
||||||
var path = "";
|
var path = "";
|
||||||
for (var i = 0; i < geometry.components.length; i++) {
|
for (var i = 0; i < geometry.components.length; i++) {
|
||||||
var x = geometry.components[i].getX() / resolution;
|
var x = geometry.components[i].x / resolution;
|
||||||
var y = geometry.components[i].getY() / resolution;
|
var y = geometry.components[i].y / resolution;
|
||||||
|
|
||||||
if ((i%3)==0 && (i/3)==0) {
|
if ((i%3)==0 && (i/3)==0) {
|
||||||
path += "m"
|
path += "m"
|
||||||
@@ -426,8 +426,8 @@ OpenLayers.Renderer.VML.prototype =
|
|||||||
|
|
||||||
var path = "";
|
var path = "";
|
||||||
for (var i = 0; i < geometry.components.length; i++) {
|
for (var i = 0; i < geometry.components.length; i++) {
|
||||||
var x = geometry.components[i].getX() / resolution;
|
var x = geometry.components[i].x / resolution;
|
||||||
var y = geometry.components[i].getY() / resolution;
|
var y = geometry.components[i].y / resolution;
|
||||||
if ((i%3)==0 && (i/3)==0) {
|
if ((i%3)==0 && (i/3)==0) {
|
||||||
path += "m";
|
path += "m";
|
||||||
} else if ((i%3)==1) {
|
} else if ((i%3)==1) {
|
||||||
|
|||||||
@@ -361,8 +361,8 @@
|
|||||||
|
|
||||||
bounds.extend(object);
|
bounds.extend(object);
|
||||||
|
|
||||||
t.ok( ((bounds.left == object.lon) &&
|
t.ok( ((bounds.left == object.x) &&
|
||||||
(bounds.bottom == object.lat) &&
|
(bounds.bottom == object.y) &&
|
||||||
(bounds.right == originalBounds.right) &&
|
(bounds.right == originalBounds.right) &&
|
||||||
(bounds.top == originalBounds.top)), "obj Point to extends correclty modifies left and bottom");
|
(bounds.top == originalBounds.top)), "obj Point to extends correclty modifies left and bottom");
|
||||||
|
|
||||||
@@ -375,8 +375,8 @@
|
|||||||
|
|
||||||
t.ok( ((bounds.left == originalBounds.left) &&
|
t.ok( ((bounds.left == originalBounds.left) &&
|
||||||
(bounds.bottom == originalBounds.bottom) &&
|
(bounds.bottom == originalBounds.bottom) &&
|
||||||
(bounds.right == object.lon) &&
|
(bounds.right == object.x) &&
|
||||||
(bounds.top == object.lat)), "obj Point to extends correclty modifies right and top");
|
(bounds.top == object.y)), "obj Point to extends correclty modifies right and top");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,8 +96,8 @@
|
|||||||
t.eq( curve.components.length, 4, "new point added to array" );
|
t.eq( curve.components.length, 4, "new point added to array" );
|
||||||
t.eq( bounds.bottom, -30, "bottom bound is -30 after 2nd addComponent" );
|
t.eq( bounds.bottom, -30, "bottom bound is -30 after 2nd addComponent" );
|
||||||
t.eq( bounds.left, -20, "left bound is 20 after 2nd addComponent" );
|
t.eq( bounds.left, -20, "left bound is 20 after 2nd addComponent" );
|
||||||
t.eq( curve.components[1].lon, -20, "new point.lon is -20 (index worked)" );
|
t.eq( curve.components[1].x, -20, "new point.lon is -20 (index worked)" );
|
||||||
t.eq( curve.components[1].lat, -30, "new point.lat is -30 (index worked)" );
|
t.eq( curve.components[1].y, -30, "new point.lat is -30 (index worked)" );
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_05_Curve_removeComponent (t) {
|
function test_05_Curve_removeComponent (t) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_02_MultiPoint_move(t) {
|
function test_02_MultiPoint_move(t) {
|
||||||
t.plan(4);
|
t.plan(2);
|
||||||
|
|
||||||
var multipoint = new OpenLayers.Geometry.MultiPoint([point]);
|
var multipoint = new OpenLayers.Geometry.MultiPoint([point]);
|
||||||
var x = point.x;
|
var x = point.x;
|
||||||
@@ -32,8 +32,6 @@
|
|||||||
multipoint.move(dx, dy);
|
multipoint.move(dx, dy);
|
||||||
t.eq(multipoint.components[0].x, x + dx, "move() correctly modifies x");
|
t.eq(multipoint.components[0].x, x + dx, "move() correctly modifies x");
|
||||||
t.eq(multipoint.components[0].y, y + dy, "move() correctly modifies y");
|
t.eq(multipoint.components[0].y, y + dy, "move() correctly modifies y");
|
||||||
t.eq(multipoint.components[0].lon, x + dx, "move() correctly modifies lon");
|
|
||||||
t.eq(multipoint.components[0].lat, y + dy, "move() correctly modifies lat");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_MultiPoint_equals(t) {
|
function test_MultiPoint_equals(t) {
|
||||||
|
|||||||
@@ -20,32 +20,8 @@
|
|||||||
t.eq( point.CLASS_NAME, "OpenLayers.Geometry.Point", "point.CLASS_NAME is set correctly");
|
t.eq( point.CLASS_NAME, "OpenLayers.Geometry.Point", "point.CLASS_NAME is set correctly");
|
||||||
t.eq( point.x, x, "point.x is set correctly");
|
t.eq( point.x, x, "point.x is set correctly");
|
||||||
t.eq( point.y, y, "point.y is set correctly");
|
t.eq( point.y, y, "point.y is set correctly");
|
||||||
t.eq( point.lon, x, "point.lon is set correctly");
|
t.eq( point.lon, null, "point.lon is not set");
|
||||||
t.eq( point.lat, y, "point.lat is set correctly");
|
t.eq( point.lat, null, "point.lat is not set");
|
||||||
}
|
|
||||||
|
|
||||||
function test_02_Point_accessors(t) {
|
|
||||||
t.plan( 6 )
|
|
||||||
|
|
||||||
//valid
|
|
||||||
var x = 10;
|
|
||||||
var y = 20;
|
|
||||||
point = new OpenLayers.Geometry.Point(x, y);
|
|
||||||
|
|
||||||
t.eq( point.getX(), x, "point.x is get() correctly");
|
|
||||||
t.eq( point.getY(), y, "point.y is get() correctly");
|
|
||||||
|
|
||||||
var x1 = 55;
|
|
||||||
var y1 = 73;
|
|
||||||
|
|
||||||
point.setX(x1);
|
|
||||||
point.setY(y1);
|
|
||||||
|
|
||||||
t.eq( point.x, x1, "point.x is set() correctly");
|
|
||||||
t.eq( point.y, y1, "point.y is set() correctly");
|
|
||||||
t.eq( point.lon, x1, "point.lon is set() correctly");
|
|
||||||
t.eq( point.lat, y1, "point.lat is set() correctly");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_03_Point_calculateBounds (t) {
|
function test_03_Point_calculateBounds (t) {
|
||||||
@@ -89,7 +65,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_06_Point_move(t) {
|
function test_06_Point_move(t) {
|
||||||
t.plan(4);
|
t.plan(2);
|
||||||
|
|
||||||
var x = 10;
|
var x = 10;
|
||||||
var y = 20;
|
var y = 20;
|
||||||
@@ -100,8 +76,6 @@
|
|||||||
point.move(dx, dy);
|
point.move(dx, dy);
|
||||||
t.eq(point.x, x + dx, "move() correctly modifies x");
|
t.eq(point.x, x + dx, "move() correctly modifies x");
|
||||||
t.eq(point.y, y + dy, "move() correctly modifies y");
|
t.eq(point.y, y + dy, "move() correctly modifies y");
|
||||||
t.eq(point.lon, x + dx, "move() correctly modifies lon");
|
|
||||||
t.eq(point.lat, y + dy, "move() correctly modifies lat");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Point_equals(t) {
|
function test_Point_equals(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user