#627 Adding read-only tilecache layer. Many thanks to crschmidt for the tests here.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@3763 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
58
examples/tilecache.html
Normal file
58
examples/tilecache.html
Normal file
@@ -0,0 +1,58 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<style type="text/css">
|
||||
html, body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
#map {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
#title {
|
||||
position: absolute;
|
||||
left: 1em;
|
||||
bottom: 1em;
|
||||
z-index: 5000;
|
||||
}
|
||||
</style>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
var map, layer;
|
||||
function init(){
|
||||
map = new OpenLayers.Map( $('map'));
|
||||
layer = new OpenLayers.Layer.TileCache("TileCache Layer",
|
||||
["http://c0.labs.metacarta.com/wms-c/cache/",
|
||||
"http://c1.labs.metacarta.com/wms-c/cache/",
|
||||
"http://c2.labs.metacarta.com/wms-c/cache/",
|
||||
"http://c3.labs.metacarta.com/wms-c/cache/",
|
||||
"http://c4.labs.metacarta.com/wms-c/cache/"],
|
||||
"basic");
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||
}
|
||||
|
||||
OpenLayers.Util.onImageLoadError = function() {
|
||||
/**
|
||||
* For images that don't exist in the cache, you can display
|
||||
* a default image - one that looks like water for example.
|
||||
* To show nothing at all, leave the following lines commented out.
|
||||
*/
|
||||
|
||||
//this.src = "../img/blank.gif";
|
||||
//this.style.display = "";
|
||||
};
|
||||
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<div id="map">
|
||||
<div id="title">
|
||||
<b>OpenLayers (Read-Only) TileCache Example</b>
|
||||
<br />from a web accessible disk-based cache only
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -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",
|
||||
|
||||
170
lib/OpenLayers/Layer/TileCache.js
Normal file
170
lib/OpenLayers/Layer/TileCache.js
Normal file
@@ -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.Grid>
|
||||
*/
|
||||
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
|
||||
* {<OpenLayers.LonLat>}
|
||||
**/
|
||||
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 <OpenLayers.Layer.TileCache>
|
||||
*/
|
||||
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<length; ++i) {
|
||||
zeros.push('0');
|
||||
}
|
||||
return zeros.join('').substring(0, length - number.length) + number;
|
||||
}
|
||||
var components = [
|
||||
this.layername,
|
||||
zeroPad(tileZ, 2),
|
||||
zeroPad(parseInt(tileX / 1000000), 3),
|
||||
zeroPad((parseInt(tileX / 1000) % 1000), 3),
|
||||
zeroPad((parseInt(tileX) % 1000), 3),
|
||||
zeroPad(parseInt(tileY / 1000000), 3),
|
||||
zeroPad((parseInt(tileY / 1000) % 1000), 3),
|
||||
zeroPad((parseInt(tileY) % 1000), 3) + '.' + this.extension
|
||||
];
|
||||
var path = components.join('/');
|
||||
var url = this.url;
|
||||
if (url instanceof Array) {
|
||||
url = this.selectUrl(path, url);
|
||||
}
|
||||
url = (url[url.length - 1] == '/') ? url : url + '/';
|
||||
return url + path;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: addTile
|
||||
* addTile creates a tile, initializes it, and
|
||||
* adds it to the layer div.
|
||||
*
|
||||
* Parameters:
|
||||
* bounds - {<OpenLayers.Bounds>}
|
||||
*
|
||||
* Returns:
|
||||
* The added {<OpenLayers.Tile.Image>}
|
||||
*/
|
||||
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 - {<OpenLayers.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"
|
||||
});
|
||||
@@ -47,6 +47,7 @@
|
||||
<li>Layer/test_WMS.html</li>
|
||||
<li>Layer/test_WFS.html</li>
|
||||
<li>Layer/test_TMS.html</li>
|
||||
<li>Layer/test_TileCache.html</li>
|
||||
<li>Layer/test_Vector.html</li>
|
||||
<li>Layer/test_GML.html</li>
|
||||
<li>Layer/test_WrapDateLine.html</li>
|
||||
|
||||
Reference in New Issue
Block a user