Bart, tests by me, r=me, (Closes #1447) git-svn-id: http://svn.openlayers.org/trunk/openlayers@7668 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
144 lines
17 KiB
HTML
144 lines
17 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript">
|
|
|
|
var v1_0_0 = '<ViewContext xmlns="http://www.opengis.net/context" version="1.0.0" id="OpenLayers_Context_233" xsi:schemaLocation="http://www.opengis.net/context http://schemas.opengis.net/context/1.0.0/context.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><General><Window width="512" height="256"/><BoundingBox minx="-109.9709708" miny="27.01451459" maxx="-80.02902918" maxy="41.98548541" SRS="EPSG:4326"/><Title/><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/></Extension></General><LayerList><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://t1.hypercube.telascience.org/cgi-bin/landsat7"/></Server><Name>landsat7</Name><Title>NASA Global Mosaic</Title><FormatList><Format current="1">image/jpeg</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">true</ol:isBaseLayer><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile></Extension></Layer><Layer queryable="1" hidden="1"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://labs.metacarta.com/wms/vmap0"/></Server><Name>basic</Name><Title>OpenLayers WMS</Title><FormatList><Format current="1">image/jpeg</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">true</ol:isBaseLayer><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile></Extension></Layer><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://lioapp.lrc.gov.on.ca/cubeserv/cubeserv.pl"/></Server><Name>na_road:CCRS</Name><Title>Transportation Network</Title><FormatList><Format current="1">image/png</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-166.5320000" miny="4.050460000" maxx="-0.2068180000" maxy="70.28700000"/><ol:transparent xmlns:ol="http://openlayers.org/context">TRUE</ol:transparent><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer><ol:opacity xmlns:ol="http://openlayers.org/context">0.6</ol:opacity><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">false</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile></Extension></Layer><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://columbo.nrlssc.navy.mil/ogcwms/servlet/WMSServlet/AccuWeather_Maps.wms"/></Server><Name>3:1</Name><Title>Radar 3:1</Title><FormatList><Format current="1">image/png</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-131.0294952" miny="14.56289673" maxx="-61.02950287" maxy="54.56289673"/><ol:transparent xmlns:ol="http://openlayers.org/context">TRUE</ol:transparent><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer><ol:opacity xmlns:ol="http://openlayers.org/context">0.8</ol:opacity><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">true</ol:singleTile></Extension></Layer></LayerList></ViewContext>';
|
|
var v1_1_0 = '<ViewContext xmlns="http://www.opengis.net/context" version="1.1.0" id="OpenLayers_Context_232" xsi:schemaLocation="http://www.opengis.net/context http://schemas.opengis.net/context/1.1.0/context.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><General><Window width="512" height="256"/><BoundingBox minx="-109.9709708" miny="27.01451459" maxx="-80.02902918" maxy="41.98548541" SRS="EPSG:4326"/><Title/><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/></Extension></General><LayerList><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://t1.hypercube.telascience.org/cgi-bin/landsat7"/></Server><Name>landsat7</Name><Title>NASA Global Mosaic</Title><sld:MinScaleDenominator xmlns:sld="http://www.opengis.net/sld">6299645.760</sld:MinScaleDenominator><sld:MaxScaleDenominator xmlns:sld="http://www.opengis.net/sld">31498228.80</sld:MaxScaleDenominator><FormatList><Format current="1">image/jpeg</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">true</ol:isBaseLayer><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile></Extension></Layer><Layer queryable="1" hidden="1"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://labs.metacarta.com/wms/vmap0"/></Server><Name>basic</Name><Title>OpenLayers WMS</Title><sld:MinScaleDenominator xmlns:sld="http://www.opengis.net/sld">6299645.760</sld:MinScaleDenominator><sld:MaxScaleDenominator xmlns:sld="http://www.opengis.net/sld">31498228.80</sld:MaxScaleDenominator><FormatList><Format current="1">image/jpeg</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-130.0000000" miny="14.00000000" maxx="-60.00000000" maxy="55.00000000"/><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">true</ol:isBaseLayer><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile></Extension></Layer><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://lioapp.lrc.gov.on.ca/cubeserv/cubeserv.pl"/></Server><Name>na_road:CCRS</Name><Title>Transportation Network</Title><sld:MinScaleDenominator xmlns:sld="http://www.opengis.net/sld">6200000.000</sld:MinScaleDenominator><sld:MaxScaleDenominator xmlns:sld="http://www.opengis.net/sld">32000000.00</sld:MaxScaleDenominator><FormatList><Format current="1">image/png</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-166.5320000" miny="4.050460000" maxx="-0.2068180000" maxy="70.28700000"/><ol:transparent xmlns:ol="http://openlayers.org/context">TRUE</ol:transparent><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer><ol:opacity xmlns:ol="http://openlayers.org/context">0.6</ol:opacity><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">false</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile></Extension></Layer><Layer queryable="1" hidden="0"><Server service="OGC:WMS" version="1.1.1"><OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://columbo.nrlssc.navy.mil/ogcwms/servlet/WMSServlet/AccuWeather_Maps.wms"/></Server><Name>3:1</Name><Title>Radar 3:1</Title><sld:MinScaleDenominator xmlns:sld="http://www.opengis.net/sld">6299645.760</sld:MinScaleDenominator><sld:MaxScaleDenominator xmlns:sld="http://www.opengis.net/sld">31498228.80</sld:MaxScaleDenominator><FormatList><Format current="1">image/png</Format></FormatList><StyleList><Style current="1"><Name/><Title>Default</Title></Style></StyleList><Extension><ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-131.0294952" miny="14.56289673" maxx="-61.02950287" maxy="54.56289673"/><ol:transparent xmlns:ol="http://openlayers.org/context">TRUE</ol:transparent><ol:numZoomLevels xmlns:ol="http://openlayers.org/context">4</ol:numZoomLevels><ol:units xmlns:ol="http://openlayers.org/context">degrees</ol:units><ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer><ol:opacity xmlns:ol="http://openlayers.org/context">0.8</ol:opacity><ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher><ol:singleTile xmlns:ol="http://openlayers.org/context">true</ol:singleTile></Extension></Layer></LayerList></ViewContext>';
|
|
|
|
function test_Format_WMC_read(t) {
|
|
t.plan(33);
|
|
|
|
var format = new OpenLayers.Format.WMC();
|
|
var map, layer;
|
|
|
|
// test v1.0.0
|
|
map = format.read(v1_0_0, {map: "map"});
|
|
t.eq(map.center.lon.toPrecision(6), (-95).toPrecision(6), "(v1.0.0) map center correctly set");
|
|
t.eq(map.center.lat.toPrecision(6), (34.5).toPrecision(6), "(v1.0.0) map center correctly set");
|
|
t.eq(map.maxExtent.left.toPrecision(6), (-130).toPrecision(6), "(v1.0.0) map maxExtent correctly set");
|
|
t.eq(map.layers.length, 4, "(v1.0.0) correct number of layers");
|
|
t.eq(map.projection, "EPSG:4326", "(v1.0.0) map projection set correctly");
|
|
// check out first base layer
|
|
layer = map.layers[0];
|
|
t.eq(layer.queryable, true, "(1.0.0) Layer is queryable");
|
|
t.ok(layer instanceof OpenLayers.Layer.WMS,
|
|
"(v1.0.0) wms layer correctly instantiated");
|
|
t.eq(layer.url, "http://t1.hypercube.telascience.org/cgi-bin/landsat7",
|
|
"(v1.0.0) layer url correctly set");
|
|
t.eq(layer.maxExtent.right.toPrecision(6), (-60).toPrecision(6),
|
|
"(v1.0.0) layer maxExtent correctly set");
|
|
t.eq(layer.numZoomLevels, 4,
|
|
"(v1.0.0) layer numZoomLevels correctly set");
|
|
t.eq(layer.isBaseLayer, true,
|
|
"(v1.0.0) layer isBaseLayer correctly set for base layer");
|
|
// check out layer not in switcher
|
|
layer = map.layers[2];
|
|
t.eq(layer.displayInLayerSwitcher, false,
|
|
"(v1.0.0) layer displayInLayerSwitcher correctly set");
|
|
t.eq(layer.params["TRANSPARENT"], "TRUE",
|
|
"(v1.0.0) layer param.transparent correctly set");
|
|
t.eq(layer.isBaseLayer, false,
|
|
"(v1.0.0) layer isBaseLayer correctly set for overlay");
|
|
// check out single tile overlay
|
|
layer = map.layers[3];
|
|
t.eq(layer.singleTile, true,
|
|
"(v1.0.0) layer singleTile correctly set");
|
|
t.eq(layer.opacity, 0.8,
|
|
"(v1.0.0) layer opacity correctly set");
|
|
map.destroy();
|
|
|
|
// test v1.1.0
|
|
var map = format.read(v1_1_0, {map: "map"});
|
|
t.eq(map.center.lon.toPrecision(6), (-95).toPrecision(6), "(v1.1.0) map center correctly set");
|
|
t.eq(map.center.lat.toPrecision(6), (34.5).toPrecision(6), "(v1.1.0) map center correctly set");
|
|
t.eq(map.maxExtent.left.toPrecision(6), (-130).toPrecision(6), "(v1.1.0) map maxExtent correctly set");
|
|
t.eq(map.layers.length, 4, "(v1.1.0) correct number of layers");
|
|
t.eq(map.projection, "EPSG:4326", "(v1.1.0) map projection set correctly");
|
|
// check out first baseLayer
|
|
layer = map.layers[0];
|
|
t.ok(layer instanceof OpenLayers.Layer.WMS,
|
|
"(v1.1.0) wms layer correctly instantiated");
|
|
t.eq(layer.url, "http://t1.hypercube.telascience.org/cgi-bin/landsat7",
|
|
"(v1.1.0) layer url correctly set");
|
|
t.eq(layer.maxExtent.right.toPrecision(6), (-60).toPrecision(6),
|
|
"(v1.1.0) layer maxExtent correctly set");
|
|
t.eq(layer.numZoomLevels, 4,
|
|
"(v1.1.0) layer numZoomLevels correctly set");
|
|
t.eq(layer.isBaseLayer, true,
|
|
"(v1.1.0) layer isBaseLayer correctly set for overlay");
|
|
// check out layer not in switcher
|
|
layer = map.layers[2];
|
|
t.eq(layer.displayInLayerSwitcher, false,
|
|
"(v1.1.0) layer displayInLayerSwitcher correctly set");
|
|
t.eq(layer.params["TRANSPARENT"], "TRUE",
|
|
"(v1.1.0) layer param.transparent correctly set");
|
|
t.eq(layer.isBaseLayer, false,
|
|
"(v1.1.0) layer isBaseLayer correctly set for overlay");
|
|
t.eq(layer.minScale.toPrecision(6), (32000000).toPrecision(6),
|
|
"(v1.1.0) layer minScale correctly set");
|
|
t.eq(layer.maxScale.toPrecision(6), (6200000).toPrecision(6),
|
|
"(v1.1.0) layer maxScale correctly set");
|
|
// check out single tile overlay
|
|
layer = map.layers[3];
|
|
t.eq(layer.singleTile, true,
|
|
"(v1.1.0) layer singleTile correctly set");
|
|
t.eq(layer.opacity, 0.8,
|
|
"(v1.1.0) layer opacity correctly set");
|
|
map.destroy();
|
|
|
|
}
|
|
|
|
function test_Format_WMC_write(t) {
|
|
|
|
var format = new OpenLayers.Format.WMC();
|
|
var map = format.read(v1_1_0, {map: "map"});
|
|
var wmc;
|
|
|
|
function sanitize(str) {
|
|
// id is unique so we don't expect it to be the same
|
|
str = str.replace(/OpenLayers_Context_\d+/, "foo");
|
|
// FF and IE differ on ordering of attribute nodes
|
|
// a better way to compare xml would be nice
|
|
str = str.replace(/\s*xsi:schemaLocation=".*?"/, "");
|
|
str = str.replace(/\s*xmlns:xlink=".*?"/g, "");
|
|
// and of course floating point precision is an issue
|
|
str = str.replace(/(-?\d+\.\d+)/g, function(m) {return parseFloat(m).toPrecision(6)});
|
|
return str;
|
|
}
|
|
|
|
/**
|
|
* Version 1.0.0 doesn't make the round trip because min/max resolutions
|
|
* are not stored. Version 1.1.0 introduced minScaleDenominator and
|
|
* maxScaleDenominator. The parser still writes valid WMC v1.0.0, you
|
|
* just need a validator to prove it.
|
|
*
|
|
* The wmc.html example can be used to produce WMC docs for validation.
|
|
* Prior to validation, the Extension tags need to be removed unless someone
|
|
* cares to write and maintain some XSD. Both version 1.0.0 and 1.1.0
|
|
* validate on http://www.validome.org/xml/.
|
|
*/
|
|
|
|
// test v1.1.0
|
|
if(OpenLayers.Util.getBrowserName()== "opera") {
|
|
t.plan(0);
|
|
t.debug_print("WMC writing works but is not tested in Opera");
|
|
} else {
|
|
t.plan(1);
|
|
|
|
map = format.read(v1_1_0, {map: "map"});
|
|
wmc = format.write(map);
|
|
t.eq(sanitize(wmc), sanitize(v1_1_0),
|
|
"(v1.1.0) write gives what read got");
|
|
map.destroy();
|
|
|
|
}
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width: 512px; height: 256px;"></div>
|
|
</body>
|
|
</html>
|