Adding a WMTS layer and capabilities parser to work with OGC WMTS service implementations. Thanks August Town for this nice contribution. p=august,me r=me (closes #2637)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10388 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2010-06-12 02:41:51 +00:00
parent f7113df376
commit d1e24bdcc0
11 changed files with 2450 additions and 0 deletions

31
examples/wmts.html Normal file
View File

@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>OpenLayers WMTS Example</title>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css"/>
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="../lib/Firebug/firebug.js"></script>
<script src="../lib/OpenLayers.js"></script>
<script src="wmts.js"></script>
</head>
<body onload="init();">
<h1 id="title">Web Map Tile Service (WMTS) Layer</h1>
<p id="shortdesc">
The WMTS layer allows viewing of tiles from a server implementing
the OGC Web Map Tile Service (WMTS) standard version 1.0.0.
</p>
<div id="map" class="smallmap"></div>
<div id="docs">
<p>
This example uses an OpenLayers.Layer.WMTS layer to display
cached tiles over an OSM layer in spherical mercator coordinates.
</p><p>
See the <a href="wmts.js" target="_blank">
wmts.js source</a> to see how this is done.
</p>
</div>
</body>
</html>

40
examples/wmts.js Normal file
View File

@@ -0,0 +1,40 @@
var map;
function init() {
map = new OpenLayers.Map({
div: "map",
projection: "EPSG:900913",
units: "m",
maxExtent: new OpenLayers.Bounds(
-20037508.34, -20037508.34, 20037508.34, 20037508.34
),
maxResolution: 156543.0339
});
var osm = new OpenLayers.Layer.OSM();
// If tile matrix identifiers differ from zoom levels (0, 1, 2, ...)
// then they must be explicitly provided.
var matrixIds = new Array(26);
for (var i=0; i<26; ++i) {
matrixIds[i] = "EPSG:900913:" + i;
}
var wmts = new OpenLayers.Layer.WMTS({
name: "Medford Buildings",
url: "http://v2.suite.opengeo.org/geoserver/gwc/service/wmts/",
layer: "medford:buildings",
matrixSet: "EPSG:900913",
matrixIds: matrixIds,
format: "image/png",
style: "_null",
opacity: 0.7,
isBaseLayer: false
});
map.addLayers([osm, wmts]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.setCenter(new OpenLayers.LonLat(-13677832, 5213272), 13);
}

View File

@@ -124,6 +124,7 @@
"OpenLayers/Layer/WMS.js",
"OpenLayers/Layer/WMS/Untiled.js",
"OpenLayers/Layer/WMS/Post.js",
"OpenLayers/Layer/WMTS.js",
"OpenLayers/Layer/ArcIMS.js",
"OpenLayers/Layer/GeoRSS.js",
"OpenLayers/Layer/Boxes.js",
@@ -289,6 +290,8 @@
"OpenLayers/Format/SOSGetFeatureOfInterest.js",
"OpenLayers/Format/OWSContext.js",
"OpenLayers/Format/OWSContext/v0_3_1.js",
"OpenLayers/Format/WMTSCapabilities.js",
"OpenLayers/Format/WMTSCapabilities/v1_0_0.js",
"OpenLayers/Layer/WFS.js",
"OpenLayers/Control/GetFeature.js",
"OpenLayers/Control/MouseToolbar.js",

View File

@@ -48,6 +48,9 @@ OpenLayers.Format.OWSCommon.v1_1_0 = OpenLayers.Class(OpenLayers.Format.OWSCommo
},
"MaximumValue": function(node, range) {
range.maxValue = this.getChildValue(node);
},
"Identifier": function(node, obj) {
obj.identifier = this.getChildValue(node);
}
}, OpenLayers.Format.OWSCommon.v1.prototype.readers["ows"])
},

View File

@@ -0,0 +1,80 @@
/* Copyright (c) 2006-2009 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/XML.js
*/
/**
* Class: OpenLayers.Format.WMTSCapabilities
* Read WMTS Capabilities.
*
* Inherits from:
* - <OpenLayers.Format.XML>
*/
OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML, {
/**
* APIProperty: defaultVersion
* {String} Version number to assume if none found. Default is "1.0.0".
*/
defaultVersion: "1.0.0",
/**
* APIProperty: version
* {String} Specify a version string if one is known.
*/
version: null,
/**
* Property: parser
* {<OpenLayers.Format>} A cached versioned format used for reading.
*/
parser: null,
/**
* Constructor: OpenLayers.Format.WMTSCapabilities
* Create a new parser for WMTS capabilities.
*
* Parameters:
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
initialize: function(options) {
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
this.options = options;
},
/**
* APIMethod: read
* Read capabilities data from a string, and return information about
* the service (offering and observedProperty mostly).
*
* Parameters:
* data - {String} or {DOMElement} data to read/parse.
*
* Returns:
* {Object} Info about the WMTS Capabilities
*/
read: function(data) {
if (typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
var root = data.documentElement;
var version = this.version || root.getAttribute("version") || this.defaultVersion;
if (!this.parser || this.parser.version !== version) {
var constr = OpenLayers.Format.WMTSCapabilities[
"v" + version.replace(/\./g, "_")
];
if (!constr) {
throw new Error("Can't find a WMTS capabilities parser for version " + version);
}
var parser = new constr(this.options);
}
return parser.read(data);
},
CLASS_NAME: "OpenLayers.Format.WMTSCapabilities"
});

View File

@@ -0,0 +1,186 @@
/* Copyright (c) 2006-2009 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Format/WMTSCapabilities.js
* @requires OpenLayers/Format/OWSCommon/v1_1_0.js
*/
/**
* Class: OpenLayers.Format.WMTSCapabilities.v1_0_0
* Read WMTS Capabilities version 1.0.0.
*
* Inherits from:
* - <OpenLayers.Format.WMTSCapabilities>
*/
OpenLayers.Format.WMTSCapabilities.v1_0_0 = OpenLayers.Class(
OpenLayers.Format.OWSCommon.v1_1_0, {
/**
* Property: version
* {String} The parser version ("1.0.0").
*/
version: "1.0.0",
/**
* Property: namespaces
* {Object} Mapping of namespace aliases to namespace URIs.
*/
namespaces: {
ows: "http://www.opengis.net/ows/1.1",
wmts: "http://www.opengis.net/wmts/1.0",
xlink: "http://www.w3.org/1999/xlink"
},
/**
* Property: defaultPrefix
* {String} The default namespace alias for creating element nodes.
*/
defaultPrefix: "wmts",
/**
* Constructor: OpenLayers.Format.WMTSCapabilities.v1_0_0
* Create a new parser for WMTS capabilities version 1.0.0.
*
* Parameters:
* options - {Object} An optional object whose properties will be set on
* this instance.
*/
initialize: function(options) {
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
this.options = options;
},
/**
* APIMethod: read
* Read capabilities data from a string, and return info about the WMTS.
*
* Parameters:
* data - {String} or {DOMElement} data to read/parse.
*
* Returns:
* {Object} Information about the SOS service.
*/
read: function(data) {
if(typeof data == "string") {
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
}
if(data && data.nodeType == 9) {
data = data.documentElement;
}
var capabilities = {};
this.readNode(data, capabilities);
capabilities.version = this.version;
return capabilities;
},
/**
* Property: readers
* Contains public functions, grouped by namespace prefix, that will
* be applied when a namespaced node is found matching the function
* name. The function will be applied in the scope of this parser
* with two arguments: the node being read and a context object passed
* from the parent.
*/
readers: {
"wmts": {
"Capabilities": function(node, obj) {
this.readChildNodes(node, obj);
},
"Contents": function(node, obj) {
obj.contents = {};
obj.contents.layers = [];
obj.contents.tileMatrixSets = {};
this.readChildNodes(node, obj.contents);
},
"Layer": function(node, obj) {
var layer = {
styles: [],
formats: [],
tileMatrixSetLinks: []
};
layer.layers = [];
this.readChildNodes(node, layer);
obj.layers.push(layer);
},
"Style": function(node, obj) {
var style = {};
style.isDefault = node.getAttribute("isDefault");
this.readChildNodes(node, style);
obj.styles.push(style);
},
"Format": function(node, obj) {
obj.formats.push(this.getChildValue(node));
},
"TileMatrixSetLink": function(node, obj) {
var tileMatrixSetLink = {};
this.readChildNodes(node, tileMatrixSetLink);
obj.tileMatrixSetLinks.push(tileMatrixSetLink);
},
"TileMatrixSet": function(node, obj) {
// node could be child of wmts:Contents or wmts:TileMatrixSetLink
// duck type wmts:Contents by looking for layers
if (obj.layers) {
// TileMatrixSet as object type in schema
var tileMatrixSet = {};
tileMatrixSet.matrixIds = [];
this.readChildNodes(node, tileMatrixSet);
obj.tileMatrixSets[tileMatrixSet.identifier] = tileMatrixSet;
} else {
// TileMatrixSet as string type in schema
obj.tileMatrixSet = this.getChildValue(node);
}
},
"TileMatrix": function(node, obj) {
var tileMatrix = {};
this.readChildNodes(node, tileMatrix);
obj.matrixIds.push(tileMatrix);
},
"ScaleDenominator": function(node, obj) {
obj.scaleDenominator = parseFloat(this.getChildValue(node));
},
"TopLeftCorner": function(node, obj) {
var topLeftCorner = this.getChildValue(node);
var coords = topLeftCorner.split(" ");
obj.topLeftCorner = new OpenLayers.LonLat(parseFloat(coords[1]), parseFloat(coords[0]));
},
"TileWidth": function(node, obj) {
obj.tileWidth = parseInt(this.getChildValue(node));
},
"TileHeight": function(node, obj) {
obj.tileHeight = parseInt(this.getChildValue(node));
},
"MatrixWidth": function(node, obj) {
obj.matrixWidth = parseInt(this.getChildValue(node));
},
"MatrixHeight": function(node, obj) {
obj.matrixHeight = parseInt(this.getChildValue(node));
},
// not used for now, can be added in the future though
/*"Themes": function(node, obj) {
obj.themes = [];
this.readChildNodes(node, obj.themes);
},
"Theme": function(node, obj) {
var theme = {};
this.readChildNodes(node, theme);
obj.push(theme);
},*/
"WSDL": function(node, obj) {
obj.wsdl = {};
obj.wsdl.href = node.getAttribute("xlink:href");
// TODO: other attributes of <WSDL> element
},
"ServiceMetadataURL": function(node, obj) {
obj.serviceMetadataUrl = {};
obj.serviceMetadataUrl.href = node.getAttribute("xlink:href");
// TODO: other attributes of <ServiceMetadataURL> element
}
},
"ows": OpenLayers.Format.OWSCommon.v1_1_0.prototype.readers["ows"]
},
CLASS_NAME: "OpenLayers.Format.WMTSCapabilities.v1_0_0"
});

View File

@@ -0,0 +1,394 @@
/* Copyright (c) 2006-2009 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Layer/Grid.js
* @requires OpenLayers/Tile/Image.js
*/
/**
* Class: OpenLayers.Layer.WMTS
* Instances of the WMTS class allow viewing of tiles from a service that
* implements the OGC WMTS specification version 1.0.0.
*
* Inherits from:
* - <OpenLayers.Layer.Grid>
*/
OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, {
/**
* APIProperty: isBaseLayer
* {Boolean}
*/
isBaseLayer: true,
/**
* Property: version
* {String} WMTS version. Default is "1.0.0".
*/
version: "1.0.0",
/**
* APIProperty: requestEncoding
* {String} Request encoding. Can be "REST" or "KVP". Default is "KVP".
*/
requestEncoding: "KVP",
/**
* APIProperty: url
* {String} The base URL for the WMTS service.
*/
url: null,
/**
* APIProperty: layer
* {String} The layer identifier advertised by the WMTS service.
*/
layer: null,
/**
* APIProperty: matrixSet
* {String} One of the advertised matrix set identifiers. Must be provided.
*/
matrixSet: null,
/**
* APIProperty: style
* {String} One of the advertised layer styles. Must be provided.
*/
style: null,
/**
* APIProperty: format
* {String} The image MIME type. Default is "image/jpeg".
*/
format: "image/jpeg",
/**
* APIProperty: tileOrigin
* {<OpenLayers.LonLat>} The top-left corner of the tile matrix in map
* units.
*/
tileOrigin: null,
/**
* APIProperty: tileFullExtent
* {<OpenLayers.Bounds>} The full extent of the tile set. If not supplied,
* the layer's <maxExtent> property will be used.
*/
tileFullExtent: null,
/**
* APIProperty: formatSuffix
* {String} For REST request encoding, an image format suffix must be
* included in the request. If not provided, the suffix will be derived
* from the <format> property.
*/
formatSuffix: null,
/**
* APIProperty: matrixIds
* {Array} A list of tile matrix identifiers. If not provided, the matrix
* identifiers will be assumed to be integers corresponding to the
* map zoom level. If a list of strings is provided, each item should
* be the matrix identifier that corresponds to the map zoom level.
* Additionally, a list of objects can be provided. Each object should
* describe the matrix as presented in the WMTS capabilities. These
* objects should have the propertes shown below.
*
* Matrix properties:
* identifier - {String} The matrix identifier (required).
* topLeftCorner - {<OpenLayers.LonLat>} The top left corner of the
* matrix. Must be provided if different than the layer <tileOrigin>.
* tileWidth - {Number} The tile width for the matrix. Must be provided
* if different than the width given in the layer <tileSize>.
* tileHeight - {Number} The tile height for the matrix. Must be provided
* if different than the height given in the layer <tileSize>.
*/
matrixIds: null,
/**
* APIProperty: dimensions
* {Array} For RESTful request encoding, extra dimensions may be specified.
* Items in this list should be property names in the <params> object.
* Values of extra dimensions will be determined from the corresponding
* values in the <params> object.
*/
dimensions: null,
/**
* APIProperty: params
* {Object} Extra parameters to include in tile requests. For KVP
* <requestEncoding>, these properties will be encoded in the request
* query string. For REST <requestEncoding>, these properties will
* become part of the request path, with order determined by the
* <dimensions> list.
*/
params: null,
/**
* Property: formatSuffixMap
* {Object} a map between WMTS 'format' request parameter and tile image file suffix
*/
formatSuffixMap: {
"image/png": "png",
"image/png8": "png",
"image/png24": "png",
"image/png32": "png",
"png": "png",
"image/jpeg": "jpg",
"image/jpg": "jpg",
"jpeg": "jpg",
"jpg": "jpg"
},
/**
* Constructor: OpenLayers.Layer.WMTS
* Create a new WMTS layer.
*
* Parameters:
* config - {Object} Configuration properties for the layer.
*
* Required configuration properties:
* url - {String} The base url for the service. See the <url> property.
* layer - {String} The layer identifier. See the <layer> property.
* matrixSet - {String} The tile matrix set identifier. See the <matrixSet>
* property.
*
* Any other documented layer properties can be provided in the config object.
*/
initialize: function(config) {
config.params = OpenLayers.Util.upperCaseObject(config.params);
var args = [config.name, config.url, config.params, config];
OpenLayers.Layer.Grid.prototype.initialize.apply(this, args);
// confirm required properties are supplied
var required = {
url: true,
layer: true,
style: true,
matrixSet: true
};
for (var prop in required) {
if (!(prop in this)) {
throw new Error("Missing property '" + prop + "' in layer configuration.");
}
}
// determine format suffix (for REST)
if (!this.formatSuffix) {
this.formatSuffix = this.formatSuffixMap[this.format] || this.format.split("/").pop();
}
// expand matrixIds (may be array of string or array of object)
if (this.matrixIds) {
var len = this.matrixIds.length;
if (len && typeof this.matrixIds[0] === "string") {
var ids = this.matrixIds;
this.matrixIds = new Array(len)
for (var i=0; i<len; ++i) {
this.matrixIds[i] = {identifier: ids[i]};
}
}
}
},
/**
* Method: updateMatrixProperties
* Set as a listener for zoom end to update tile matrix related properties.
*/
updateMatrixProperties: function() {
if (this.matrixIds && this.matrixIds.length) {
var zoom = this.map.getZoom();
var matrix = this.matrixIds[zoom];
if (matrix) {
if (matrix.topLeftCorner) {
this.tileOrigin = matrix.topLeftCorner;
}
if (matrix.tileWidth && matrix.tileHeight) {
this.tileSize = new OpenLayers.Size(
matrix.tileWidth, matrix.tileHeight
);
}
}
}
},
/**
* Method: setMap
* Overwrite default <setMap> from Layer
*
* Parameters:
* map - {<OpenLayers.Map>}
*/
setMap: function(map) {
OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments);
this.map.events.on({
zoomend: this.updateMatrixProperties,
scope: this
});
this.updateMatrixProperties();
if (!this.tileOrigin) {
this.tileOrigin = new OpenLayers.LonLat(this.maxExtent.left, this.maxExtent.top);
}
if (!this.tileFullExtent) {
this.tileFullExtent = this.maxExtent;
}
},
/**
* Method: removeMap
*/
removeMap: function() {
if (this.map) {
this.map.events.un({
zoomend: this.updateMatrixProperties,
scope: this
});
}
OpenLayers.Layer.Grid.prototype.removeMap.apply(this, arguments);
},
/**
* APIMethod: clone
*
* Parameters:
* obj - {Object}
*
* Returns:
* {<OpenLayers.Layer.WMTS>} An exact clone of this <OpenLayers.Layer.WMTS>
*/
clone: function(obj) {
if (obj == null) {
obj = new OpenLayers.Layer.WMTS(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: getMatrixId
* Determine the appropriate matrix id for the given map resolution.
*/
getMatrixId: function() {
var id;
var zoom = this.map.getZoom();
if (!this.matrixIds || this.matrixIds.length === 0) {
id = zoom;
} else {
// TODO: get appropriate matrix id given the map resolution
id = this.matrixIds[zoom].identifier;
}
return id;
},
/**
* Method: getURL
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
*
* Returns:
* {String} A URL for the tile corresponding to the given bounds.
*/
getURL: function(bounds) {
bounds = this.adjustBounds(bounds);
var url = "";
if (!this.tileFullExtent || this.tileFullExtent.intersectsBounds(bounds)) {
var res = this.map.getResolution();
var zoom = this.map.getZoom();
var center = bounds.getCenterLonLat();
var col = Math.floor((center.lon - this.tileOrigin.lon) / (res * this.tileSize.w));
var row = Math.floor((this.tileOrigin.lat - center.lat) / (res * this.tileSize.h));
var matrixId = this.getMatrixId();
if (this.requestEncoding.toUpperCase() === "REST") {
// include 'version', 'layer' and 'style' in tile resource url
var path = this.version + "/" + this.layer + "/" + this.style + "/";
// append optional dimension path elements
if (this.dimensions) {
for (var i=0; i<this.dimensions.length; i++) {
if (this.params[this.dimensions[i]]) {
path = path + this.params[this.dimensions[i]] + "/";
}
}
}
// append other required path elements
path = path + this.matrixSet + "/" + matrixId + "/" + row + "/" + col + "." + this.formatSuffix;
if (this.url instanceof Array) {
url = this.selectUrl(path, url)
} else {
url = this.url;
}
if (!url.match(/\/$/)) {
url = url + "/";
}
url = url + path;
} else if (this.requestEncoding.toUpperCase() === "KVP") {
// assemble all required parameters
var params = {
SERVICE: "WMTS",
REQUEST: "GetTile",
VERSION: this.version,
LAYER: this.layer,
STYLE: this.style,
TILEMATRIXSET: this.matrixSet,
TILEMATRIX: matrixId,
TILEROW: row,
TILECOL: col,
FORMAT: this.format
};
url = OpenLayers.Layer.Grid.prototype.getFullRequestString.apply(this, [params]);
}
}
return url;
},
/**
* APIMethod: mergeNewParams
* Extend the existing layer <params> with new properties. Tiles will be
* reloaded with updated params in the request.
*
* Parameters:
* newParams - {Object} Properties to extend to existing <params>.
*/
mergeNewParams: function(newParams) {
if (this.requestEncoding.toUpperCase() === "KVP") {
return OpenLayers.Layer.Grid.prototype.mergeNewParams.apply(
this, [OpenLayers.Util.upperCaseObject(newParams)]
);
}
},
/**
* Method: addTile
* Create a tile, initialize it, and add it to the layer div.
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
* position - {<OpenLayers.Pixel>}
*
* Returns:
* {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image
*/
addTile: function(bounds,position) {
return new OpenLayers.Tile.Image(this, position, bounds,
null, this.tileSize);
},
CLASS_NAME: "OpenLayers.Layer.WMTS"
});

View File

@@ -0,0 +1,20 @@
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_initialize(t) {
t.plan(1);
var format = new OpenLayers.Format.WMTSCapabilities({
version: "foo"
});
t.eq(format.version, "foo", "version set on format");
}
</script>
</head>
<body>
</body>
</html>

View File

@@ -0,0 +1,275 @@
<html>
<head>
<script src="../../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_ows(t) {
t.plan(17);
var xml = document.getElementById("ogcsample").firstChild.nodeValue;
var doc = new OpenLayers.Format.XML().read(xml);
var obj = new OpenLayers.Format.WMTSCapabilities().read(doc);
// ows:ServiceIdentification
var serviceIdentification = obj.serviceIdentification;
t.eq(serviceIdentification.title, "Web Map Tile Service", "ows:ServiceIdentification title is correct");
t.eq(serviceIdentification.serviceTypeVersion, "1.0.0", "ows:ServiceIdentification serviceTypeVersion is correct");
t.eq(serviceIdentification.serviceType.value, "OGC WMTS", "ows:ServiceIdentification serviceType is correct");
// ows:ServiceProvider
var serviceProvider = obj.serviceProvider;
t.eq(serviceProvider.providerName, "MiraMon", "ows:ServiceProvider providerName is correct");
t.eq(serviceProvider.providerSite, "http://www.creaf.uab.es/miramon", "ows:ServiceProvider providerSite is correct");
t.eq(serviceProvider.serviceContact.individualName, "Joan Maso Pau", "ows:ServiceProvider individualName is correct");
t.eq(serviceProvider.serviceContact.positionName, "Senior Software Engineer", "ows:ServiceProvider positionName is correct");
t.eq(serviceProvider.serviceContact.contactInfo.address.administrativeArea, "Barcelona", "ows:ServiceProvider address administrativeArea is correct");
t.eq(serviceProvider.serviceContact.contactInfo.address.city, "Bellaterra", "ows:ServiceProvider address city is correct");
t.eq(serviceProvider.serviceContact.contactInfo.address.country, "Spain", "ows:ServiceProvider address country is correct");
t.eq(serviceProvider.serviceContact.contactInfo.address.deliveryPoint, "Fac Ciencies UAB", "ows:ServiceProvider address deliveryPoint is correct");
t.eq(serviceProvider.serviceContact.contactInfo.address.electronicMailAddress, "joan.maso@uab.es", "ows:ServiceProvider address electronicMailAddress is correct");
t.eq(serviceProvider.serviceContact.contactInfo.address.postalCode, "08193", "ows:ServiceProvider address postalCode is correct");
t.eq(serviceProvider.serviceContact.contactInfo.phone.voice, "+34 93 581 1312", "ows:ServiceProvider phone voice is correct");
// ows:OperationsMetadata
var operationsMetadata = obj.operationsMetadata;
t.eq(operationsMetadata.GetCapabilities.dcp.http.get, "http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?", "ows:OperationsMetadata GetCapabilities url is correct");
t.eq(operationsMetadata.GetFeatureInfo.dcp.http.get, "http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?", "ows:OperationsMetadata GetFeatureInfo url is correct");
t.eq(operationsMetadata.GetTile.dcp.http.get, "http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?", "ows:OperationsMetadata GetTile url is correct");
}
function test_layers(t) {
t.plan(21);
var xml = document.getElementById("ogcsample").firstChild.nodeValue;
var doc = new OpenLayers.Format.XML().read(xml);
var obj = new OpenLayers.Format.WMTSCapabilities().read(doc);
var contents = obj.contents;
var numOfLayers = contents.layers.length;
t.eq(numOfLayers, 1, "correct count of layers");
var layer = contents.layers[0];
t.eq(layer.abstract, "Coastline/shorelines (BA010)", "layer abstract is correct");
t.eq(layer.identifier, "coastlines", "layer identifier is correct");
t.eq(layer.title, "Coastlines", "layer title is correct");
var numOfFormats = layer.formats.length;
t.eq(numOfFormats, 2, "correct count of formats");
t.eq(layer.formats[0], "image/png", "format image/png is correct");
t.eq(layer.formats[1], "image/gif", "format image/gif is correct");
var numOfStyles = layer.styles.length;
t.eq(numOfStyles, 2, "correct count of styles");
t.eq(layer.styles[0].identifier, "DarkBlue", "style 0 identifier is correct");
t.eq(layer.styles[0].isDefault, "true", "style 0 isDefault is correct");
t.eq(layer.styles[0].title, "Dark Blue", "style 0 title is correct");
t.eq(layer.styles[1].identifier, "thickAndRed", "style 1 identifier is correct");
t.ok(!layer.styles[1].isDefault, "style 1 isDefault is correct");
t.eq(layer.styles[1].title, "Thick And Red", "style 1 title is correct");
//t.eq(layer.styles[1].abstract, "Specify this style if you want your maps to have thick red coastlines. ", "style 1 abstract is correct");
t.eq(layer.tileMatrixSetLinks.length, 1, "correct count of tileMatrixSetLinks");
t.eq(layer.tileMatrixSetLinks[0].tileMatrixSet, "BigWorld", "tileMatrixSet is correct");
var wgs84Bbox = layer.bounds;
t.ok(wgs84Bbox instanceof OpenLayers.Bounds, "wgs84BoudingBox instance of OpenLayers.Bounds");
t.eq(wgs84Bbox.left, -180.0, "wgs84BoudingBox left is correct");
t.eq(wgs84Bbox.right, 180.0, "wgs84BoudingBox right is correct");
t.eq(wgs84Bbox.bottom, -90.0, "wgs84BoudingBox bottom is correct");
t.eq(wgs84Bbox.top, 90.0, "wgs84BoudingBox top is correct");
}
function test_tileMatrixSets(t) {
t.plan(19);
var xml = document.getElementById("ogcsample").firstChild.nodeValue;
var doc = new OpenLayers.Format.XML().read(xml);
var obj = new OpenLayers.Format.WMTSCapabilities().read(doc);
var tileMatrixSets = obj.contents.tileMatrixSets;
t.ok(tileMatrixSets['BigWorld'], "tileMatrixSets 'BigWorld' found");
var bigWorld = tileMatrixSets['BigWorld'];
t.eq(bigWorld.identifier, "BigWorld", "tileMatrixSets identifier is correct");
t.eq(bigWorld.matrixIds.length, 2, "tileMatrix count is correct");
t.eq(bigWorld.matrixIds[0].identifier, "1e6", "tileMatrix 0 identifier is correct");
t.eq(bigWorld.matrixIds[0].matrixHeight, 50000, "tileMatrix 0 matrixHeight is correct");
t.eq(bigWorld.matrixIds[0].matrixWidth, 60000, "tileMatrix 0 matrixWidth is correct");
t.eq(bigWorld.matrixIds[0].scaleDenominator, 1000000, "tileMatrix 0 scaleDenominator is correct");
t.eq(bigWorld.matrixIds[0].tileWidth, 256, "tileMatrix 0 tileWidth is correct");
t.eq(bigWorld.matrixIds[0].tileHeight, 256, "tileMatrix 0 tileHeight is correct");
t.eq(bigWorld.matrixIds[0].topLeftCorner.lon, -180, "tileMatrix 0 topLeftCorner.lon is correct");
t.eq(bigWorld.matrixIds[0].topLeftCorner.lat, 84, "tileMatrix 0 topLeftCorner.lat is correct");
t.eq(bigWorld.matrixIds[1].identifier, "2.5e6", "tileMatrix 1 identifier is correct");
t.eq(bigWorld.matrixIds[1].matrixHeight, 7000, "tileMatrix 1 matrixHeight is correct");
t.eq(bigWorld.matrixIds[1].matrixWidth, 9000, "tileMatrix 1 matrixWidth is correct");
t.eq(bigWorld.matrixIds[1].scaleDenominator, 2500000, "tileMatrix 1 scaleDenominator is correct");
t.eq(bigWorld.matrixIds[1].tileWidth, 256, "tileMatrix 1 tileWidth is correct");
t.eq(bigWorld.matrixIds[1].tileHeight, 256, "tileMatrix 1 tileHeight is correct");
t.eq(bigWorld.matrixIds[1].topLeftCorner.lon, -180, "tileMatrix 1 topLeftCorner.lon is correct");
t.eq(bigWorld.matrixIds[1].topLeftCorner.lat, 84, "tileMatrix 1 topLeftCorner.lat is correct");
}
</script>
</head>
<body>
<!--
OGC example below taken from
http://schemas.opengis.net/wmts/1.0/examples/wmtsGetCapabilities_response.xml
-->
<div id="ogcsample"><!--
<?xml version="1.0" encoding="UTF-8"?>
<Capabilities xmlns="http://www.opengis.net/wmts/1.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xsi:schemaLocation="http://www.opengis.net/wmts/1.0 http://schemas.opengis.net/wmts/1.0/wmtsGetCapabilities_response.xsd" version="1.0.0">
<ows:ServiceIdentification>
<ows:Title>Web Map Tile Service</ows:Title>
<ows:Abstract>Service that contrains the map access interface to some TileMatrixSets</ows:Abstract>
<ows:Keywords>
<ows:Keyword>tile</ows:Keyword>
<ows:Keyword>tile matrix set</ows:Keyword>
<ows:Keyword>map</ows:Keyword>
</ows:Keywords>
<ows:ServiceType>OGC WMTS</ows:ServiceType>
<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
<ows:Fees>none</ows:Fees>
<ows:AccessConstraints>none</ows:AccessConstraints>
</ows:ServiceIdentification>
<ows:ServiceProvider>
<ows:ProviderName>MiraMon</ows:ProviderName>
<ows:ProviderSite xlink:href="http://www.creaf.uab.es/miramon"/>
<ows:ServiceContact>
<ows:IndividualName>Joan Maso Pau</ows:IndividualName>
<ows:PositionName>Senior Software Engineer</ows:PositionName>
<ows:ContactInfo>
<ows:Phone>
<ows:Voice>+34 93 581 1312</ows:Voice>
<ows:Facsimile>+34 93 581 4151</ows:Facsimile>
</ows:Phone>
<ows:Address>
<ows:DeliveryPoint>Fac Ciencies UAB</ows:DeliveryPoint>
<ows:City>Bellaterra</ows:City>
<ows:AdministrativeArea>Barcelona</ows:AdministrativeArea>
<ows:PostalCode>08193</ows:PostalCode>
<ows:Country>Spain</ows:Country>
<ows:ElectronicMailAddress>joan.maso@uab.es</ows:ElectronicMailAddress>
</ows:Address>
</ows:ContactInfo>
</ows:ServiceContact>
</ows:ServiceProvider>
<ows:OperationsMetadata>
<ows:Operation name="GetCapabilities">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?">
<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>KVP</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Get>
</ows:HTTP>
</ows:DCP>
</ows:Operation>
<ows:Operation name="GetTile">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?"/>
</ows:HTTP>
</ows:DCP>
</ows:Operation>
<ows:Operation name="GetFeatureInfo">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="http://www.miramon.uab.es/cgi-bin/MiraMon5_0.cgi?"/>
</ows:HTTP>
</ows:DCP>
</ows:Operation>
</ows:OperationsMetadata>
<Contents>
<Layer>
<ows:Title>Coastlines</ows:Title>
<ows:Abstract>Coastline/shorelines (BA010)</ows:Abstract>
<ows:WGS84BoundingBox>
<ows:LowerCorner>-180 -90</ows:LowerCorner>
<ows:UpperCorner>180 90</ows:UpperCorner>
</ows:WGS84BoundingBox>
<ows:Identifier>coastlines</ows:Identifier>
<Style isDefault="true">
<ows:Title>Dark Blue</ows:Title>
<ows:Identifier>DarkBlue</ows:Identifier>
<LegendURL format="image/png" xlink:href="http://www.miramon.uab.es/wmts/Coastlines/coastlines_darkBlue.png"/>
</Style>
<Style>
<ows:Title>Thick And Red</ows:Title>
<ows:Abstract>Specify this style if you want your maps to have thick red coastlines.
</ows:Abstract>
<ows:Identifier>thickAndRed</ows:Identifier>
</Style>
<Format>image/png</Format>
<Format>image/gif</Format>
<Dimension>
<ows:Title>Time</ows:Title>
<ows:Abstract>Monthly datasets</ows:Abstract>
<ows:Identifier>TIME</ows:Identifier>
<Value>2007-05</Value>
<Value>2007-06</Value>
<Value>2007-07</Value>
</Dimension>
<TileMatrixSetLink>
<TileMatrixSet>BigWorld</TileMatrixSet>
</TileMatrixSetLink>
</Layer>
<TileMatrixSet>
<ows:Identifier>BigWorld</ows:Identifier>
<ows:SupportedCRS>urn:ogc:def:crs:OGC:1.3:CRS84</ows:SupportedCRS>
<TileMatrix>
<ows:Identifier>1e6</ows:Identifier>
<ScaleDenominator>1e6</ScaleDenominator>
<TopLeftCorner>84 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>60000</MatrixWidth>
<MatrixHeight>50000</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>2.5e6</ows:Identifier>
<ScaleDenominator>2.5e6</ScaleDenominator>
<TopLeftCorner>84 -180</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>9000</MatrixWidth>
<MatrixHeight>7000</MatrixHeight>
</TileMatrix>
</TileMatrixSet>
</Contents>
<Themes>
<Theme>
<ows:Title>Foundation</ows:Title>
<ows:Abstract>"Digital Chart Of The World" data</ows:Abstract>
<ows:Identifier>Foundation</ows:Identifier>
<Theme>
<ows:Title>Boundaries</ows:Title>
<ows:Identifier>Boundaries</ows:Identifier>
<LayerRef>coastlines</LayerRef>
<LayerRef>politicalBoundaries</LayerRef>
<LayerRef>depthContours</LayerRef>
</Theme>
<Theme>
<ows:Title>Transportation</ows:Title>
<ows:Identifier>Transportation</ows:Identifier>
<LayerRef>roads</LayerRef>
<LayerRef>railroads</LayerRef>
<LayerRef>airports</LayerRef>
</Theme>
</Theme>
<Theme>
<ows:Title>World Geology</ows:Title>
<ows:Identifier>World Geology</ows:Identifier>
<LayerRef>worldAgeRockType</LayerRef>
<LayerRef>worldFaultLines</LayerRef>
<LayerRef>felsicMagmatic</LayerRef>
<LayerRef>maficMagmatic</LayerRef>
</Theme>
</Themes>
</Capabilities>
--></div>
</body>
</html>

1415
tests/Layer/WMTS.html Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -85,6 +85,8 @@
<li>Format/WMSCapabilities/v1_3_0.html</li>
<li>Format/WMSDescribeLayer.html</li>
<li>Format/WMSGetFeatureInfo.html</li>
<li>Format/WMTSCapabilities.html</li>
<li>Format/WMTSCapabilities/v1_0_0.html</li>
<li>Format/CSWGetDomain.html</li>
<li>Format/CSWGetDomain/v2_0_2.html</li>
<li>Format/CSWGetRecords.html</li>
@@ -144,6 +146,7 @@
<li>Layer/WFS.html</li>
<li>Layer/WMS.html</li>
<li>Layer/WMS/Post.html</li>
<li>Layer/WMTS.html</li>
<li>Layer/WrapDateLine.html</li>
<li>Layer/XYZ.html</li>
<li>Layer/Yahoo.html</li>