Bienvenue sur PostGIS.fr

Bienvenue sur PostGIS.fr , le site de la communauté des utilisateurs francophones de PostGIS.

PostGIS ajoute le support d'objets géographique à la base de données PostgreSQL. En effet, PostGIS "spatialise" le serverur PostgreSQL, ce qui permet de l'utiliser comme une base de données SIG.

Maintenu à jour, en fonction de nos disponibilités et des diverses sorties des outils que nous testons, nous vous proposons l'ensemble de nos travaux publiés en langue française.

source: trunk/workshop-routing-foss4g/web/OpenLayers/lib/OpenLayers/BaseTypes/LonLat.js @ 76

Revision 76, 5.5 KB checked in by djay, 12 years ago (diff)

Ajout du répertoire web

  • Property svn:executable set to *
Line 
1/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for
2 * full list of contributors). Published under the Clear BSD license. 
3 * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
4 * full text of the license. */
5
6/**
7 * @requires OpenLayers/Console.js
8 */
9
10/**
11 * Class: OpenLayers.LonLat
12 * This class represents a longitude and latitude pair
13 */
14OpenLayers.LonLat = OpenLayers.Class({
15
16    /**
17     * APIProperty: lon
18     * {Float} The x-axis coodinate in map units
19     */
20    lon: 0.0,
21   
22    /**
23     * APIProperty: lat
24     * {Float} The y-axis coordinate in map units
25     */
26    lat: 0.0,
27
28    /**
29     * Constructor: OpenLayers.LonLat
30     * Create a new map location.
31     *
32     * Parameters:
33     * lon - {Number} The x-axis coordinate in map units.  If your map is in
34     *     a geographic projection, this will be the Longitude.  Otherwise,
35     *     it will be the x coordinate of the map location in your map units.
36     * lat - {Number} The y-axis coordinate in map units.  If your map is in
37     *     a geographic projection, this will be the Latitude.  Otherwise,
38     *     it will be the y coordinate of the map location in your map units.
39     */
40    initialize: function(lon, lat) {
41        this.lon = OpenLayers.Util.toFloat(lon);
42        this.lat = OpenLayers.Util.toFloat(lat);
43    },
44   
45    /**
46     * Method: toString
47     * Return a readable string version of the lonlat
48     *
49     * Returns:
50     * {String} String representation of OpenLayers.LonLat object.
51     *           (ex. <i>"lon=5,lat=42"</i>)
52     */
53    toString:function() {
54        return ("lon=" + this.lon + ",lat=" + this.lat);
55    },
56
57    /**
58     * APIMethod: toShortString
59     *
60     * Returns:
61     * {String} Shortened String representation of OpenLayers.LonLat object.
62     *         (ex. <i>"5, 42"</i>)
63     */
64    toShortString:function() {
65        return (this.lon + ", " + this.lat);
66    },
67
68    /**
69     * APIMethod: clone
70     *
71     * Returns:
72     * {<OpenLayers.LonLat>} New OpenLayers.LonLat object with the same lon
73     *                       and lat values
74     */
75    clone:function() {
76        return new OpenLayers.LonLat(this.lon, this.lat);
77    },
78
79    /**
80     * APIMethod: add
81     *
82     * Parameters:
83     * lon - {Float}
84     * lat - {Float}
85     *
86     * Returns:
87     * {<OpenLayers.LonLat>} A new OpenLayers.LonLat object with the lon and
88     *                       lat passed-in added to this's.
89     */
90    add:function(lon, lat) {
91        if ( (lon == null) || (lat == null) ) {
92            var msg = OpenLayers.i18n("lonlatAddError");
93            OpenLayers.Console.error(msg);
94            return null;
95        }
96        return new OpenLayers.LonLat(this.lon + OpenLayers.Util.toFloat(lon), 
97                                     this.lat + OpenLayers.Util.toFloat(lat));
98    },
99
100    /**
101     * APIMethod: equals
102     *
103     * Parameters:
104     * ll - {<OpenLayers.LonLat>}
105     *
106     * Returns:
107     * {Boolean} Boolean value indicating whether the passed-in
108     *           <OpenLayers.LonLat> object has the same lon and lat
109     *           components as this.
110     *           Note: if ll passed in is null, returns false
111     */
112    equals:function(ll) {
113        var equals = false;
114        if (ll != null) {
115            equals = ((this.lon == ll.lon && this.lat == ll.lat) ||
116                      (isNaN(this.lon) && isNaN(this.lat) && isNaN(ll.lon) && isNaN(ll.lat)));
117        }
118        return equals;
119    },
120
121    /**
122     * APIMethod: transform
123     * Transform the LonLat object from source to dest. This transformation is
124     *    *in place*: if you want a *new* lonlat, use .clone() first.
125     *
126     * Parameters:
127     * source - {<OpenLayers.Projection>} Source projection.
128     * dest   - {<OpenLayers.Projection>} Destination projection.
129     *
130     * Returns:
131     * {<OpenLayers.LonLat>} Itself, for use in chaining operations.
132     */
133    transform: function(source, dest) {
134        var point = OpenLayers.Projection.transform(
135            {'x': this.lon, 'y': this.lat}, source, dest);
136        this.lon = point.x;
137        this.lat = point.y;
138        return this;
139    },
140   
141    /**
142     * APIMethod: wrapDateLine
143     *
144     * Parameters:
145     * maxExtent - {<OpenLayers.Bounds>}
146     *
147     * Returns:
148     * {<OpenLayers.LonLat>} A copy of this lonlat, but wrapped around the
149     *                       "dateline" (as specified by the borders of
150     *                       maxExtent)
151     */
152    wrapDateLine: function(maxExtent) {   
153
154        var newLonLat = this.clone();
155   
156        if (maxExtent) {
157            //shift right?
158            while (newLonLat.lon < maxExtent.left) {
159                newLonLat.lon +=  maxExtent.getWidth();
160            }   
161           
162            //shift left?
163            while (newLonLat.lon > maxExtent.right) {
164                newLonLat.lon -= maxExtent.getWidth();
165            }   
166        }
167               
168        return newLonLat;
169    },
170
171    CLASS_NAME: "OpenLayers.LonLat"
172});
173
174/**
175 * Function: fromString
176 * Alternative constructor that builds a new <OpenLayers.LonLat> from a
177 *     parameter string
178 *
179 * Parameters:
180 * str - {String} Comma-separated Lon,Lat coordinate string.
181 *                 (ex. <i>"5,40"</i>)
182 *
183 * Returns:
184 * {<OpenLayers.LonLat>} New <OpenLayers.LonLat> object built from the
185 *                       passed-in String.
186 */
187OpenLayers.LonLat.fromString = function(str) {
188    var pair = str.split(",");
189    return new OpenLayers.LonLat(pair[0], pair[1]);
190};
Note: See TracBrowser for help on using the repository browser.