]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Layer/MultiMap.js
fixes notices
[syp.git] / openlayers / lib / OpenLayers / Layer / MultiMap.js
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  * @requires OpenLayers/Layer/EventPane.js
7  * @requires OpenLayers/Layer/FixedZoomLevels.js
8  */
9
10 /**
11  * Class: OpenLayers.Layer.MultiMap
12  * Note that MultiMap does not fully support the sphericalMercator
13  * option. See Ticket #953 for more details.
14  * 
15  * Inherits from:
16  *  - <OpenLayers.Layer.EventPane>
17  *  - <OpenLayers.Layer.FixedZoomLevels>
18  */
19 OpenLayers.Layer.MultiMap = OpenLayers.Class(
20   OpenLayers.Layer.EventPane, OpenLayers.Layer.FixedZoomLevels, {
21     
22     /** 
23      * Constant: MIN_ZOOM_LEVEL
24      * {Integer} 1 
25      */
26     MIN_ZOOM_LEVEL: 1,
27     
28     /** 
29      * Constant: MAX_ZOOM_LEVEL
30      * {Integer} 17
31      */
32     MAX_ZOOM_LEVEL: 17,
33
34     /** 
35      * Constant: RESOLUTIONS
36      * {Array(Float)} Hardcode these resolutions so that they are more closely
37      *                tied with the standard wms projection
38      */
39     RESOLUTIONS: [
40         9, 
41         1.40625,
42         0.703125,
43         0.3515625,
44         0.17578125,
45         0.087890625,
46         0.0439453125,
47         0.02197265625,
48         0.010986328125,
49         0.0054931640625,
50         0.00274658203125,
51         0.001373291015625,
52         0.0006866455078125,
53         0.00034332275390625,
54         0.000171661376953125,
55         0.0000858306884765625,
56         0.00004291534423828125
57     ],
58
59     /**
60      * APIProperty: type
61      * {?}
62      */
63     type: null,
64
65     /** 
66      * Constructor: OpenLayers.Layer.MultiMap
67      * 
68      * Parameters:
69      * name - {String}
70      * options - {Object}
71      */
72     initialize: function(name, options) {
73         OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
74         OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this, 
75                                                                     arguments);
76         if (this.sphericalMercator) {
77             OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
78             this.initMercatorParameters();
79             this.RESOLUTIONS.unshift(10); 
80         }    
81     },
82     
83     /**
84      * Method: loadMapObject
85      */
86     loadMapObject:function() {
87         try { //crash proofing
88             this.mapObject = new MultimapViewer(this.div);
89         } catch (e) { }
90     },
91
92     /** 
93      * APIMethod: getWarningHTML
94      * 
95      * Returns: 
96      * {String} String with information on why layer is broken, how to get
97      *          it working.
98      */
99     getWarningHTML:function() {
100         return OpenLayers.i18n(
101             "getLayerWarning", {'layerType':"MM", 'layerLib':"MultiMap"}
102         );
103     },
104
105
106
107     /************************************
108      *                                  *
109      *   MapObject Interface Controls   *
110      *                                  *
111      ************************************/
112
113
114   // Get&Set Center, Zoom
115
116     /** 
117      * APIMethod: setMapObjectCenter
118      * Set the mapObject to the specified center and zoom
119      * 
120      * Parameters:
121      * center - {Object} MapObject LonLat format
122      * zoom - {int} MapObject zoom format
123      */
124     setMapObjectCenter: function(center, zoom) {
125         this.mapObject.goToPosition(center, zoom); 
126     },
127    
128     /**
129      * APIMethod: getMapObjectCenter
130      * 
131      * Returns: 
132      * {Object} The mapObject's current center in Map Object format
133      */
134     getMapObjectCenter: function() {
135         return this.mapObject.getCurrentPosition();
136     },
137
138     /** 
139      * APIMethod: getMapObjectZoom
140      * 
141      * Returns:
142      * {Integer} The mapObject's current zoom, in Map Object format
143      */
144     getMapObjectZoom: function() {
145         return this.mapObject.getZoomFactor();
146     },
147
148
149   // LonLat - Pixel Translation
150   
151     /**
152      * APIMethod: getMapObjectLonLatFromMapObjectPixel
153      * 
154      * Parameters:
155      * moPixel - {Object} MapObject Pixel format
156      * 
157      * Returns:
158      * {Object} MapObject LonLat translated from MapObject Pixel
159      */
160     getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
161         moPixel.x = moPixel.x - (this.map.getSize().w/2);
162         moPixel.y = moPixel.y - (this.map.getSize().h/2);
163         return this.mapObject.getMapPositionAt(moPixel);
164     },
165
166     /**
167      * APIMethod: getMapObjectPixelFromMapObjectLonLat
168      * 
169      * Parameters:
170      * moLonLat - {Object} MapObject LonLat format
171      * 
172      * Returns:
173      * {Object} MapObject Pixel transtlated from MapObject LonLat
174      */
175     getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
176         return this.mapObject.geoPosToContainerPixels(moLonLat);
177     },
178
179
180     /************************************
181      *                                  *
182      *       MapObject Primitives       *
183      *                                  *
184      ************************************/
185
186
187   // LonLat
188     
189     /**
190      * APIMethod: getLongitudeFromMapObjectLonLat
191      * 
192      * Parameters:
193      * moLonLat - {Object} MapObject LonLat format
194      * 
195      * Returns:
196      * {Float} Longitude of the given MapObject LonLat
197      */
198     getLongitudeFromMapObjectLonLat: function(moLonLat) {
199         return this.sphericalMercator ? 
200             this.forwardMercator(moLonLat.lon, moLonLat.lat).lon :
201             moLonLat.lon;
202     },
203
204     /**
205      * APIMethod: getLatitudeFromMapObjectLonLat
206      * 
207      * Parameters:
208      * moLonLat - {Object} MapObject LonLat format
209      * 
210      * Returns:
211      * {Float} Latitude of the given MapObject LonLat
212      */
213     getLatitudeFromMapObjectLonLat: function(moLonLat) {
214         return this.sphericalMercator ? 
215             this.forwardMercator(moLonLat.lon, moLonLat.lat).lat :
216             moLonLat.lat;
217     },
218
219     /**
220      * APIMethod: getMapObjectLonLatFromLonLat
221      * 
222      * Parameters:
223      * lon - {Float}
224      * lat - {Float}
225      * 
226      * Returns:
227      * {Object} MapObject LonLat built from lon and lat params
228      */
229     getMapObjectLonLatFromLonLat: function(lon, lat) {
230         var mmLatLon;
231         if(this.sphericalMercator) {
232             var lonlat = this.inverseMercator(lon, lat);
233             mmLatLon = new MMLatLon(lonlat.lat, lonlat.lon);
234         } else {
235             mmLatLon = new MMLatLon(lat, lon);
236         }
237         return mmLatLon;
238     },
239
240   // Pixel
241     
242     /**
243      * APIMethod: getXFromMapObjectPixel
244      * 
245      * Parameters:
246      * moPixel - {Object} MapObject Pixel format
247      * 
248      * Returns:
249      * {Integer} X value of the MapObject Pixel
250      */
251     getXFromMapObjectPixel: function(moPixel) {
252         return moPixel.x;
253     },
254
255     /**
256      * APIMethod: getYFromMapObjectPixel
257      * 
258      * Parameters:
259      * moPixel - {Object} MapObject Pixel format
260      * 
261      * Returns:
262      * {Integer} Y value of the MapObject Pixel
263      */
264     getYFromMapObjectPixel: function(moPixel) {
265         return moPixel.y;
266     },
267
268     /**
269      * APIMethod: getMapObjectPixelFromXY
270      * 
271      * Parameters:
272      * x - {Integer}
273      * y - {Integer}
274      * 
275      * Returns:
276      * {Object} MapObject Pixel from x and y parameters
277      */
278     getMapObjectPixelFromXY: function(x, y) {
279         return new MMPoint(x, y);
280     },
281
282     CLASS_NAME: "OpenLayers.Layer.MultiMap"
283 });