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
11 * Class: OpenLayers.Layer.KaMap
14 * - <OpenLayers.Layer.Grid>
16 OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
19 * APIProperty: isBaseLayer
20 * {Boolean} KaMap Layer is always a base layer
31 * APIProperty: resolution
34 resolution: OpenLayers.DOTS_PER_INCH,
37 * Constant: DEFAULT_PARAMS
38 * {Object} parameters set by default. The default parameters set
39 * the format via the 'i' parameter to 'jpeg'.
47 * Constructor: OpenLayers.Layer.KaMap
52 * params - {Object} Parameters to be sent to the HTTP server in the
53 * query string for the tile. The format can be set via the 'i'
54 * parameter (defaults to jpg) , and the map should be set via
55 * the 'map' parameter. It has been reported that ka-Map may behave
56 * inconsistently if your format parameter does not match the format
57 * parameter configured in your config.php. (See ticket #327 for more
59 * options - {Object} Additional options for the layer. Any of the
60 * APIProperties listed on this layer, and any layer types it
61 * extends, can be overridden through the options parameter.
63 initialize: function(name, url, params, options) {
64 var newArguments = [];
65 newArguments.push(name, url, params, options);
66 OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
67 this.params = OpenLayers.Util.applyDefaults(
68 this.params, this.DEFAULT_PARAMS
76 * bounds - {<OpenLayers.Bounds>}
79 * {String} A string with the layer's url and parameters and also the
80 * passed-in bounds and appropriate tile size specified as
83 getURL: function (bounds) {
84 bounds = this.adjustBounds(bounds);
85 var mapRes = this.map.getResolution();
86 var scale = Math.round((this.map.getScale() * 10000)) / 10000;
87 var pX = Math.round(bounds.left / mapRes);
88 var pY = -Math.round(bounds.top / mapRes);
89 return this.getFullRequestString(
100 * bounds - {<OpenLayers.Bounds>}
101 * position - {<OpenLayers.Pixel>}
104 * {<OpenLayers.Tile.Image>}
106 addTile:function(bounds,position) {
107 var url = this.getURL(bounds);
108 return new OpenLayers.Tile.Image(this, position, bounds,
113 * Method: calculateGridLayout
114 * ka-Map uses the center point of the map as an origin for
115 * its tiles. Override calculateGridLayout to center tiles
116 * correctly for this case.
119 * bounds - {<OpenLayers.Bound>}
120 * extent - {<OpenLayers.Bounds>}
121 * resolution - {Number}
124 * Object containing properties tilelon, tilelat, tileoffsetlat,
125 * tileoffsetlat, tileoffsetx, tileoffsety
127 calculateGridLayout: function(bounds, extent, resolution) {
128 var tilelon = resolution*this.tileSize.w;
129 var tilelat = resolution*this.tileSize.h;
131 var offsetlon = bounds.left;
132 var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
133 var tilecolremain = offsetlon/tilelon - tilecol;
134 var tileoffsetx = -tilecolremain * this.tileSize.w;
135 var tileoffsetlon = tilecol * tilelon;
137 var offsetlat = bounds.top;
138 var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
139 var tilerowremain = tilerow - offsetlat/tilelat;
140 var tileoffsety = -(tilerowremain+1) * this.tileSize.h;
141 var tileoffsetlat = tilerow * tilelat;
144 tilelon: tilelon, tilelat: tilelat,
145 tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
146 tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
157 * {<OpenLayers.Layer.Kamap>} An exact clone of this OpenLayers.Layer.KaMap
159 clone: function (obj) {
162 obj = new OpenLayers.Layer.KaMap(this.name,
168 //get all additions from superclasses
169 obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
171 // copy/set any non-init, non-simple values here
172 if (this.tileSize != null) {
173 obj.tileSize = this.tileSize.clone();
176 // we do not want to copy reference to grid, so we make a new array
183 * APIMethod: getTileBounds
184 * Returns The tile bounds for a layer given a pixel location.
187 * viewPortPx - {<OpenLayers.Pixel>} The location in the viewport.
190 * {<OpenLayers.Bounds>} Bounds of the tile at the given pixel location.
192 getTileBounds: function(viewPortPx) {
193 var resolution = this.getResolution();
194 var tileMapWidth = resolution * this.tileSize.w;
195 var tileMapHeight = resolution * this.tileSize.h;
196 var mapPoint = this.getLonLatFromViewPortPx(viewPortPx);
197 var tileLeft = tileMapWidth * Math.floor(mapPoint.lon / tileMapWidth);
198 var tileBottom = tileMapHeight * Math.floor(mapPoint.lat / tileMapHeight);
199 return new OpenLayers.Bounds(tileLeft, tileBottom,
200 tileLeft + tileMapWidth,
201 tileBottom + tileMapHeight);
204 CLASS_NAME: "OpenLayers.Layer.KaMap"