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. */
7 * @requires OpenLayers/Layer/Grid.js
8 * @requires OpenLayers/Layer/KaMap.js
12 * Class: OpenLayers.Layer.KaMapCache
14 * This class is designed to talk directly to a web-accessible ka-Map
15 * cache generated by the precache2.php script.
17 * To create a a new KaMapCache layer, you must indicate also the "i" parameter
18 * (that will be used to calculate the file extension), and another special
19 * parameter, object names "metaTileSize", with "h" (height) and "w" (width)
22 * // Create a new kaMapCache layer.
23 * var kamap_base = new OpenLayers.Layer.KaMapCache(
25 * "http://www.example.org/web/acessible/cache",
26 * {g: "satellite", map: "world", i: 'png24', metaTileSize: {w: 5, h: 5} }
29 * // Create an kaMapCache overlay layer (using "isBaseLayer: false").
30 * // Forces the output to be a "gif", using the "i" parameter.
31 * var kamap_overlay = new OpenLayers.Layer.KaMapCache(
33 * "http://www.example.org/web/acessible/cache",
34 * {g: "streets", map: "world", i: "gif", metaTileSize: {w: 5, h: 5} },
35 * {isBaseLayer: false}
38 * The cache URLs must look like:
39 * var/cache/World/50000/Group_Name/def/t-440320/l20480
41 * This means that the cache generated via tile.php will *not* work with
42 * this class, and should instead use the KaMap layer.
44 * More information is available in Ticket #1518.
47 * - <OpenLayers.Layer.KaMap>
48 * - <OpenLayers.Layer.Grid>
50 OpenLayers.Layer.KaMapCache = OpenLayers.Class(OpenLayers.Layer.KaMap, {
53 * Constant: IMAGE_EXTENSIONS
54 * {Object} Simple hash map to convert format to extension.
66 * Constant: DEFAULT_FORMAT
67 * {Object} Simple hash map to convert format to extension.
69 DEFAULT_FORMAT: 'jpeg',
72 * Constructor: OpenLayers.Layer.KaMapCache
77 * params - {Object} Parameters to be sent to the HTTP server in the
78 * query string for the tile. The format can be set via the 'i'
79 * parameter (defaults to jpg) , and the map should be set via
80 * the 'map' parameter. It has been reported that ka-Map may behave
81 * inconsistently if your format parameter does not match the format
82 * parameter configured in your config.php. (See ticket #327 for more
84 * options - {Object} Additional options for the layer. Any of the
85 * APIProperties listed on this layer, and any layer types it
86 * extends, can be overridden through the options parameter.
88 initialize: function(name, url, params, options) {
89 OpenLayers.Layer.KaMap.prototype.initialize.apply(this, arguments);
90 this.extension = this.IMAGE_EXTENSIONS[this.params.i.toLowerCase() || DEFAULT_FORMAT];
97 * bounds - {<OpenLayers.Bounds>}
100 * {String} A string with the layer's url and parameters and also the
101 * passed-in bounds and appropriate tile size specified as
104 getURL: function (bounds) {
105 bounds = this.adjustBounds(bounds);
106 var mapRes = this.map.getResolution();
107 var scale = Math.round((this.map.getScale() * 10000)) / 10000;
108 var pX = Math.round(bounds.left / mapRes);
109 var pY = -Math.round(bounds.top / mapRes);
111 var metaX = Math.floor(pX / this.tileSize.w / this.params.metaTileSize.w) * this.tileSize.w * this.params.metaTileSize.w;
112 var metaY = Math.floor(pY / this.tileSize.h / this.params.metaTileSize.h) * this.tileSize.h * this.params.metaTileSize.h;
114 // if url is not a string, it should be an array of strings,
115 // in which case we will deterministically select one of them in
116 // order to evenly distribute requests to different urls.
119 if (url instanceof Array) {
120 url = this.selectUrl(paramsString, url);
130 this.params.g.replace(/\s/g, '_'),
143 return components.join("");
146 CLASS_NAME: "OpenLayers.Layer.KaMapCache"