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