Only write out min/max scale related properties if they are explicitly set on the layer. Thanks for slapping Safari around a bit with this on crschmidt. Works but still untested there. r=crschmidt (closes #1314)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6033 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-02-07 21:06:08 +00:00
parent 9d045baf71
commit 61f124f214
3 changed files with 91 additions and 10 deletions

View File

@@ -89,17 +89,23 @@ OpenLayers.Format.WMC.v1_1_0 = OpenLayers.Class(
);
// min/max scale denominator elements go before the 4th element in v1
var minSD = this.createElementNS(
this.namespaces.sld, "sld:MinScaleDenominator"
);
minSD.appendChild(this.createTextNode(layer.maxScale.toPrecision(10)));
node.insertBefore(minSD, node.childNodes[3]);
if(layer.options.resolutions || layer.options.scales ||
layer.options.minResolution || layer.options.maxScale) {
var minSD = this.createElementNS(
this.namespaces.sld, "sld:MinScaleDenominator"
);
minSD.appendChild(this.createTextNode(layer.maxScale.toPrecision(10)));
node.insertBefore(minSD, node.childNodes[3]);
}
var maxSD = this.createElementNS(
this.namespaces.sld, "sld:MaxScaleDenominator"
);
maxSD.appendChild(this.createTextNode(layer.minScale.toPrecision(10)));
node.insertBefore(maxSD, node.childNodes[4]);
if(layer.options.resolutions || layer.options.scales ||
layer.options.maxResolution || layer.options.minScale) {
var maxSD = this.createElementNS(
this.namespaces.sld, "sld:MaxScaleDenominator"
);
maxSD.appendChild(this.createTextNode(layer.minScale.toPrecision(10)));
node.insertBefore(maxSD, node.childNodes[4]);
}
return node;

View File

@@ -0,0 +1,74 @@
<html>
<head>
<script src="../../../lib/OpenLayers.js"></script>
<script type="text/javascript">
function test_write_wmc_Layer(t) {
if (OpenLayers.Util.getBrowserName() == "safari") {
t.plan(0);
t.debug_print("Safari has wierd behavior with getElementsByTagNameNS: the result is that we can't run these tests there. Patches welcome.");
return;
}
t.plan(10);
// direct construction of a parser for a unit test
var wmc = new OpenLayers.Format.WMC.v1_1_0();
var sldNS = wmc.namespaces["sld"];
// test that Min/MaxScaleDenominator is not written out when no
// resolution related options are set
var layer = new OpenLayers.Layer.WMS(
"test", "http://foo", {},
{maxExtent: new OpenLayers.Bounds(1, 2, 3, 4)}
);
var node = wmc.write_wmc_Layer(layer);
var minList = wmc.getElementsByTagNameNS(node, sldNS, "MinScaleDenominator");
t.eq(minList.length, 0, "(none) node not written with MinScaleDenominator");
var maxList = wmc.getElementsByTagNameNS(node, sldNS, "MaxScaleDenominator");
t.eq(maxList.length, 0, "(none) node not written with MaxScaleDenominator");
// test that Min/MaxScaleDenominator is written out for explicit
// resolutions array
layer = new OpenLayers.Layer.WMS(
"test", "http://foo", {},
{resolutions: [4, 2, 1], maxExtent: new OpenLayers.Bounds(1, 2, 3, 4)}
);
layer.minScale = Math.random();
layer.maxScale = Math.random();
sldNS = wmc.namespaces["sld"];
node = wmc.write_wmc_Layer(layer);
minList = wmc.getElementsByTagNameNS(node, sldNS, "MinScaleDenominator");
t.eq(minList.length, 1, "(resolutions) node written with MinScaleDenominator");
t.eq(layer.maxScale.toPrecision(10), wmc.getChildValue(minList[0]),
"(resolutions) node written with correct MinScaleDenominator value");
maxList = wmc.getElementsByTagNameNS(node, sldNS, "MaxScaleDenominator");
t.eq(maxList.length, 1, "(resolutions) node written with MaxScaleDenominator");
t.eq(layer.minScale.toPrecision(10), wmc.getChildValue(maxList[0]),
"(resolutions) node written with correct MaxScaleDenominator value");
layer = new OpenLayers.Layer.WMS(
"test", "http://foo", {},
{scales: [4, 2, 1], maxExtent: new OpenLayers.Bounds(1, 2, 3, 4)}
);
layer.minScale = Math.random();
layer.maxScale = Math.random();
node = wmc.write_wmc_Layer(layer);
minList = wmc.getElementsByTagNameNS(node, sldNS, "MinScaleDenominator");
var f = new OpenLayers.Format.XML();
t.eq(minList.length, 1, "(scales) node written with MinScaleDenominator");
t.eq(layer.maxScale.toPrecision(10), wmc.getChildValue(minList[0]),
"(scales) node written with correct MinScaleDenominator value");
maxList = wmc.getElementsByTagNameNS(node, sldNS, "MaxScaleDenominator");
t.eq(maxList.length, 1, "(scales) node written with MaxScaleDenominator");
t.eq(layer.minScale.toPrecision(10), wmc.getChildValue(maxList[0]),
"(scales) node written with correct MaxScaleDenominator value");
}
</script>
</head>
<body>
<div id="map" style="width: 512px; height: 256px;"></div>
</body>
</html>

View File

@@ -31,6 +31,7 @@
<li>Format/test_SLD.html</li>
<li>Format/test_WKT.html</li>
<li>Format/test_WMC.html</li>
<li>Format/WMC/test_v1_1_0.html</li>
<li>Format/test_XML.html</li>
<li>test_Icon.html</li>
<li>test_Marker.html</li>