~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/BaseTypes/LonLat.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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. */
 
4
 
 
5
/**
 
6
 * Class: OpenLayers.LonLat
 
7
 * This class represents a longitude and latitude pair
 
8
 */
 
9
OpenLayers.LonLat = OpenLayers.Class({
 
10
 
 
11
    /** 
 
12
     * APIProperty: lon
 
13
     * {Float} The x-axis coodinate in map units
 
14
     */
 
15
    lon: 0.0,
 
16
    
 
17
    /** 
 
18
     * APIProperty: lat
 
19
     * {Float} The y-axis coordinate in map units
 
20
     */
 
21
    lat: 0.0,
 
22
 
 
23
    /**
 
24
     * Constructor: OpenLayers.LonLat
 
25
     * Create a new map location.
 
26
     *
 
27
     * Parameters:
 
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.
 
34
     */
 
35
    initialize: function(lon, lat) {
 
36
        this.lon = parseFloat(lon);
 
37
        this.lat = parseFloat(lat);
 
38
    },
 
39
    
 
40
    /**
 
41
     * Method: toString
 
42
     * Return a readable string version of the lonlat
 
43
     *
 
44
     * Returns:
 
45
     * {String} String representation of OpenLayers.LonLat object. 
 
46
     *           (ex. <i>"lon=5,lat=42"</i>)
 
47
     */
 
48
    toString:function() {
 
49
        return ("lon=" + this.lon + ",lat=" + this.lat);
 
50
    },
 
51
 
 
52
    /** 
 
53
     * APIMethod: toShortString
 
54
     * 
 
55
     * Returns:
 
56
     * {String} Shortened String representation of OpenLayers.LonLat object. 
 
57
     *         (ex. <i>"5, 42"</i>)
 
58
     */
 
59
    toShortString:function() {
 
60
        return (this.lon + ", " + this.lat);
 
61
    },
 
62
 
 
63
    /** 
 
64
     * APIMethod: clone
 
65
     * 
 
66
     * Returns:
 
67
     * {<OpenLayers.LonLat>} New OpenLayers.LonLat object with the same lon 
 
68
     *                       and lat values
 
69
     */
 
70
    clone:function() {
 
71
        return new OpenLayers.LonLat(this.lon, this.lat);
 
72
    },
 
73
 
 
74
    /** 
 
75
     * APIMethod: add
 
76
     * 
 
77
     * Parameters:
 
78
     * lon - {Float}
 
79
     * lat - {Float}
 
80
     * 
 
81
     * Returns:
 
82
     * {<OpenLayers.LonLat>} A new OpenLayers.LonLat object with the lon and 
 
83
     *                       lat passed-in added to this's. 
 
84
     */
 
85
    add:function(lon, lat) {
 
86
        if ( (lon == null) || (lat == null) ) {
 
87
            var msg = OpenLayers.i18n("lonlatAddError");
 
88
            OpenLayers.Console.error(msg);
 
89
            return null;
 
90
        }
 
91
        return new OpenLayers.LonLat(this.lon + lon, this.lat + lat);
 
92
    },
 
93
 
 
94
    /** 
 
95
     * APIMethod: equals
 
96
     * 
 
97
     * Parameters:
 
98
     * ll - {<OpenLayers.LonLat>}
 
99
     * 
 
100
     * Returns:
 
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
 
105
     */
 
106
    equals:function(ll) {
 
107
        var equals = false;
 
108
        if (ll != null) {
 
109
            equals = ((this.lon == ll.lon && this.lat == ll.lat) ||
 
110
                      (isNaN(this.lon) && isNaN(this.lat) && isNaN(ll.lon) && isNaN(ll.lat)));
 
111
        }
 
112
        return equals;
 
113
    },
 
114
 
 
115
    /**
 
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.
 
119
     *
 
120
     * Parameters: 
 
121
     * source - {<OpenLayers.Projection>} Source projection. 
 
122
     * dest   - {<OpenLayers.Projection>} Destination projection. 
 
123
     *
 
124
     * Returns:
 
125
     * {<OpenLayers.LonLat>} Itself, for use in chaining operations.
 
126
     */
 
127
    transform: function(source, dest) {
 
128
        var point = OpenLayers.Projection.transform(
 
129
            {'x': this.lon, 'y': this.lat}, source, dest);
 
130
        this.lon = point.x;
 
131
        this.lat = point.y;
 
132
        return this;
 
133
    },
 
134
    
 
135
    /**
 
136
     * APIMethod: wrapDateLine
 
137
     * 
 
138
     * Parameters:
 
139
     * maxExtent - {<OpenLayers.Bounds>}
 
140
     * 
 
141
     * Returns:
 
142
     * {<OpenLayers.LonLat>} A copy of this lonlat, but wrapped around the 
 
143
     *                       "dateline" (as specified by the borders of 
 
144
     *                       maxExtent)
 
145
     */
 
146
    wrapDateLine: function(maxExtent) {    
 
147
 
 
148
        var newLonLat = this.clone();
 
149
    
 
150
        if (maxExtent) {
 
151
            //shift right?
 
152
            while (newLonLat.lon < maxExtent.left) {
 
153
                newLonLat.lon +=  maxExtent.getWidth();
 
154
            }    
 
155
           
 
156
            //shift left?
 
157
            while (newLonLat.lon > maxExtent.right) {
 
158
                newLonLat.lon -= maxExtent.getWidth();
 
159
            }    
 
160
        }
 
161
                
 
162
        return newLonLat;
 
163
    },
 
164
 
 
165
    CLASS_NAME: "OpenLayers.LonLat"
 
166
});
 
167
 
 
168
/** 
 
169
 * Function: fromString
 
170
 * Alternative constructor that builds a new <OpenLayers.LonLat> from a 
 
171
 *     parameter string
 
172
 * 
 
173
 * Parameters:
 
174
 * str - {String} Comma-separated Lon,Lat coordinate string. 
 
175
 *                 (ex. <i>"5,40"</i>)
 
176
 * 
 
177
 * Returns:
 
178
 * {<OpenLayers.LonLat>} New <OpenLayers.LonLat> object built from the 
 
179
 *                       passed-in String.
 
180
 */
 
181
OpenLayers.LonLat.fromString = function(str) {
 
182
    var pair = str.split(",");
 
183
    return new OpenLayers.LonLat(parseFloat(pair[0]), 
 
184
                                 parseFloat(pair[1]));
 
185
};