1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3
* full text of the license. */
6
* @requires OpenLayers/Geometry.js
10
* Class: OpenLayers.Geometry.Point
11
* Point geometry class.
14
* - <OpenLayers.Geometry>
16
OpenLayers.Geometry.Point = OpenLayers.Class(OpenLayers.Geometry, {
31
* Constructor: OpenLayers.Geometry.Point
32
* Construct a point geometry.
39
initialize: function(x, y) {
40
OpenLayers.Geometry.prototype.initialize.apply(this, arguments);
42
this.x = parseFloat(x);
43
this.y = parseFloat(y);
50
* {<OpenLayers.Geometry.Point>} An exact clone of this OpenLayers.Geometry.Point
52
clone: function(obj) {
54
obj = new OpenLayers.Geometry.Point(this.x, this.y);
57
// catch any randomly tagged-on properties
58
OpenLayers.Util.applyDefaults(obj, this);
64
* Method: calculateBounds
65
* Create a new Bounds based on the lon/lat
67
calculateBounds: function () {
68
this.bounds = new OpenLayers.Bounds(this.x, this.y,
73
* APIMethod: distanceTo
76
* point - {<OpenLayers.Geometry.Point>}
78
distanceTo: function(point) {
80
if ( (this.x != null) && (this.y != null) &&
81
(point != null) && (point.x != null) && (point.y != null) ) {
83
var dx2 = Math.pow(this.x - point.x, 2);
84
var dy2 = Math.pow(this.y - point.y, 2);
85
distance = Math.sqrt( dx2 + dy2 );
94
* xy - {<OpenLayers.Geometry>}
97
* {Boolean} Boolean value indicating whether the passed-in
98
* {<OpenLayers.Geometry>} object has the same components as this
99
* note that if ll passed in is null, returns false
102
equals:function(geom) {
105
equals = ((this.x == geom.x && this.y == geom.y) ||
106
(isNaN(this.x) && isNaN(this.y) && isNaN(geom.x) && isNaN(geom.y)));
112
* Method: toShortString
115
* {String} Shortened String representation of Point object.
116
* (ex. <i>"5, 42"</i>)
118
toShortString: function() {
119
return (this.x + ", " + this.y);
124
* Moves a point in place
130
move: function(x, y) {
138
* Rotate a point around another.
141
* angle - {Float} Rotation angle in degrees (measured counterclockwise
142
* from the positive x-axis)
143
* origin - {<OpenLayers.Geometry.Point>} Center point for the rotation
145
rotate: function(angle, origin) {
146
angle *= Math.PI / 180;
147
var radius = this.distanceTo(origin);
148
var theta = angle + Math.atan2(this.y - origin.y, this.x - origin.x);
149
this.x = origin.x + (radius * Math.cos(theta));
150
this.y = origin.y + (radius * Math.sin(theta));
156
* Resize a point relative to some origin. For points, this has the effect
157
* of scaling a vector (from the origin to the point). This method is
158
* more useful on geometry collection subclasses.
161
* scale - {Float} Ratio of the new distance from the origin to the old
162
* distance from the origin. A scale of 2 doubles the
163
* distance between the point and origin.
164
* origin - {<OpenLayers.Geometry.Point>} Point of origin for resizing
165
* ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1.
167
resize: function(scale, origin, ratio) {
168
ratio = (ratio == undefined) ? 1 : ratio;
169
this.x = origin.x + (scale * ratio * (this.x - origin.x));
170
this.y = origin.y + (scale * (this.y - origin.y));
175
* APIMethod: intersects
176
* Determine if the input geometry intersects this one.
179
* geometry - {<OpenLayers.Geometry>} Any type of geometry.
182
* {Boolean} The input geometry intersects this one.
184
intersects: function(geometry) {
185
var intersect = false;
186
if(geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
187
intersect = this.equals(geometry);
189
intersect = geometry.intersects(this);
195
* APIMethod: transform
196
* Translate the x,y properties of the point from source to dest.
199
* source - {<OpenLayers.Projection>}
200
* dest - {<OpenLayers.Projection>}
203
* {<OpenLayers.Geometry>}
205
transform: function(source, dest) {
206
if ((source && dest)) {
207
OpenLayers.Projection.transform(
214
CLASS_NAME: "OpenLayers.Geometry.Point"