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

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Layer/Yahoo.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
/**
 
7
 * @requires OpenLayers/Layer/EventPane.js
 
8
 * @requires OpenLayers/Layer/FixedZoomLevels.js
 
9
 */
 
10
 
 
11
/**
 
12
 * Class: OpenLayers.Layer.Yahoo
 
13
 * 
 
14
 * Inherits from:
 
15
 *  - <OpenLayers.Layer.EventPane>
 
16
 *  - <OpenLayers.Layer.FixedZoomLevels>
 
17
 */
 
18
OpenLayers.Layer.Yahoo = OpenLayers.Class(
 
19
  OpenLayers.Layer.EventPane, OpenLayers.Layer.FixedZoomLevels, {
 
20
    
 
21
    /** 
 
22
     * Constant: MIN_ZOOM_LEVEL
 
23
     * {Integer} 0 
 
24
     */
 
25
    MIN_ZOOM_LEVEL: 0,
 
26
    
 
27
    /** 
 
28
     * Constant: MAX_ZOOM_LEVEL
 
29
     * {Integer} 15
 
30
     */
 
31
    MAX_ZOOM_LEVEL: 15,
 
32
 
 
33
    /** 
 
34
     * Constant: RESOLUTIONS
 
35
     * {Array(Float)} Hardcode these resolutions so that they are more closely
 
36
     *                tied with the standard wms projection
 
37
     */
 
38
    RESOLUTIONS: [
 
39
        1.40625, 
 
40
        0.703125, 
 
41
        0.3515625, 
 
42
        0.17578125, 
 
43
        0.087890625, 
 
44
        0.0439453125,
 
45
        0.02197265625, 
 
46
        0.010986328125, 
 
47
        0.0054931640625, 
 
48
        0.00274658203125, 
 
49
        0.001373291015625, 
 
50
        0.0006866455078125, 
 
51
        0.00034332275390625, 
 
52
        0.000171661376953125, 
 
53
        0.0000858306884765625, 
 
54
        0.00004291534423828125
 
55
    ],
 
56
 
 
57
    /**
 
58
     * APIProperty: type
 
59
     * {YahooMapType}
 
60
     */
 
61
    type: null,
 
62
    
 
63
    /**
 
64
     * APIProperty: sphericalMercator
 
65
     * {Boolean} Should the map act as a mercator-projected map? This will
 
66
     * cause all interactions with the map to be in the actual map projection,
 
67
     * which allows support for vector drawing, overlaying other maps, etc. 
 
68
     */
 
69
    sphericalMercator: false, 
 
70
 
 
71
    /** 
 
72
     * Constructor: OpenLayers.Layer.Yahoo
 
73
     * 
 
74
     * Parameters:
 
75
     * name - {String}
 
76
     * options - {Object}
 
77
     */
 
78
    initialize: function(name, options) {
 
79
        OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
 
80
        OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this, 
 
81
                                                                    arguments);
 
82
        if(this.sphericalMercator) {
 
83
            OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
 
84
            this.initMercatorParameters();
 
85
        }
 
86
    },
 
87
    
 
88
    /**
 
89
     * Method: loadMapObject
 
90
     */
 
91
    loadMapObject:function() {
 
92
        try { //do not crash! 
 
93
            var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
 
94
            this.mapObject = new YMap(this.div, this.type, size);
 
95
            this.mapObject.disableKeyControls();
 
96
            this.mapObject.disableDragMap();
 
97
 
 
98
            //can we do smooth panning? (moveByXY is not an API function)
 
99
            if ( !this.mapObject.moveByXY || 
 
100
                 (typeof this.mapObject.moveByXY != "function" ) ) {
 
101
 
 
102
                this.dragPanMapObject = null;
 
103
            }                
 
104
        } catch(e) {}
 
105
    },
 
106
 
 
107
    /**
 
108
     * Method: onMapResize
 
109
     * 
 
110
     */
 
111
    onMapResize: function() {
 
112
        try {
 
113
            var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
 
114
            this.mapObject.resizeTo(size);
 
115
        } catch(e) {}     
 
116
    },    
 
117
    
 
118
    
 
119
    /** 
 
120
     * APIMethod: setMap
 
121
     * Overridden from EventPane because we need to remove this yahoo event
 
122
     *     pane which prohibits our drag and drop, and we can only do this 
 
123
     *     once the map has been loaded and centered.
 
124
     * 
 
125
     * Parameters:
 
126
     * map - {<OpenLayers.Map>}
 
127
     */
 
128
    setMap: function(map) {
 
129
        OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
 
130
 
 
131
        this.map.events.register("moveend", this, this.fixYahooEventPane);
 
132
    },
 
133
 
 
134
    /** 
 
135
     * Method: fixYahooEventPane
 
136
     * The map has been centered, so the mysterious yahoo eventpane has been
 
137
     *     added. we remove it so that it doesnt mess with *our* event pane.
 
138
     */
 
139
    fixYahooEventPane: function() {
 
140
        var yahooEventPane = OpenLayers.Util.getElement("ygddfdiv");
 
141
        if (yahooEventPane != null) {
 
142
            if (yahooEventPane.parentNode != null) {
 
143
                yahooEventPane.parentNode.removeChild(yahooEventPane);
 
144
            }
 
145
            this.map.events.unregister("moveend", this, 
 
146
                                       this.fixYahooEventPane);
 
147
        }
 
148
    },
 
149
 
 
150
    /** 
 
151
     * APIMethod: getWarningHTML
 
152
     * 
 
153
     * Returns: 
 
154
     * {String} String with information on why layer is broken, how to get
 
155
     *          it working.
 
156
     */
 
157
    getWarningHTML:function() {
 
158
        return OpenLayers.i18n(
 
159
            "getLayerWarning", {'layerType':'Yahoo', 'layerLib':'Yahoo'}
 
160
        );
 
161
    },
 
162
 
 
163
  /********************************************************/
 
164
  /*                                                      */
 
165
  /*             Translation Functions                    */
 
166
  /*                                                      */
 
167
  /*    The following functions translate GMaps and OL    */ 
 
168
  /*     formats for Pixel, LonLat, Bounds, and Zoom      */
 
169
  /*                                                      */
 
170
  /********************************************************/
 
171
 
 
172
 
 
173
  //
 
174
  // TRANSLATION: MapObject Zoom <-> OpenLayers Zoom
 
175
  //
 
176
  
 
177
    /**
 
178
     * APIMethod: getOLZoomFromMapObjectZoom
 
179
     * 
 
180
     * Parameters:
 
181
     * gZoom - {Integer}
 
182
     * 
 
183
     * Returns:
 
184
     * {Integer} An OpenLayers Zoom level, translated from the passed in gZoom
 
185
     *           Returns null if null value is passed in.
 
186
     */
 
187
    getOLZoomFromMapObjectZoom: function(moZoom) {
 
188
        var zoom = null;
 
189
        if (moZoom != null) {
 
190
            zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getOLZoomFromMapObjectZoom.apply(this, [moZoom]);
 
191
            zoom = 18 - zoom;
 
192
        }
 
193
        return zoom;
 
194
    },
 
195
    
 
196
    /**
 
197
     * APIMethod: getMapObjectZoomFromOLZoom
 
198
     * 
 
199
     * Parameters:
 
200
     * olZoom - {Integer}
 
201
     * 
 
202
     * Returns:
 
203
     * {Integer} A MapObject level, translated from the passed in olZoom
 
204
     *           Returns null if null value is passed in
 
205
     */
 
206
    getMapObjectZoomFromOLZoom: function(olZoom) {
 
207
        var zoom = null; 
 
208
        if (olZoom != null) {
 
209
            zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getMapObjectZoomFromOLZoom.apply(this, [olZoom]);
 
210
            zoom = 18 - zoom;
 
211
        }
 
212
        return zoom;
 
213
    },
 
214
 
 
215
    /************************************
 
216
     *                                  *
 
217
     *   MapObject Interface Controls   *
 
218
     *                                  *
 
219
     ************************************/
 
220
 
 
221
 
 
222
  // Get&Set Center, Zoom
 
223
 
 
224
    /** 
 
225
     * APIMethod: setMapObjectCenter
 
226
     * Set the mapObject to the specified center and zoom
 
227
     * 
 
228
     * Parameters:
 
229
     * center - {Object} MapObject LonLat format
 
230
     * zoom - {int} MapObject zoom format
 
231
     */
 
232
    setMapObjectCenter: function(center, zoom) {
 
233
        this.mapObject.drawZoomAndCenter(center, zoom); 
 
234
    },
 
235
   
 
236
    /**
 
237
     * APIMethod: getMapObjectCenter
 
238
     * 
 
239
     * Returns: 
 
240
     * {Object} The mapObject's current center in Map Object format
 
241
     */
 
242
    getMapObjectCenter: function() {
 
243
        return this.mapObject.getCenterLatLon();
 
244
    },
 
245
 
 
246
    /**
 
247
     * APIMethod: dragPanMapObject
 
248
     * 
 
249
     * Parameters:
 
250
     * dX - {Integer}
 
251
     * dY - {Integer}
 
252
     */
 
253
    dragPanMapObject: function(dX, dY) {
 
254
        this.mapObject.moveByXY({
 
255
            'x': -dX,
 
256
            'y': dY
 
257
        });
 
258
    },
 
259
    
 
260
    /** 
 
261
     * APIMethod: getMapObjectZoom
 
262
     * 
 
263
     * Returns:
 
264
     * {Integer} The mapObject's current zoom, in Map Object format
 
265
     */
 
266
    getMapObjectZoom: function() {
 
267
        return this.mapObject.getZoomLevel();
 
268
    },
 
269
 
 
270
 
 
271
  // LonLat - Pixel Translation
 
272
  
 
273
    /**
 
274
     * APIMethod: getMapObjectLonLatFromMapObjectPixel
 
275
     * 
 
276
     * Parameters:
 
277
     * moPixel - {Object} MapObject Pixel format
 
278
     * 
 
279
     * Returns:
 
280
     * {Object} MapObject LonLat translated from MapObject Pixel
 
281
     */
 
282
    getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
 
283
        return this.mapObject.convertXYLatLon(moPixel);
 
284
    },
 
285
 
 
286
    /**
 
287
     * APIMethod: getMapObjectPixelFromMapObjectLonLat
 
288
     * 
 
289
     * Parameters:
 
290
     * moLonLat - {Object} MapObject LonLat format
 
291
     * 
 
292
     * Returns:
 
293
     * {Object} MapObject Pixel transtlated from MapObject LonLat
 
294
     */
 
295
    getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
 
296
        return this.mapObject.convertLatLonXY(moLonLat);
 
297
    },
 
298
 
 
299
 
 
300
    /************************************
 
301
     *                                  *
 
302
     *       MapObject Primitives       *
 
303
     *                                  *
 
304
     ************************************/
 
305
 
 
306
 
 
307
  // LonLat
 
308
    
 
309
    /**
 
310
     * APIMethod: getLongitudeFromMapObjectLonLat
 
311
     * 
 
312
     * Parameters:
 
313
     * moLonLat - {Object} MapObject LonLat format
 
314
     * 
 
315
     * Returns:
 
316
     * {Float} Longitude of the given MapObject LonLat
 
317
     */
 
318
    getLongitudeFromMapObjectLonLat: function(moLonLat) {
 
319
        return this.sphericalMercator ? 
 
320
            this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lon :
 
321
            moLonLat.Lon;
 
322
    },
 
323
 
 
324
    /**
 
325
     * APIMethod: getLatitudeFromMapObjectLonLat
 
326
     * 
 
327
     * Parameters:
 
328
     * moLonLat - {Object} MapObject LonLat format
 
329
     * 
 
330
     * Returns:
 
331
     * {Float} Latitude of the given MapObject LonLat
 
332
     */
 
333
    getLatitudeFromMapObjectLonLat: function(moLonLat) {
 
334
        return this.sphericalMercator ? 
 
335
            this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lat :
 
336
            moLonLat.Lat;
 
337
    },
 
338
 
 
339
    /**
 
340
     * APIMethod: getMapObjectLonLatFromLonLat
 
341
     * 
 
342
     * Parameters:
 
343
     * lon - {Float}
 
344
     * lat - {Float}
 
345
     * 
 
346
     * Returns:
 
347
     * {Object} MapObject LonLat built from lon and lat params
 
348
     */
 
349
    getMapObjectLonLatFromLonLat: function(lon, lat) {
 
350
        var yLatLong;
 
351
        if(this.sphericalMercator) {
 
352
            var lonlat = this.inverseMercator(lon, lat);
 
353
            yLatLong = new YGeoPoint(lonlat.lat, lonlat.lon);
 
354
        } else {
 
355
            yLatLong = new YGeoPoint(lat, lon);
 
356
        }
 
357
        return yLatLong;
 
358
    },
 
359
 
 
360
  // Pixel
 
361
    
 
362
    /**
 
363
     * APIMethod: getXFromMapObjectPixel
 
364
     * 
 
365
     * Parameters:
 
366
     * moPixel - {Object} MapObject Pixel format
 
367
     * 
 
368
     * Returns:
 
369
     * {Integer} X value of the MapObject Pixel
 
370
     */
 
371
    getXFromMapObjectPixel: function(moPixel) {
 
372
        return moPixel.x;
 
373
    },
 
374
 
 
375
    /**
 
376
     * APIMethod: getYFromMapObjectPixel
 
377
     * 
 
378
     * Parameters:
 
379
     * moPixel - {Object} MapObject Pixel format
 
380
     * 
 
381
     * Returns:
 
382
     * {Integer} Y value of the MapObject Pixel
 
383
     */
 
384
    getYFromMapObjectPixel: function(moPixel) {
 
385
        return moPixel.y;
 
386
    },
 
387
 
 
388
    /**
 
389
     * APIMethod: getMapObjectPixelFromXY
 
390
     * 
 
391
     * Parameters:
 
392
     * x - {Integer}
 
393
     * y - {Integer}
 
394
     * 
 
395
     * Returns:
 
396
     * {Object} MapObject Pixel from x and y parameters
 
397
     */
 
398
    getMapObjectPixelFromXY: function(x, y) {
 
399
        return new YCoordPoint(x, y);
 
400
    },
 
401
    
 
402
  // Size
 
403
  
 
404
    /**
 
405
     * APIMethod: getMapObjectSizeFromOLSize
 
406
     * 
 
407
     * Parameters:
 
408
     * olSize - {<OpenLayers.Size>}
 
409
     * 
 
410
     * Returns:
 
411
     * {Object} MapObject Size from olSize parameter
 
412
     */
 
413
    getMapObjectSizeFromOLSize: function(olSize) {
 
414
        return new YSize(olSize.w, olSize.h);
 
415
    },
 
416
    
 
417
    CLASS_NAME: "OpenLayers.Layer.Yahoo"
 
418
});