correctly parse ScaleHint values from WMS GetCapabilities response, thanks elemoine for the testcase, r=elemoine (closes #2150)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9571 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2009-07-20 12:32:31 +00:00
parent f4d60b89a8
commit 2c8ec98643
2 changed files with 39 additions and 4 deletions

View File

@@ -184,10 +184,10 @@ OpenLayers.Format.WMSCapabilities.v1_1 = OpenLayers.Class(
var rad2 = Math.pow(2, 0.5);
var ipm = OpenLayers.INCHES_PER_UNIT["m"];
layer.maxScale = parseFloat(
((rad2 * min) * ipm * OpenLayers.DOTS_PER_INCH).toPrecision(13)
((min / rad2) * ipm * OpenLayers.DOTS_PER_INCH).toPrecision(13)
);
layer.minScale = parseFloat(
((rad2 * max) * ipm * OpenLayers.DOTS_PER_INCH).toPrecision(13)
((max / rad2) * ipm * OpenLayers.DOTS_PER_INCH).toPrecision(13)
);
},
@@ -311,4 +311,4 @@ OpenLayers.Format.WMSCapabilities.v1_1 = OpenLayers.Class(
CLASS_NAME: "OpenLayers.Format.WMSCapabilities.v1_1"
});
});

View File

@@ -54,13 +54,25 @@
}
function test_ogc(t) {
t.plan(12)
t.plan(14)
/*
* Set up
*/
// needed for the minScale/maxScale test, see below
var dpi = OpenLayers.DOTS_PER_INCH;
OpenLayers.DOTS_PER_INCH = 90.71;
var xml = document.getElementById("ogcsample").firstChild.nodeValue;
var doc = new OpenLayers.Format.XML().read(xml);
var obj = new OpenLayers.Format.WMSCapabilities().read(doc);
var capability = obj.capability;
/*
* Test
*/
var attribution = capability.layers[2].attribution;
t.eq(attribution.title, "State College University", "attribution title parsed correctly.");
@@ -79,6 +91,28 @@
t.eq(metadataURLs[0].type, "FGDC", "type parsed correctly.");
t.eq(metadataURLs[0].format, "text/plain", "format parsed correctly.");
t.eq(metadataURLs[0].href, "http://www.university.edu/metadata/roads.txt", "href parsed correctly.");
/*
Test minScale and maxScale
For Mapserver
<ScaleHint min="0.395998292216226" max="98.9995730540565" />
corresponds to (RESOLUTION keyword in MAP file has value of 90.71):
MAXSCALE 250000
MINSCALE 1000
*/
t.eq(capability.layers[0].minScale, 250000, "layer.minScale is correct");
t.eq(capability.layers[0].maxScale, 1000, "layer.maxScale is correct");
/*
* Tear down
*/
OpenLayers.DOTS_PER_INCH = dpi;
}
</script>
@@ -310,6 +344,7 @@ Changes:
</LegendURL>
</Style>
<ScaleHint min="0.395998292216226" max="98.9995730540565" />
</Layer>
<Layer queryable="1">
<Name>RIVERS_1M</Name>