[76] | 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 | * @requires OpenLayers/Tile/Image.js |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | /** |
---|
| 13 | * Class: OpenLayers.Layer.TMS |
---|
| 14 | * |
---|
| 15 | * Inherits from: |
---|
| 16 | * - <OpenLayers.Layer.Grid> |
---|
| 17 | */ |
---|
| 18 | OpenLayers.Layer.TMS = OpenLayers.Class(OpenLayers.Layer.Grid, { |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * APIProperty: serviceVersion |
---|
| 22 | * {String} |
---|
| 23 | */ |
---|
| 24 | serviceVersion: "1.0.0", |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * APIProperty: isBaseLayer |
---|
| 28 | * {Boolean} |
---|
| 29 | */ |
---|
| 30 | isBaseLayer: true, |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * APIProperty: tileOrigin |
---|
| 34 | * {<OpenLayers.Pixel>} |
---|
| 35 | */ |
---|
| 36 | tileOrigin: null, |
---|
| 37 | |
---|
| 38 | /** |
---|
| 39 | * APIProperty: serverResolutions |
---|
| 40 | * {Array} A list of all resolutions available on the server. Only set this |
---|
| 41 | * property if the map resolutions differs from the server. |
---|
| 42 | */ |
---|
| 43 | serverResolutions: null, |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * APIProperty: zoomOffset |
---|
| 47 | * {Number} If your cache has more zoom levels than you want to provide |
---|
| 48 | * access to with this layer, supply a zoomOffset. This zoom offset |
---|
| 49 | * is added to the current map zoom level to determine the level |
---|
| 50 | * for a requested tile. For example, if you supply a zoomOffset |
---|
| 51 | * of 3, when the map is at the zoom 0, tiles will be requested from |
---|
| 52 | * level 3 of your cache. Default is 0 (assumes cache level and map |
---|
| 53 | * zoom are equivalent). Using <zoomOffset> is an alternative to |
---|
| 54 | * setting <serverResolutions> if you only want to expose a subset |
---|
| 55 | * of the server resolutions. |
---|
| 56 | */ |
---|
| 57 | zoomOffset: 0, |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * Constructor: OpenLayers.Layer.TMS |
---|
| 61 | * |
---|
| 62 | * Parameters: |
---|
| 63 | * name - {String} |
---|
| 64 | * url - {String} |
---|
| 65 | * options - {Object} Hashtable of extra options to tag onto the layer |
---|
| 66 | */ |
---|
| 67 | initialize: function(name, url, options) { |
---|
| 68 | var newArguments = []; |
---|
| 69 | newArguments.push(name, url, {}, options); |
---|
| 70 | OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments); |
---|
| 71 | }, |
---|
| 72 | |
---|
| 73 | /** |
---|
| 74 | * APIMethod:destroy |
---|
| 75 | */ |
---|
| 76 | destroy: function() { |
---|
| 77 | // for now, nothing special to do here. |
---|
| 78 | OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments); |
---|
| 79 | }, |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | * APIMethod: clone |
---|
| 84 | * |
---|
| 85 | * Parameters: |
---|
| 86 | * obj - {Object} |
---|
| 87 | * |
---|
| 88 | * Returns: |
---|
| 89 | * {<OpenLayers.Layer.TMS>} An exact clone of this <OpenLayers.Layer.TMS> |
---|
| 90 | */ |
---|
| 91 | clone: function (obj) { |
---|
| 92 | |
---|
| 93 | if (obj == null) { |
---|
| 94 | obj = new OpenLayers.Layer.TMS(this.name, |
---|
| 95 | this.url, |
---|
| 96 | this.getOptions()); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | //get all additions from superclasses |
---|
| 100 | obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); |
---|
| 101 | |
---|
| 102 | // copy/set any non-init, non-simple values here |
---|
| 103 | |
---|
| 104 | return obj; |
---|
| 105 | }, |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | * Method: getURL |
---|
| 109 | * |
---|
| 110 | * Parameters: |
---|
| 111 | * bounds - {<OpenLayers.Bounds>} |
---|
| 112 | * |
---|
| 113 | * Returns: |
---|
| 114 | * {String} A string with the layer's url and parameters and also the |
---|
| 115 | * passed-in bounds and appropriate tile size specified as |
---|
| 116 | * parameters |
---|
| 117 | */ |
---|
| 118 | getURL: function (bounds) { |
---|
| 119 | bounds = this.adjustBounds(bounds); |
---|
| 120 | var res = this.map.getResolution(); |
---|
| 121 | var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w)); |
---|
| 122 | var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h)); |
---|
| 123 | var z = this.serverResolutions != null ? |
---|
| 124 | OpenLayers.Util.indexOf(this.serverResolutions, res) : |
---|
| 125 | this.map.getZoom() + this.zoomOffset; |
---|
| 126 | var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type; |
---|
| 127 | var url = this.url; |
---|
| 128 | if (url instanceof Array) { |
---|
| 129 | url = this.selectUrl(path, url); |
---|
| 130 | } |
---|
| 131 | return url + path; |
---|
| 132 | }, |
---|
| 133 | |
---|
| 134 | /** |
---|
| 135 | * Method: addTile |
---|
| 136 | * addTile creates a tile, initializes it, and adds it to the layer div. |
---|
| 137 | * |
---|
| 138 | * Parameters: |
---|
| 139 | * bounds - {<OpenLayers.Bounds>} |
---|
| 140 | * position - {<OpenLayers.Pixel>} |
---|
| 141 | * |
---|
| 142 | * Returns: |
---|
| 143 | * {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image |
---|
| 144 | */ |
---|
| 145 | addTile:function(bounds,position) { |
---|
| 146 | return new OpenLayers.Tile.Image(this, position, bounds, |
---|
| 147 | null, this.tileSize); |
---|
| 148 | }, |
---|
| 149 | |
---|
| 150 | /** |
---|
| 151 | * APIMethod: setMap |
---|
| 152 | * When the layer is added to a map, then we can fetch our origin |
---|
| 153 | * (if we don't have one.) |
---|
| 154 | * |
---|
| 155 | * Parameters: |
---|
| 156 | * map - {<OpenLayers.Map>} |
---|
| 157 | */ |
---|
| 158 | setMap: function(map) { |
---|
| 159 | OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments); |
---|
| 160 | if (!this.tileOrigin) { |
---|
| 161 | this.tileOrigin = new OpenLayers.LonLat(this.map.maxExtent.left, |
---|
| 162 | this.map.maxExtent.bottom); |
---|
| 163 | } |
---|
| 164 | }, |
---|
| 165 | |
---|
| 166 | CLASS_NAME: "OpenLayers.Layer.TMS" |
---|
| 167 | }); |
---|