From 5e7b2e03f1e82b3462603ec153af69c36b92609d Mon Sep 17 00:00:00 2001 From: crschmidt Date: Sun, 19 Nov 2006 19:54:42 +0000 Subject: [PATCH] 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 --- build/docs.sh | 2 +- doc/Layer.TMS.txt | 15 ++++ examples/tms.html | 39 +++++++++ lib/OpenLayers.js | 1 + lib/OpenLayers/Layer/TMS.js | 112 ++++++++++++++++++++++++ tests/list-tests.html | 1 + tests/test_Layer_TMS.html | 164 ++++++++++++++++++++++++++++++++++++ 7 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 doc/Layer.TMS.txt create mode 100644 examples/tms.html create mode 100644 lib/OpenLayers/Layer/TMS.js create mode 100644 tests/test_Layer_TMS.html diff --git a/build/docs.sh b/build/docs.sh index 3ec415f1c3..79df71c7b3 100755 --- a/build/docs.sh +++ b/build/docs.sh @@ -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 " OpenLayers Class Reference Documentation diff --git a/doc/Layer.TMS.txt b/doc/Layer.TMS.txt new file mode 100644 index 0000000000..312484859f --- /dev/null +++ b/doc/Layer.TMS.txt @@ -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. diff --git a/examples/tms.html b/examples/tms.html new file mode 100644 index 0000000000..a4832c71f8 --- /dev/null +++ b/examples/tms.html @@ -0,0 +1,39 @@ + + + + + + + + URL of TMS (Should end in /): layer_name
+ Example: http://mapserver.refractions.net/cgi-bin/tms/, global_mosaic, jpg +
+ + diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index 323bda974e..0356c7ecc4 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -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", diff --git a/lib/OpenLayers/Layer/TMS.js b/lib/OpenLayers/Layer/TMS.js new file mode 100644 index 0000000000..a5a22f2ab7 --- /dev/null +++ b/lib/OpenLayers/Layer/TMS.js @@ -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" +}); diff --git a/tests/list-tests.html b/tests/list-tests.html index 74c8dc7852..40d524a32a 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -21,6 +21,7 @@
  • test_Layer_GeoRSS.html
  • test_Layer_KaMap.html
  • test_Layer_WMS.html
  • +
  • test_Layer_TMS.html
  • test_Tile.html
  • test_Tile_Image.html
  • test_Control.html
  • diff --git a/tests/test_Layer_TMS.html b/tests/test_Layer_TMS.html new file mode 100644 index 0000000000..65f5cf98ba --- /dev/null +++ b/tests/test_Layer_TMS.html @@ -0,0 +1,164 @@ + + + + + + +
    + +