| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 3 |
<script src="../../lib/OpenLayers.js"></script> |
|---|
| 4 |
<script type="text/javascript"> |
|---|
| 5 |
|
|---|
| 6 |
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>'; |
|---|
| 7 |
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>'; |
|---|
| 8 |
|
|---|
| 9 |
function test_Format_WMC_read(t) { |
|---|
| 10 |
t.plan(33); |
|---|
| 11 |
|
|---|
| 12 |
var format = new OpenLayers.Format.WMC(); |
|---|
| 13 |
var map, layer; |
|---|
| 14 |
|
|---|
| 15 |
// test v1.0.0 |
|---|
| 16 |
map = format.read(v1_0_0, {map: "map"}); |
|---|
| 17 |
t.eq(map.center.lon.toPrecision(6), (-95).toPrecision(6), "(v1.0.0) map center correctly set"); |
|---|
| 18 |
t.eq(map.center.lat.toPrecision(6), (34.5).toPrecision(6), "(v1.0.0) map center correctly set"); |
|---|
| 19 |
t.eq(map.maxExtent.left.toPrecision(6), (-130).toPrecision(6), "(v1.0.0) map maxExtent correctly set"); |
|---|
| 20 |
t.eq(map.layers.length, 4, "(v1.0.0) correct number of layers"); |
|---|
| 21 |
t.eq(map.projection, "EPSG:4326", "(v1.0.0) map projection set correctly"); |
|---|
| 22 |
// check out first base layer |
|---|
| 23 |
layer = map.layers[0]; |
|---|
| 24 |
t.eq(layer.queryable, true, "(1.0.0) Layer is queryable"); |
|---|
| 25 |
t.ok(layer instanceof OpenLayers.Layer.WMS, |
|---|
| 26 |
"(v1.0.0) wms layer correctly instantiated"); |
|---|
| 27 |
t.eq(layer.url, "http://t1.hypercube.telascience.org/cgi-bin/landsat7", |
|---|
| 28 |
"(v1.0.0) layer url correctly set"); |
|---|
| 29 |
t.eq(layer.maxExtent.right.toPrecision(6), (-60).toPrecision(6), |
|---|
| 30 |
"(v1.0.0) layer maxExtent correctly set"); |
|---|
| 31 |
t.eq(layer.numZoomLevels, 4, |
|---|
| 32 |
"(v1.0.0) layer numZoomLevels correctly set"); |
|---|
| 33 |
t.eq(layer.isBaseLayer, true, |
|---|
| 34 |
"(v1.0.0) layer isBaseLayer correctly set for base layer"); |
|---|
| 35 |
// check out layer not in switcher |
|---|
| 36 |
layer = map.layers[2]; |
|---|
| 37 |
t.eq(layer.displayInLayerSwitcher, false, |
|---|
| 38 |
"(v1.0.0) layer displayInLayerSwitcher correctly set"); |
|---|
| 39 |
t.eq(layer.params["TRANSPARENT"], "TRUE", |
|---|
| 40 |
"(v1.0.0) layer param.transparent correctly set"); |
|---|
| 41 |
t.eq(layer.isBaseLayer, false, |
|---|
| 42 |
"(v1.0.0) layer isBaseLayer correctly set for overlay"); |
|---|
| 43 |
// check out single tile overlay |
|---|
| 44 |
layer = map.layers[3]; |
|---|
| 45 |
t.eq(layer.singleTile, true, |
|---|
| 46 |
"(v1.0.0) layer singleTile correctly set"); |
|---|
| 47 |
t.eq(layer.opacity, 0.8, |
|---|
| 48 |
"(v1.0.0) layer opacity correctly set"); |
|---|
| 49 |
map.destroy(); |
|---|
| 50 |
|
|---|
| 51 |
// test v1.1.0 |
|---|
| 52 |
var map = format.read(v1_1_0, {map: "map"}); |
|---|
| 53 |
t.eq(map.center.lon.toPrecision(6), (-95).toPrecision(6), "(v1.1.0) map center correctly set"); |
|---|
| 54 |
t.eq(map.center.lat.toPrecision(6), (34.5).toPrecision(6), "(v1.1.0) map center correctly set"); |
|---|
| 55 |
t.eq(map.maxExtent.left.toPrecision(6), (-130).toPrecision(6), "(v1.1.0) map maxExtent correctly set"); |
|---|
| 56 |
t.eq(map.layers.length, 4, "(v1.1.0) correct number of layers"); |
|---|
| 57 |
t.eq(map.projection, "EPSG:4326", "(v1.1.0) map projection set correctly"); |
|---|
| 58 |
// check out first baseLayer |
|---|
| 59 |
layer = map.layers[0]; |
|---|
| 60 |
t.ok(layer instanceof OpenLayers.Layer.WMS, |
|---|
| 61 |
"(v1.1.0) wms layer correctly instantiated"); |
|---|
| 62 |
t.eq(layer.url, "http://t1.hypercube.telascience.org/cgi-bin/landsat7", |
|---|
| 63 |
"(v1.1.0) layer url correctly set"); |
|---|
| 64 |
t.eq(layer.maxExtent.right.toPrecision(6), (-60).toPrecision(6), |
|---|
| 65 |
"(v1.1.0) layer maxExtent correctly set"); |
|---|
| 66 |
t.eq(layer.numZoomLevels, 4, |
|---|
| 67 |
"(v1.1.0) layer numZoomLevels correctly set"); |
|---|
| 68 |
t.eq(layer.isBaseLayer, true, |
|---|
| 69 |
"(v1.1.0) layer isBaseLayer correctly set for overlay"); |
|---|
| 70 |
// check out layer not in switcher |
|---|
| 71 |
layer = map.layers[2]; |
|---|
| 72 |
t.eq(layer.displayInLayerSwitcher, false, |
|---|
| 73 |
"(v1.1.0) layer displayInLayerSwitcher correctly set"); |
|---|
| 74 |
t.eq(layer.params["TRANSPARENT"], "TRUE", |
|---|
| 75 |
"(v1.1.0) layer param.transparent correctly set"); |
|---|
| 76 |
t.eq(layer.isBaseLayer, false, |
|---|
| 77 |
"(v1.1.0) layer isBaseLayer correctly set for overlay"); |
|---|
| 78 |
t.eq(layer.minScale.toPrecision(6), (32000000).toPrecision(6), |
|---|
| 79 |
"(v1.1.0) layer minScale correctly set"); |
|---|
| 80 |
t.eq(layer.maxScale.toPrecision(6), (6200000).toPrecision(6), |
|---|
| 81 |
"(v1.1.0) layer maxScale correctly set"); |
|---|
| 82 |
// check out single tile overlay |
|---|
| 83 |
layer = map.layers[3]; |
|---|
| 84 |
t.eq(layer.singleTile, true, |
|---|
| 85 |
"(v1.1.0) layer singleTile correctly set"); |
|---|
| 86 |
t.eq(layer.opacity, 0.8, |
|---|
| 87 |
"(v1.1.0) layer opacity correctly set"); |
|---|
| 88 |
map.destroy(); |
|---|
| 89 |
|
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
function test_Format_WMC_write(t) { |
|---|
| 93 |
|
|---|
| 94 |
var format = new OpenLayers.Format.WMC(); |
|---|
| 95 |
var map = format.read(v1_1_0, {map: "map"}); |
|---|
| 96 |
var wmc; |
|---|
| 97 |
|
|---|
| 98 |
function sanitize(str) { |
|---|
| 99 |
// id is unique so we don't expect it to be the same |
|---|
| 100 |
str = str.replace(/OpenLayers_Context_\d+/, "foo"); |
|---|
| 101 |
// FF and IE differ on ordering of attribute nodes |
|---|
| 102 |
// a better way to compare xml would be nice |
|---|
| 103 |
str = str.replace(/\s*xsi:schemaLocation=".*?"/, ""); |
|---|
| 104 |
str = str.replace(/\s*xmlns:xlink=".*?"/g, ""); |
|---|
| 105 |
// and of course floating point precision is an issue |
|---|
| 106 |
str = str.replace(/(-?\d+\.\d+)/g, function(m) {return parseFloat(m).toPrecision(6)}); |
|---|
| 107 |
return str; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
/** |
|---|
| 111 |
* Version 1.0.0 doesn't make the round trip because min/max resolutions |
|---|
| 112 |
* are not stored. Version 1.1.0 introduced minScaleDenominator and |
|---|
| 113 |
* maxScaleDenominator. The parser still writes valid WMC v1.0.0, you |
|---|
| 114 |
* just need a validator to prove it. |
|---|
| 115 |
* |
|---|
| 116 |
* The wmc.html example can be used to produce WMC docs for validation. |
|---|
| 117 |
* Prior to validation, the Extension tags need to be removed unless someone |
|---|
| 118 |
* cares to write and maintain some XSD. Both version 1.0.0 and 1.1.0 |
|---|
| 119 |
* validate on http://www.validome.org/xml/. |
|---|
| 120 |
*/ |
|---|
| 121 |
|
|---|
| 122 |
// test v1.1.0 |
|---|
| 123 |
if(OpenLayers.Util.getBrowserName()== "opera") { |
|---|
| 124 |
t.plan(0); |
|---|
| 125 |
t.debug_print("WMC writing works but is not tested in Opera"); |
|---|
| 126 |
} else { |
|---|
| 127 |
t.plan(1); |
|---|
| 128 |
|
|---|
| 129 |
map = format.read(v1_1_0, {map: "map"}); |
|---|
| 130 |
wmc = format.write(map); |
|---|
| 131 |
t.eq(sanitize(wmc), sanitize(v1_1_0), |
|---|
| 132 |
"(v1.1.0) write gives what read got"); |
|---|
| 133 |
map.destroy(); |
|---|
| 134 |
|
|---|
| 135 |
} |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
</script> |
|---|
| 139 |
</head> |
|---|
| 140 |
<body> |
|---|
| 141 |
<div id="map" style="width: 512px; height: 256px;"></div> |
|---|
| 142 |
</body> |
|---|
| 143 |
</html> |
|---|