Commit TMS support from 'crschmidt/refractions' Ticket #394 , reviewed by
Schuyler. git-svn-id: http://svn.openlayers.org/trunk/openlayers@1927 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm ../doc/reference.html
|
||||
CLASSES="Map Layer Layer.Image Layer.HTTPRequest Layer.Grid Layer.WMS Layer.KaMap Layer.EventPane Layer.Google Layer.VirtualEarth Layer.Markers Layer.Text Layer.GeoRSS Layer.Boxes Icon Marker Marker.Box Tile Tile.Image Tile.WFS Control Control.LayerSwitcher Control.MouseDefaults Control.MousePosition Control.MouseToolbar Control.OverviewMap Control.PanZoom Control.PanZoomBar Control.Permalink Control.Scale LonLat Size Pixel Bounds Util Ajax"
|
||||
CLASSES="Map Layer Layer.Image Layer.HTTPRequest Layer.Grid Layer.WMS Layer.KaMap Layer.EventPane Layer.Google Layer.VirtualEarth Layer.Markers Layer.Text Layer.GeoRSS Layer.Boxes Layer.TMS Icon Marker Marker.Box Tile Tile.Image Tile.WFS Control Control.LayerSwitcher Control.MouseDefaults Control.MousePosition Control.MouseToolbar Control.OverviewMap Control.PanZoom Control.PanZoomBar Control.Permalink Control.Scale LonLat Size Pixel Bounds Util Ajax"
|
||||
echo "<html>
|
||||
<head>
|
||||
<title>OpenLayers Class Reference Documentation</title>
|
||||
|
||||
15
doc/Layer.TMS.txt
Normal file
15
doc/Layer.TMS.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
OpenLayers.Layer.TMS
|
||||
|
||||
The TMS layer allows one to connect to a TMS -- Tiled Map Service -- server to obtain images.
|
||||
|
||||
* Constructor
|
||||
OpenLayers.Layer.TMS(name, url, options) -- URL is the base URL to the layer. Options is a set of options, extending the parameters of the layer.
|
||||
|
||||
* Methods
|
||||
getURL({OpenLayers.Bounds|bounds}) -- {String} -- Returns a TMS URL for the given bounds based on the properties of the layer.
|
||||
All other methods are inherited from {OpenLayers.Layer.Grid}
|
||||
|
||||
* Options
|
||||
tileOrigin -- The tileOrigin option will allow you to set your tileOrigin to something other than the lower left extent of your map.
|
||||
layername -- Name of the layer in the TMS request.
|
||||
type -- The extension images have.
|
||||
39
examples/tms.html
Normal file
39
examples/tms.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<style type="text/css">
|
||||
#map {
|
||||
width: 800px;
|
||||
height: 475px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
var lon = 5;
|
||||
var lat = 40;
|
||||
var zoom = 5;
|
||||
var map, layer;
|
||||
|
||||
function init(){
|
||||
map = new OpenLayers.Map( $('map'), {maxResolution:1.40625/2} );
|
||||
layer = new OpenLayers.Layer.TMS( "TMS",
|
||||
"http://labs.metacarta.com/wms-c/Basic.py/", {layername: 'basic', type:'png'} );
|
||||
map.addLayer(layer);
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
|
||||
}
|
||||
function addTMS() {
|
||||
l=new OpenLayers.Layer.TMS($('layer').value, $('url').value, {layername: $('layer').value, type:$('type').value});
|
||||
map.addLayer(l);
|
||||
map.setBaseLayer(l);
|
||||
}
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
URL of TMS (Should end in /): <input type="text" id="url" size="60" /> layer_name <input type="text" id="layer" /> <select id="type"><option>png</option><option>jpg</option></select> <input type="submit" onclick="addTMS()"/><br />
|
||||
Example: http://mapserver.refractions.net/cgi-bin/tms/, global_mosaic, jpg
|
||||
<div id="map"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -86,6 +86,7 @@ if (typeof(_OPENLAYERS_SFL_) == "undefined") {
|
||||
"OpenLayers/Layer/GeoRSS.js",
|
||||
"OpenLayers/Layer/Boxes.js",
|
||||
"OpenLayers/Layer/Canvas.js",
|
||||
"OpenLayers/Layer/TMS.js",
|
||||
"OpenLayers/Popup/Anchored.js",
|
||||
"OpenLayers/Popup/AnchoredBubble.js",
|
||||
"OpenLayers/Control.js",
|
||||
|
||||
112
lib/OpenLayers/Layer/TMS.js
Normal file
112
lib/OpenLayers/Layer/TMS.js
Normal file
@@ -0,0 +1,112 @@
|
||||
/* 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. */
|
||||
|
||||
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
* @requires OpenLayers/Layer/Grid.js
|
||||
*/
|
||||
OpenLayers.Layer.TMS = OpenLayers.Class.create();
|
||||
OpenLayers.Layer.TMS.prototype =
|
||||
OpenLayers.Class.inherit( OpenLayers.Layer.Grid, {
|
||||
|
||||
|
||||
reproject: false,
|
||||
isBaseLayer: true,
|
||||
tileOrigin: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {String} url
|
||||
* @param {Object} params
|
||||
* @param {Object} options Hashtable of extra options to tag onto the layer
|
||||
*/
|
||||
initialize: function(name, url, options) {
|
||||
var newArguments = new Array();
|
||||
newArguments.push(name, url, {}, options);
|
||||
OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
destroy: function() {
|
||||
// for now, nothing special to do here.
|
||||
OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @param {Object} obj
|
||||
*
|
||||
* @returns An exact clone of this OpenLayers.Layer.TMS
|
||||
* @type OpenLayers.Layer.TMS
|
||||
*/
|
||||
clone: function (obj) {
|
||||
|
||||
if (obj == null) {
|
||||
obj = new OpenLayers.Layer.TMS(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;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
*
|
||||
* @returns A string with the layer's url and parameters and also the
|
||||
* passed-in bounds and appropriate tile size specified as
|
||||
* parameters
|
||||
* @type String
|
||||
*/
|
||||
getURL: function (bounds) {
|
||||
var res = this.map.getResolution();
|
||||
var x = (bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w);
|
||||
var y = (bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h);
|
||||
var z = this.map.getZoom();
|
||||
return this.url + "1.0.0" + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
|
||||
},
|
||||
|
||||
/**
|
||||
* addTile creates a tile, initializes it, and
|
||||
* adds it to the layer div.
|
||||
*
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
*
|
||||
* @returns The added OpenLayers.Tile.Image
|
||||
* @type OpenLayers.Tile.Image
|
||||
*/
|
||||
addTile:function(bounds,position) {
|
||||
var url = this.getURL(bounds);
|
||||
return new OpenLayers.Tile.Image(this, position, bounds,
|
||||
url, this.tileSize);
|
||||
},
|
||||
|
||||
/** When the layer is added to a map, then we can fetch our origin
|
||||
* (if we don't have one.)
|
||||
*
|
||||
* @param {OpenLayers.Map} 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);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Layer.TMS"
|
||||
});
|
||||
@@ -21,6 +21,7 @@
|
||||
<li>test_Layer_GeoRSS.html</li>
|
||||
<li>test_Layer_KaMap.html</li>
|
||||
<li>test_Layer_WMS.html</li>
|
||||
<li>test_Layer_TMS.html</li>
|
||||
<li>test_Tile.html</li>
|
||||
<li>test_Tile_Image.html</li>
|
||||
<li>test_Control.html</li>
|
||||
|
||||
164
tests/test_Layer_TMS.html
Normal file
164
tests/test_Layer_TMS.html
Normal file
@@ -0,0 +1,164 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript"><!--
|
||||
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
|
||||
var layer;
|
||||
|
||||
var name = 'Test Layer';
|
||||
var url = "http://labs.metacarta.com/wms-c/Basic.py/";
|
||||
var options = {'layername':'basic', 'type':'png'};
|
||||
|
||||
|
||||
function test_01_Layer_TMS_constructor (t) {
|
||||
t.plan( 1 );
|
||||
|
||||
layer = new OpenLayers.Layer.TMS(name, url, options);
|
||||
t.ok( layer instanceof OpenLayers.Layer.TMS, "returns OpenLayers.Layer.TMS object" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
function test_03_Layer_TMS_clearTiles (t) {
|
||||
t.plan( 1 );
|
||||
var map = new OpenLayers.Map('map');
|
||||
layer = new OpenLayers.Layer.TMS(name, url, options);
|
||||
map.addLayer(layer);
|
||||
|
||||
map.setCenter(new OpenLayers.LonLat(0,0));
|
||||
|
||||
//grab a reference to one of the tiles
|
||||
var tile = layer.grid[0][0];
|
||||
|
||||
layer.clearGrid();
|
||||
|
||||
t.ok( layer.grid != null, "layer.grid does not get nullified" );
|
||||
}
|
||||
|
||||
|
||||
function test_04_Layer_TMS_getTMSBounds(t) {
|
||||
t.plan( 1 );
|
||||
|
||||
layer = new OpenLayers.Layer.TMS(name, url, options);
|
||||
|
||||
var bl = { bounds: new OpenLayers.Bounds(1,2,0,0)};
|
||||
var tr = { bounds: new OpenLayers.Bounds(0,0,3,4)};
|
||||
layer.grid = [ [6, tr],
|
||||
[bl, 7]];
|
||||
|
||||
var bounds = layer.getGridBounds();
|
||||
|
||||
var testBounds = new OpenLayers.Bounds(1,2,3,4);
|
||||
|
||||
t.ok( bounds.equals(testBounds), "getTMSBounds() returns correct bounds")
|
||||
|
||||
layer.grid = null;
|
||||
}
|
||||
|
||||
function test_05_Layer_TMS_getResolution(t) {
|
||||
t.plan( 1 );
|
||||
|
||||
var map = new OpenLayers.Map('map');
|
||||
layer = new OpenLayers.Layer.TMS(name, url, options);
|
||||
map.addLayer(layer);
|
||||
|
||||
map.zoom = 5;
|
||||
|
||||
t.eq( layer.getResolution(), 0.0439453125, "getResolution() returns correct value");
|
||||
}
|
||||
|
||||
function test_06_Layer_TMS_getZoomForExtent(t) {
|
||||
t.plan( 2 );
|
||||
var bounds, zoom;
|
||||
|
||||
var map = new OpenLayers.Map('map');
|
||||
layer = new OpenLayers.Layer.TMS(name, url, options);
|
||||
map.addLayer(layer);
|
||||
|
||||
bounds = new OpenLayers.Bounds(10,10,12,12);
|
||||
zoom = layer.getZoomForExtent(bounds);
|
||||
|
||||
t.eq( zoom, 8, "getZoomForExtent() returns correct value");
|
||||
|
||||
bounds = new OpenLayers.Bounds(10,10,100,100);
|
||||
zoom = layer.getZoomForExtent(bounds);
|
||||
|
||||
t.eq( zoom, 2, "getZoomForExtent() returns correct value");
|
||||
}
|
||||
|
||||
|
||||
/** THIS WOULD BE WHERE THE TESTS WOULD GO FOR
|
||||
*
|
||||
* -moveTo
|
||||
* -insertColumn
|
||||
* -insertRow
|
||||
|
||||
function 07_Layer_TMS_moveTo(t) {
|
||||
}
|
||||
|
||||
function 08_Layer_TMS_insertColumn(t) {
|
||||
}
|
||||
|
||||
function 09_Layer_TMS_insertRow(t) {
|
||||
}
|
||||
|
||||
*
|
||||
*/
|
||||
function test_10_Layer_TMS_getURL(t) {
|
||||
|
||||
t.plan(1);
|
||||
|
||||
var map = new OpenLayers.Map('map', options);
|
||||
var options = {'layername':'basic', 'type':'png'};
|
||||
layer = new OpenLayers.Layer.TMS(name, url, options);
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LonLat(0,0), 9);
|
||||
var tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125));
|
||||
t.eq(tileurl, "http://labs.metacarta.com/wms-c/Basic.py/1.0.0/basic/9/261/192.png", "Tile URL is correct");
|
||||
}
|
||||
|
||||
function test_11_Layer_TMS_setMap(t) {
|
||||
|
||||
t.plan(3);
|
||||
|
||||
var map = new OpenLayers.Map('map', options);
|
||||
layer = new OpenLayers.Layer.TMS(name, url, options);
|
||||
|
||||
t.eq(layer.tileOrigin, null, "Tile origin starts out null");
|
||||
layer.setMap(map);
|
||||
|
||||
t.eq(layer.tileOrigin.lat, -90, "lat is -90");
|
||||
t.eq(layer.tileOrigin.lon, -180, "lon is -180");
|
||||
}
|
||||
|
||||
function test_99_Layer_TMS_destroy (t) {
|
||||
|
||||
t.plan( 3 );
|
||||
|
||||
var map = new OpenLayers.Map('map');
|
||||
layer = new OpenLayers.Layer.TMS(name, url, options);
|
||||
map.addLayer(layer);
|
||||
layer.destroy();
|
||||
t.eq( layer.grid, null, "layer.grid is null after destroy" );
|
||||
t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" );
|
||||
|
||||
|
||||
//test with tile creation
|
||||
layer = new OpenLayers.Layer.TMS(name, url, options);
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LonLat(0,0), 5);
|
||||
//grab a reference to one of the tiles
|
||||
var tile = layer.grid[0][0];
|
||||
|
||||
layer.destroy();
|
||||
|
||||
t.ok( layer.grid == null, "tiles appropriately destroyed");
|
||||
}
|
||||
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width:500px;height:550px"></div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user