]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Layer/WorldWind.js
web interface to add co-administrators
[syp.git] / openlayers / lib / OpenLayers / Layer / WorldWind.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 /**
7  * @requires OpenLayers/Layer/Grid.js
8  */
9
10 /**
11  * Class: OpenLayers.Layer.WorldWind
12  * 
13  * Inherits from:
14  *  - <OpenLayers.Layer.Grid>
15  */
16 OpenLayers.Layer.WorldWind = OpenLayers.Class(OpenLayers.Layer.Grid, {
17     
18     DEFAULT_PARAMS: {
19     },
20
21     /**
22      * APIProperty: isBaseLayer
23      * WorldWind layer is a base layer by default.
24      */
25     isBaseLayer: true,    
26
27     
28     /** 
29      * APIProperty: lzd
30      * LevelZeroTileSizeDegrees
31      */
32     lzd: null,
33
34     /**
35      * APIProperty: zoomLevels
36      * Number of zoom levels.
37      */
38     zoomLevels: null,
39     
40     /**
41      * Constructor: OpenLayers.Layer.WorldWind
42      * 
43      * Parameters:
44      * name - {String} Name of Layer
45      * url - {String} Base URL  
46      * lzd - {Float} Level zero tile size degrees 
47      * zoomLevels - {Int} number of zoom levels
48      * params - {Object} additional parameters
49      * options - {Object} additional options
50      */
51     initialize: function(name, url, lzd, zoomLevels, params, options) {
52         this.lzd = lzd;
53         this.zoomLevels = zoomLevels;
54         var newArguments = [];
55         newArguments.push(name, url, params, options);
56         OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
57         this.params = OpenLayers.Util.applyDefaults(
58             this.params, this.DEFAULT_PARAMS
59         );
60     },
61     /**
62      * Method: addTile
63      * 
64      * Parameters:
65      * bounds - {<OpenLayers.Bounds>}
66      * position - {<OpenLayers.Pixel>}
67      * 
68      * Returns:
69      * {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image
70      */
71     addTile:function(bounds,position) {
72         return new OpenLayers.Tile.Image(this, position, bounds, 
73                                              null, this.tileSize);
74     },
75
76     /**
77      * Method: getZoom
78      * Convert map zoom to WW zoom.
79      */
80     getZoom: function () {
81         var zoom = this.map.getZoom();
82         var extent = this.map.getMaxExtent();
83         zoom = zoom - Math.log(this.maxResolution / (this.lzd/512))/Math.log(2);
84         return zoom;
85     },
86
87     /**
88      * Method: getURL
89      *
90      * Parameters:
91      * bounds - {<OpenLayers.Bounds>} 
92      *
93      * Returns:
94      * {String} A string with the layer's url and parameters and also the 
95      *           passed-in bounds and appropriate tile size specified as 
96      *           parameters
97      */
98     getURL: function (bounds) {
99         bounds = this.adjustBounds(bounds);
100         var zoom = this.getZoom();
101         var extent = this.map.getMaxExtent();
102         var deg = this.lzd/Math.pow(2,this.getZoom());
103         var x = Math.floor((bounds.left - extent.left)/deg);
104         var y = Math.floor((bounds.bottom - extent.bottom)/deg);
105         if (this.map.getResolution() <= (this.lzd/512)
106             && this.getZoom() <= this.zoomLevels) {
107             return this.getFullRequestString(
108               { L: zoom, 
109                 X: x,
110                 Y: y
111               });
112         } else {
113             return OpenLayers.Util.getImagesLocation() + "blank.gif";
114         }
115
116     },
117
118     CLASS_NAME: "OpenLayers.Layer.WorldWind"
119 });