3 <script src="../../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 function test_write_wmc_Layer(t) {
7 if (OpenLayers.Util.getBrowserName() == "safari") {
9 t.debug_print("Safari has wierd behavior with getElementsByTagNameNS: the result is that we can't run these tests there. Patches welcome.");
14 // direct construction of a parser for a unit test
15 var wmc = new OpenLayers.Format.WMC.v1_1_0();
16 var sldNS = wmc.namespaces["sld"];
18 // test that Min/MaxScaleDenominator is not written out when no
19 // resolution related options are set
20 var layer = new OpenLayers.Layer.WMS(
21 "test", "http://foo", {},
22 {maxExtent: new OpenLayers.Bounds(1, 2, 3, 4)}
24 var node = wmc.write_wmc_Layer(layer);
25 var minList = wmc.getElementsByTagNameNS(node, sldNS, "MinScaleDenominator");
26 t.eq(minList.length, 0, "(none) node not written with MinScaleDenominator");
27 var maxList = wmc.getElementsByTagNameNS(node, sldNS, "MaxScaleDenominator");
28 t.eq(maxList.length, 0, "(none) node not written with MaxScaleDenominator");
30 // test that Min/MaxScaleDenominator is written out for explicit
32 layer = new OpenLayers.Layer.WMS(
33 "test", "http://foo", {},
34 {resolutions: [4, 2, 1], maxExtent: new OpenLayers.Bounds(1, 2, 3, 4)}
36 layer.minScale = Math.random();
37 layer.maxScale = Math.random();
38 sldNS = wmc.namespaces["sld"];
39 node = wmc.write_wmc_Layer(layer);
40 minList = wmc.getElementsByTagNameNS(node, sldNS, "MinScaleDenominator");
41 t.eq(minList.length, 1, "(resolutions) node written with MinScaleDenominator");
42 t.eq(layer.maxScale.toPrecision(10), wmc.getChildValue(minList[0]),
43 "(resolutions) node written with correct MinScaleDenominator value");
44 maxList = wmc.getElementsByTagNameNS(node, sldNS, "MaxScaleDenominator");
45 t.eq(maxList.length, 1, "(resolutions) node written with MaxScaleDenominator");
46 t.eq(layer.minScale.toPrecision(10), wmc.getChildValue(maxList[0]),
47 "(resolutions) node written with correct MaxScaleDenominator value");
49 layer = new OpenLayers.Layer.WMS(
50 "test", "http://foo", {},
51 {scales: [4, 2, 1], maxExtent: new OpenLayers.Bounds(1, 2, 3, 4)}
53 layer.minScale = Math.random();
54 layer.maxScale = Math.random();
55 node = wmc.write_wmc_Layer(layer);
56 minList = wmc.getElementsByTagNameNS(node, sldNS, "MinScaleDenominator");
57 var f = new OpenLayers.Format.XML();
58 t.eq(minList.length, 1, "(scales) node written with MinScaleDenominator");
59 t.eq(layer.maxScale.toPrecision(10), wmc.getChildValue(minList[0]),
60 "(scales) node written with correct MinScaleDenominator value");
61 maxList = wmc.getElementsByTagNameNS(node, sldNS, "MaxScaleDenominator");
62 t.eq(maxList.length, 1, "(scales) node written with MaxScaleDenominator");
63 t.eq(layer.minScale.toPrecision(10), wmc.getChildValue(maxList[0]),
64 "(scales) node written with correct MaxScaleDenominator value");
72 <div id="map" style="width: 512px; height: 256px;"></div>