diff --git a/examples/tilecache.html b/examples/tilecache.html new file mode 100644 index 0000000000..1c151267a5 --- /dev/null +++ b/examples/tilecache.html @@ -0,0 +1,58 @@ + + + + + + + +
+
+ OpenLayers (Read-Only) TileCache Example +
from a web accessible disk-based cache only +
+ + diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index 61f7c87b4c..5d05dc1ab9 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -110,6 +110,7 @@ "OpenLayers/Layer/GeoRSS.js", "OpenLayers/Layer/Boxes.js", "OpenLayers/Layer/TMS.js", + "OpenLayers/Layer/TileCache.js", "OpenLayers/Popup/Anchored.js", "OpenLayers/Popup/AnchoredBubble.js", "OpenLayers/Handler.js", diff --git a/lib/OpenLayers/Layer/TileCache.js b/lib/OpenLayers/Layer/TileCache.js new file mode 100644 index 0000000000..659b89fdaf --- /dev/null +++ b/lib/OpenLayers/Layer/TileCache.js @@ -0,0 +1,170 @@ +/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD licence. + * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt + * for the full text of the license. */ + + +/** + * @requires OpenLayers/Layer/Grid.js + * + * Class: OpenLayers.Layer.TileCache + * + * Inherits from: + * - + */ +OpenLayers.Layer.TileCache = OpenLayers.Class.create(); +OpenLayers.Layer.TileCache.prototype = + OpenLayers.Class.inherit( OpenLayers.Layer.Grid, { + + /** + * APIProperty: reproject + * {Boolean} + **/ + reproject: false, + + /** + * APIProperty: isBaseLayer + * {Boolean} + **/ + isBaseLayer: true, + + /** + * APIProperty: tileOrigin + * {} + **/ + tileOrigin: null, + + /** + * APIProperty: format + * {String} + **/ + format: 'image/png', + + /** + * Constructor: OpenLayers.Layer.TileCache + * + * Parameters: + * name - {String} + * url - {String} + * layername - {String} + * options - {Object} Hashtable of extra options to tag onto the layer + */ + initialize: function(name, url, layername, options) { + options = OpenLayers.Util.extend({maxResolution: 180/256}, options); + this.layername = layername; + OpenLayers.Layer.Grid.prototype.initialize.apply(this, + [name, url, {}, options]); + this.extension = this.format.split('/')[1].toLowerCase(); + this.extension = (this.extension == 'jpeg') ? 'jpg' : this.extension; + }, + + /** + * APIMethod: clone + * obj - {Object} + * + * Returns: + * An exact clone of this + */ + clone: function (obj) { + + if (obj == null) { + obj = new OpenLayers.Layer.TileCache(this.name, + this.url, + this.options); + } + + //get all additions from superclasses + obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); + + // copy/set any non-init, non-simple values here + + return obj; + }, + + /** + * Method: getURL + * + * Parameters: + * bounds - {OpenLayers.Bounds} + * + * Returns: + * A string with the layer's url and parameters and also the + * passed-in bounds and appropriate tile size specified as + * parameters + */ + getURL: function(bounds) { + var res = this.map.getResolution(); + var bbox = this.maxExtent; + var size = this.tileSize; + var tileX = Math.floor((bounds.left - bbox.left) / (res * size.w)); + var tileY = Math.floor((bounds.bottom - bbox.bottom) / (res * size.h)); + var tileZ = this.map.zoom; + /** + * Zero-pad a positive integer. + * number - {Int} + * length - {Int} + + * Returns: + * A zero-padded string + */ + function zeroPad(number, length) { + number = String(number); + var zeros = []; + for(var i=0; i} + * + * Returns: + * The added {} + */ + addTile:function(bounds, position) { + var url = this.getURL(bounds); + return new OpenLayers.Tile.Image(this, position, bounds, + url, this.tileSize); + }, + + /** + * Method: setMap + * When the layer is added to a map, then we can fetch our origin + * (if we don't have one.) + * + * Parameters: + * map - {} + */ + setMap: function(map) { + OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments); + if (!this.tileOrigin) { + this.tileOrigin = new OpenLayers.LonLat(this.map.maxExtent.left, + this.map.maxExtent.bottom); + } + }, + + CLASS_NAME: "OpenLayers.Layer.TileCache" +}); diff --git a/tests/list-tests.html b/tests/list-tests.html index 4d7d815b70..6993d7891b 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -47,6 +47,7 @@
  • Layer/test_WMS.html
  • Layer/test_WFS.html
  • Layer/test_TMS.html
  • +
  • Layer/test_TileCache.html
  • Layer/test_Vector.html
  • Layer/test_GML.html
  • Layer/test_WrapDateLine.html