add tests to create a REST WMTS Layer

This commit is contained in:
Stéphane Brunner
2012-03-03 19:58:41 +01:00
committed by Stéphane Brunner
parent a662f82a1b
commit 8d1d08b0c2

View File

@@ -43,15 +43,15 @@
undefined,
"ows:OperationsMetadata GetTile Constraints Get is correct");
}
function test_layers(t) {
t.plan(37);
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");
@@ -89,11 +89,11 @@
t.eq(wgs84Bbox.top, 90.0, "wgs84BoudingBox top is correct");
t.eq(layer.resourceUrl.tile.format, "image/png", "resourceUrl.tile.format is correct");
t.eq(layer.resourceUrl.tile.template, "http://www.example.com/wmts/coastlines/{TileMatrix}/{TileRow}/{TileCol}.png",
t.eq(layer.resourceUrl.tile.template, "http://www.example.com/wmts/coastlines/{TileMatrix}/{TileRow}/{TileCol}.png",
"resourceUrl.tile.template is correct");
t.eq(layer.resourceUrl.FeatureInfo.format, "application/gml+xml; version=3.1", "resourceUrl.FeatureInfo.format is correct");
t.eq(layer.resourceUrl.FeatureInfo.template, "http://www.example.com/wmts/coastlines/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}/{J}/{I}.xml",
t.eq(layer.resourceUrl.FeatureInfo.template, "http://www.example.com/wmts/coastlines/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}/{J}/{I}.xml",
"resourceUrl.FeatureInfo.template is correct");
var dimensions = layer.dimensions;
@@ -112,7 +112,7 @@
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;
@@ -138,54 +138,100 @@
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");
}
function test_createLayer(t) {
t.plan(7);
t.plan(27);
var format = new OpenLayers.Format.WMTSCapabilities();
var xml = document.getElementById("ogcsample").firstChild.nodeValue;
var doc = new OpenLayers.Format.XML().read(xml);
var caps = format.read(doc);
var layer;
var success = true;
try {
// incomplete config (missing matrixSet)
// incomplete config (missing layer)
layer = format.createLayer(caps, {
layer: "coastlines"
});
} catch (err) {
success = false;
}
t.ok(!success, "createLayer throws error if provided incomplete layer config");
// bogus layer identifier
layer = format.createLayer(caps, {
layer: "foo",
matrixSet: "BigWorld"
});
t.eq(layer, undefined, "createLayer returns undefined given bad layer identifier");
try {
layer = format.createLayer(caps, {
layer: "foo",
matrixSet: "BigWorld"
});
} catch (err) {
success = false;
}
t.ok(!success, "createLayer returns undefined given bad layer identifier");
// bogus matrixSet identifier
layer = format.createLayer(caps, {
layer: "coastlines",
matrixSet: "TheWorld"
});
t.eq(layer, undefined, "createLayer returns undefined given bad matrixSet identifier");
try {
layer = format.createLayer(caps, {
layer: "coastlines",
matrixSet: "TheWorld"
});
} catch (err) {
success = false;
}
t.ok(!success, "createLayer returns undefined given bad matrixSet identifier");
layer = format.createLayer(caps, {
layer: "coastlines",
matrixSet: "BigWorld"
});
t.ok(layer instanceof OpenLayers.Layer.WMTS, "correct instance");
// autodetect matrixSet
layer = format.createLayer(caps, {
layer: "coastlines"
});
t.ok(layer instanceof OpenLayers.Layer.WMTS, "correct instance, with autodetected matrixSet");
t.eq(layer.matrixIds.length, 2, "correct matrixIds length");
t.eq(layer.name, "Coastlines", "correct layer title");
t.eq(layer.style, "DarkBlue", "correct style identifier");
t.eq(layer.requestEncoding, "KVP", "correct requestEncoding");
xml = document.getElementById("restsample").firstChild.nodeValue;
doc = new OpenLayers.Format.XML().read(xml);
caps = format.read(doc);
layer = format.createLayer(caps, {
layer: "ch.are.agglomerationen_isolierte_staedte-2000",
matrixSet: "21781"
});
t.ok(layer instanceof OpenLayers.Layer.WMTS, "correct instance");
t.eq(layer.url, "http://wmts.geo.admin.ch/1.0.0/ch.are.agglomerationen_isolierte_staedte-2000/default/{Time}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png", "correct url");
t.eq(layer.matrixIds.length, 3, "correct matrixIds length");
t.eq(layer.requestEncoding, "REST", "correct requestEncoding");
t.eq(layer.name, "Agglomérations et villes isolées", "correct layer title");
t.eq(layer.style, "ch.are.agglomerationen_isolierte_staedte-2000", "correct style identifier");
t.eq(layer.projection.getCode(), "EPSG:21781", "correct projection");
t.eq(layer.units, "m", "correct untis");
t.eq(layer.resolutions.length, 3, "correct resolutions length");
t.ok((layer.resolutions[0] - 4000) < 1, "correct first resolution");
t.eq(layer.dimensions.length, 1, "correct dimensions length");
t.eq(layer.dimensions[0], "Time", "correct dimensions");
t.eq(layer.params['TIME'], "20090101", "correct params");
layer = format.createLayer(caps, {
layer: "ch.are.agglomerationen_isolierte_staedte-2000",
style: "toto",
params: {"Time": "2012"}
});
t.eq(layer.matrixIds.length, 3, "correct matrixIds length");
t.eq(layer.style, "toto", "correct style identifier");
t.eq(layer.dimensions.length, 1, "correct dimensions length");
t.eq(layer.dimensions[0], "Time", "correct dimensions");
t.eq(layer.params['TIME'], "2012", "correct params");
}
</script>
</head>
<body>
@@ -300,15 +346,15 @@ http://schemas.opengis.net/wmts/1.0/examples/wmtsGetCapabilities_response.xml
<TileMatrixSet>BigWorld</TileMatrixSet>
</TileMatrixSetLink>
</Layer>
<TileMatrixSet>
<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>-180 84</TopLeftCorner>
<ScaleDenominator>1e6</ScaleDenominator>
<TopLeftCorner>-180 84</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<TileHeight>256</TileHeight>
<MatrixWidth>60000</MatrixWidth>
<MatrixHeight>50000</MatrixHeight>
</TileMatrix>
@@ -354,5 +400,133 @@ http://schemas.opengis.net/wmts/1.0/examples/wmtsGetCapabilities_response.xml
</Themes>
</Capabilities>
--></div>
<div id="restsample"><!--
<?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>Federal Geodata Infrastructure of Switzerland</ows:Title>
<ows:Abstract>Some Geodata are subject to license and fees</ows:Abstract>
<ows:Keywords>
<ows:Keyword>FGDI</ows:Keyword>
<ows:Keyword>Pixelkarte</ows:Keyword>
<ows:Keyword>Switzerland</ows:Keyword>
</ows:Keywords>
<ows:ServiceType>OGC WMTS</ows:ServiceType>
<ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
<ows:Fees>yes</ows:Fees>
<ows:AccessConstraints>license</ows:AccessConstraints>
</ows:ServiceIdentification>
<ows:ServiceProvider>
<ows:ProviderName>swisstopo</ows:ProviderName>
<ows:ProviderSite xlink:href="http://www.swisstopo.admin.ch"/>
<ows:ServiceContact>
<ows:IndividualName>David Oesch</ows:IndividualName>
<ows:PositionName></ows:PositionName>
<ows:ContactInfo>
<ows:Phone>
<ows:Voice>+41 (0)31 / 963 21 11</ows:Voice>
<ows:Facsimile>+41 (0)31 / 963 24 59</ows:Facsimile>
</ows:Phone>
<ows:Address>
<ows:DeliveryPoint>swisstopo</ows:DeliveryPoint>
<ows:City>Bern</ows:City>
<ows:AdministrativeArea>BE</ows:AdministrativeArea>
<ows:PostalCode>3084</ows:PostalCode>
<ows:Country>Switzerland</ows:Country>
<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://wmts.geo.admin.ch/1.0.0/WMTSCapabilities.xml">
<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>REST</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://wmts.geo.admin.ch/">
<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>REST</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Get>
</ows:HTTP>
</ows:DCP>
</ows:Operation>
</ows:OperationsMetadata>
<Contents>
<Layer>
<ows:Title>Agglomérations et villes isolées</ows:Title>
<ows:Abstract>Les agglomérations et villes isolées (communes non rattachées à une agglomération et comptant au moins 10`000 habitants) font partie des régions danalyse de la statistique suisse. Ce niveau géographique est défini depuis plus de 100 ans, afin de mesurer lurbanisation, phénomène fondamental structurant lorganisation du territoire. Sa fonction principale est de permettre une comparaison spatiale entre des espaces urbains inégalement délimités sur le plan institutionnel. Une version ancienne est appliquée pour la première fois en 1930, puis révisée en 1984 et 1990, toujours sur la base des recensements de la population. La version actuelle classe les 2896 communes de Suisse (état 2000) selon leur appartenance ou pas à une agglomération ou ville isolée en fonction de critères statistiques (Etat et évolution de la population, lien de continuité de la zone bâtie, rapport entre population active occupée et population résidante, structure économique et flux de pendulaires). Les agglomérations et les villes isolées forment l`espace urbain, les territoires restant l`espace rural. La définition des agglomérations de lOFS na pas valeur dobligation légale.</ows:Abstract>
<ows:WGS84BoundingBox>
<ows:LowerCorner>5.140242 45.398181</ows:LowerCorner>
<ows:UpperCorner>11.47757 48.230651</ows:UpperCorner>
</ows:WGS84BoundingBox>
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
<ows:Metadata xlink:href="http://www.swisstopo.admin.ch/SITiled/world/AdminBoundaries/metadata.htm"/>
<Style>
<ows:Title>Agglomérations et villes isolées</ows:Title>
<ows:Identifier>ch.are.agglomerationen_isolierte_staedte-2000</ows:Identifier>
<LegendURL format="image/png" xlink:href="http://api.geo.admin.ch/legend/ch.are.agglomerationen_isolierte_staedte-2000_fr.png" />
</Style>
<Format>image/png</Format>
<Dimension>
<ows:Identifier>Time</ows:Identifier>
<Default>20090101</Default>
<Value>20090101</Value>
</Dimension>
<TileMatrixSetLink>
<TileMatrixSet>21781</TileMatrixSet>
</TileMatrixSetLink>
<ResourceURL format="image/png" resourceType="tile" template="http://wmts.geo.admin.ch/1.0.0/ch.are.agglomerationen_isolierte_staedte-2000/default/{Time}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png"/>
</Layer>
<TileMatrixSet>
<ows:Identifier>21781</ows:Identifier>
<ows:SupportedCRS>urn:ogc:def:crs:EPSG:21781</ows:SupportedCRS>
<TileMatrix>
<ows:Identifier>0</ows:Identifier>
<ScaleDenominator>14285750.5715</ScaleDenominator>
<TopLeftCorner>420000.0 350000.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>1</MatrixWidth>
<MatrixHeight>1</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>8</ows:Identifier>
<ScaleDenominator>7142875.28575</ScaleDenominator>
<TopLeftCorner>420000.0 350000.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>1</MatrixWidth>
<MatrixHeight>1</MatrixHeight>
</TileMatrix>
<TileMatrix>
<ows:Identifier>12</ows:Identifier>
<ScaleDenominator>3571437.64288</ScaleDenominator>
<TopLeftCorner>420000.0 350000.0</TopLeftCorner>
<TileWidth>256</TileWidth>
<TileHeight>256</TileHeight>
<MatrixWidth>2</MatrixWidth>
<MatrixHeight>2</MatrixHeight>
</TileMatrix>
</TileMatrixSet>
</Contents>
<ServiceMetadataURL xlink:href="http://www.opengis.uab.es/SITiled/world/1.0.0/WMTSCapabilities.xml"/>
</Capabilities>
--></div>
</body>
</html>