Merge pull request #760 from ahocevar/wmscaps-scalehint

Correct handling of 0 and Infinity ScaleHint. r=@marcjansen
This commit is contained in:
ahocevar
2012-11-20 08:01:48 -08:00
3 changed files with 23 additions and 11 deletions
+12 -8
View File
@@ -78,14 +78,18 @@ OpenLayers.Format.WMSCapabilities.v1_1 = OpenLayers.Class(
var max = node.getAttribute("max"); var max = node.getAttribute("max");
var rad2 = Math.pow(2, 0.5); var rad2 = Math.pow(2, 0.5);
var ipm = OpenLayers.INCHES_PER_UNIT["m"]; var ipm = OpenLayers.INCHES_PER_UNIT["m"];
obj.maxScale = parseFloat( if (min != 0) {
((min / rad2) * ipm * obj.maxScale = parseFloat(
OpenLayers.DOTS_PER_INCH).toPrecision(13) ((min / rad2) * ipm *
); OpenLayers.DOTS_PER_INCH).toPrecision(13)
obj.minScale = parseFloat( );
((max / rad2) * ipm * }
OpenLayers.DOTS_PER_INCH).toPrecision(13) if (max != Number.POSITIVE_INFINITY) {
); obj.minScale = parseFloat(
((max / rad2) * ipm *
OpenLayers.DOTS_PER_INCH).toPrecision(13)
);
}
}, },
"Dimension": function(node, obj) { "Dimension": function(node, obj) {
var name = node.getAttribute("name").toLowerCase(); var name = node.getAttribute("name").toLowerCase();
@@ -10,6 +10,13 @@
/** /**
* Class: OpenLayers.Format.WMSCapabilities/v1_1_1 * Class: OpenLayers.Format.WMSCapabilities/v1_1_1
* Read WMS Capabilities version 1.1.1. * Read WMS Capabilities version 1.1.1.
*
* Note on <ScaleHint> parsing: If the 'min' attribute is set to "0", no
* maxScale will be set on the layer object. If the 'max' attribute is set to
* "Infinity", no minScale will be set. This makes it easy to create proper
* {<OpenLayers.Layer.WMS>} configurations directly from the layer object
* literals returned by this format, because no minScale/maxScale modifications
* need to be made.
* *
* Inherits from: * Inherits from:
* - <OpenLayers.Format.WMSCapabilities.v1_1> * - <OpenLayers.Format.WMSCapabilities.v1_1>
+4 -3
View File
@@ -332,7 +332,7 @@
} }
function test_ogc(t) { function test_ogc(t) {
t.plan(14) t.plan(16)
/* /*
* Set up * Set up
@@ -386,6 +386,8 @@
t.eq(capability.layers[0].minScale, 250000, "layer.minScale is correct"); t.eq(capability.layers[0].minScale, 250000, "layer.minScale is correct");
t.eq(capability.layers[0].maxScale, 1000, "layer.maxScale is correct"); t.eq(capability.layers[0].maxScale, 1000, "layer.maxScale is correct");
t.eq(capability.layers[1].minScale, undefined, "layer.minScale for max='Infinity' is correct");
t.eq(capability.layers[1].maxScale, undefined, "layer.maxScale for min='0' is correct");
/* /*
* Tear down * Tear down
*/ */
@@ -590,8 +592,6 @@ Changes:
</StyleSheetURL> </StyleSheetURL>
</Style> </Style>
<ScaleHint min="4000" max="35000"></ScaleHint>
<Layer queryable="1"> <Layer queryable="1">
<Name>ROADS_1M</Name> <Name>ROADS_1M</Name>
@@ -641,6 +641,7 @@ Changes:
<Keyword>canal</Keyword> <Keyword>canal</Keyword>
<Keyword>waterway</Keyword> <Keyword>waterway</Keyword>
</KeywordList> </KeywordList>
<ScaleHint min="0" max="Infinity" />
</Layer> </Layer>
</Layer> </Layer>
<Layer queryable="1"> <Layer queryable="1">