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
+187 -13
View File
@@ -140,7 +140,7 @@
} }
function test_createLayer(t) { function test_createLayer(t) {
t.plan(7); t.plan(27);
var format = new OpenLayers.Format.WMTSCapabilities(); var format = new OpenLayers.Format.WMTSCapabilities();
@@ -152,9 +152,8 @@
var success = true; var success = true;
try { try {
// incomplete config (missing matrixSet) // incomplete config (missing layer)
layer = format.createLayer(caps, { layer = format.createLayer(caps, {
layer: "coastlines"
}); });
} catch (err) { } catch (err) {
success = false; success = false;
@@ -162,18 +161,26 @@
t.ok(!success, "createLayer throws error if provided incomplete layer config"); t.ok(!success, "createLayer throws error if provided incomplete layer config");
// bogus layer identifier // bogus layer identifier
layer = format.createLayer(caps, { try {
layer: "foo", layer = format.createLayer(caps, {
matrixSet: "BigWorld" layer: "foo",
}); matrixSet: "BigWorld"
t.eq(layer, undefined, "createLayer returns undefined given bad layer identifier"); });
} catch (err) {
success = false;
}
t.ok(!success, "createLayer returns undefined given bad layer identifier");
// bogus matrixSet identifier // bogus matrixSet identifier
layer = format.createLayer(caps, { try {
layer: "coastlines", layer = format.createLayer(caps, {
matrixSet: "TheWorld" layer: "coastlines",
}); matrixSet: "TheWorld"
t.eq(layer, undefined, "createLayer returns undefined given bad matrixSet identifier"); });
} catch (err) {
success = false;
}
t.ok(!success, "createLayer returns undefined given bad matrixSet identifier");
layer = format.createLayer(caps, { layer = format.createLayer(caps, {
layer: "coastlines", layer: "coastlines",
@@ -181,9 +188,48 @@
}); });
t.ok(layer instanceof OpenLayers.Layer.WMTS, "correct instance"); 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.matrixIds.length, 2, "correct matrixIds length");
t.eq(layer.name, "Coastlines", "correct layer title"); t.eq(layer.name, "Coastlines", "correct layer title");
t.eq(layer.style, "DarkBlue", "correct style identifier"); 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> </script>
@@ -354,5 +400,133 @@ http://schemas.opengis.net/wmts/1.0/examples/wmtsGetCapabilities_response.xml
</Themes> </Themes>
</Capabilities> </Capabilities>
--></div> --></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> </body>
</html> </html>