#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;
|
||||
if (object) {
|
||||
switch(object.CLASS_NAME) {
|
||||
case "OpenLayers.Geometry.Point":
|
||||
case "OpenLayers.LonLat":
|
||||
bounds = new OpenLayers.Bounds(object.lon, object.lat,
|
||||
object.lon, object.lat);
|
||||
break;
|
||||
case "OpenLayers.Geometry.Point":
|
||||
bounds = new OpenLayers.Bounds(object.x, object.y,
|
||||
object.x, object.y);
|
||||
break;
|
||||
|
||||
case "OpenLayers.Bounds":
|
||||
bounds = object;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -102,8 +102,8 @@ OpenLayers.Handler.Path.prototype =
|
||||
*/
|
||||
modifyGeometry: function() {
|
||||
var index = this.line.components.length - 1;
|
||||
this.line.components[index].setX(this.point.x);
|
||||
this.line.components[index].setY(this.point.y);
|
||||
this.line.components[index].x = this.point.x;
|
||||
this.line.components[index].y = this.point.y;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -141,8 +141,8 @@ OpenLayers.Handler.Path.prototype =
|
||||
this.mouseDown = true;
|
||||
this.lastDown = evt.xy;
|
||||
var lonlat = this.control.map.getLonLatFromPixel(evt.xy);
|
||||
this.point.setX(lonlat.lon);
|
||||
this.point.setY(lonlat.lat);
|
||||
this.point.x = lonlat.lon;
|
||||
this.point.y = lonlat.lat;
|
||||
if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) {
|
||||
this.addPoint();
|
||||
}
|
||||
@@ -161,8 +161,8 @@ OpenLayers.Handler.Path.prototype =
|
||||
mousemove: function (evt) {
|
||||
if(this.drawing) {
|
||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.point.setX(lonlat.lon);
|
||||
this.point.setY(lonlat.lat);
|
||||
this.point.x = lonlat.lon;
|
||||
this.point.y = lonlat.lat;
|
||||
if(this.mouseDown && this.freehandMode(evt)) {
|
||||
this.addPoint();
|
||||
} else {
|
||||
|
||||
@@ -188,8 +188,8 @@ OpenLayers.Handler.Point.prototype =
|
||||
this.lastDown = evt.xy;
|
||||
this.drawing = true;
|
||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.point.setX(lonlat.lon);
|
||||
this.point.setY(lonlat.lat);
|
||||
this.point.x = lonlat.lon;
|
||||
this.point.y = lonlat.lat;
|
||||
this.drawGeometry();
|
||||
return false;
|
||||
},
|
||||
@@ -204,8 +204,8 @@ OpenLayers.Handler.Point.prototype =
|
||||
mousemove: function (evt) {
|
||||
if(this.drawing) {
|
||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.point.setX(lonlat.lon);
|
||||
this.point.setY(lonlat.lat);
|
||||
this.point.x = lonlat.lon;
|
||||
this.point.y = lonlat.lat;
|
||||
this.drawGeometry();
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -65,8 +65,8 @@ OpenLayers.Handler.Polygon.prototype =
|
||||
*/
|
||||
modifyGeometry: function() {
|
||||
var index = this.line.components.length - 2;
|
||||
this.line.components[index].setX(this.point.x);
|
||||
this.line.components[index].setY(this.point.y);
|
||||
this.line.components[index].x = this.point.x;
|
||||
this.line.components[index].y = this.point.y;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -333,8 +333,8 @@ OpenLayers.Renderer.VML.prototype =
|
||||
|
||||
var path = "m";
|
||||
for (var i = 0; i < geometry.components.length; i++) {
|
||||
var x = (geometry.components[i].getX()/resolution);
|
||||
var y = (geometry.components[i].getY()/resolution);
|
||||
var x = (geometry.components[i].x/resolution);
|
||||
var y = (geometry.components[i].y/resolution);
|
||||
path += " " + x.toFixed() + "," + y.toFixed() + " l ";
|
||||
}
|
||||
if (closeLine) {
|
||||
@@ -360,8 +360,8 @@ OpenLayers.Renderer.VML.prototype =
|
||||
|
||||
path += "m";
|
||||
for (var i = 0; i < linearRing.components.length; i++) {
|
||||
var x = linearRing.components[i].getX() / resolution;
|
||||
var y = linearRing.components[i].getY() / resolution;
|
||||
var x = linearRing.components[i].x / resolution;
|
||||
var y = linearRing.components[i].y / resolution;
|
||||
path += " " + x.toFixed() + "," + y.toFixed();
|
||||
if (i==0) {
|
||||
path += " l";
|
||||
@@ -399,8 +399,8 @@ OpenLayers.Renderer.VML.prototype =
|
||||
|
||||
var path = "";
|
||||
for (var i = 0; i < geometry.components.length; i++) {
|
||||
var x = geometry.components[i].getX() / resolution;
|
||||
var y = geometry.components[i].getY() / resolution;
|
||||
var x = geometry.components[i].x / resolution;
|
||||
var y = geometry.components[i].y / resolution;
|
||||
|
||||
if ((i%3)==0 && (i/3)==0) {
|
||||
path += "m"
|
||||
@@ -426,8 +426,8 @@ OpenLayers.Renderer.VML.prototype =
|
||||
|
||||
var path = "";
|
||||
for (var i = 0; i < geometry.components.length; i++) {
|
||||
var x = geometry.components[i].getX() / resolution;
|
||||
var y = geometry.components[i].getY() / resolution;
|
||||
var x = geometry.components[i].x / resolution;
|
||||
var y = geometry.components[i].y / resolution;
|
||||
if ((i%3)==0 && (i/3)==0) {
|
||||
path += "m";
|
||||
} else if ((i%3)==1) {
|
||||
|
||||
Reference in New Issue
Block a user