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
* Class: OpenLayers.LonLat
7
* This class represents a longitude and latitude pair
9
OpenLayers.LonLat = OpenLayers.Class({
13
* {Float} The x-axis coodinate in map units
19
* {Float} The y-axis coordinate in map units
24
* Constructor: OpenLayers.LonLat
25
* Create a new map location.
28
* lon - {Number} The x-axis coordinate in map units. If your map is in
29
* a geographic projection, this will be the Longitude. Otherwise,
30
* it will be the x coordinate of the map location in your map units.
31
* lat - {Number} The y-axis coordinate in map units. If your map is in
32
* a geographic projection, this will be the Latitude. Otherwise,
33
* it will be the y coordinate of the map location in your map units.
35
initialize: function(lon, lat) {
36
this.lon = parseFloat(lon);
37
this.lat = parseFloat(lat);
42
* Return a readable string version of the lonlat
45
* {String} String representation of OpenLayers.LonLat object.
46
* (ex. <i>"lon=5,lat=42"</i>)
49
return ("lon=" + this.lon + ",lat=" + this.lat);
53
* APIMethod: toShortString
56
* {String} Shortened String representation of OpenLayers.LonLat object.
57
* (ex. <i>"5, 42"</i>)
59
toShortString:function() {
60
return (this.lon + ", " + this.lat);
67
* {<OpenLayers.LonLat>} New OpenLayers.LonLat object with the same lon
71
return new OpenLayers.LonLat(this.lon, this.lat);
82
* {<OpenLayers.LonLat>} A new OpenLayers.LonLat object with the lon and
83
* lat passed-in added to this's.
85
add:function(lon, lat) {
86
if ( (lon == null) || (lat == null) ) {
87
var msg = OpenLayers.i18n("lonlatAddError");
88
OpenLayers.Console.error(msg);
91
return new OpenLayers.LonLat(this.lon + lon, this.lat + lat);
98
* ll - {<OpenLayers.LonLat>}
101
* {Boolean} Boolean value indicating whether the passed-in
102
* <OpenLayers.LonLat> object has the same lon and lat
103
* components as this.
104
* Note: if ll passed in is null, returns false
106
equals:function(ll) {
109
equals = ((this.lon == ll.lon && this.lat == ll.lat) ||
110
(isNaN(this.lon) && isNaN(this.lat) && isNaN(ll.lon) && isNaN(ll.lat)));
116
* APIMethod: transform
117
* Transform the LonLat object from source to dest. This transformation is
118
* *in place*: if you want a *new* lonlat, use .clone() first.
121
* source - {<OpenLayers.Projection>} Source projection.
122
* dest - {<OpenLayers.Projection>} Destination projection.
125
* {<OpenLayers.LonLat>} Itself, for use in chaining operations.
127
transform: function(source, dest) {
128
var point = OpenLayers.Projection.transform(
129
{'x': this.lon, 'y': this.lat}, source, dest);
136
* APIMethod: wrapDateLine
139
* maxExtent - {<OpenLayers.Bounds>}
142
* {<OpenLayers.LonLat>} A copy of this lonlat, but wrapped around the
143
* "dateline" (as specified by the borders of
146
wrapDateLine: function(maxExtent) {
148
var newLonLat = this.clone();
152
while (newLonLat.lon < maxExtent.left) {
153
newLonLat.lon += maxExtent.getWidth();
157
while (newLonLat.lon > maxExtent.right) {
158
newLonLat.lon -= maxExtent.getWidth();
165
CLASS_NAME: "OpenLayers.LonLat"
169
* Function: fromString
170
* Alternative constructor that builds a new <OpenLayers.LonLat> from a
174
* str - {String} Comma-separated Lon,Lat coordinate string.
175
* (ex. <i>"5,40"</i>)
178
* {<OpenLayers.LonLat>} New <OpenLayers.LonLat> object built from the
181
OpenLayers.LonLat.fromString = function(str) {
182
var pair = str.split(",");
183
return new OpenLayers.LonLat(parseFloat(pair[0]),
184
parseFloat(pair[1]));