diff --git a/lib/OpenLayers/Format/Context.js b/lib/OpenLayers/Format/Context.js index 88b0edebbf..26e875e386 100644 --- a/lib/OpenLayers/Format/Context.js +++ b/lib/OpenLayers/Format/Context.js @@ -269,9 +269,14 @@ OpenLayers.Format.Context = OpenLayers.Class({ */ contextToMap: function(context, options) { options = OpenLayers.Util.applyDefaults({ - maxExtent: context.maxExtent, - projection: context.projection + maxExtent: context.maxExtent, + projection: context.projection, + units: context.units }, options); + if (options.maxExtent) { + options.maxResolution = + options.maxExtent.getWidth() / OpenLayers.Map.TILE_WIDTH; + } var map = new OpenLayers.Map(options); map.addLayers(this.getLayersFromContext(context.layersContext)); map.setCenter( diff --git a/tests/Format/WMC.html b/tests/Format/WMC.html index 33a7a34cf3..4608ed3fc0 100644 --- a/tests/Format/WMC.html +++ b/tests/Format/WMC.html @@ -5,9 +5,10 @@ var v1_0_0 = '<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 Mosaicimage/jpeg4degreestruetruefalse'; var v1_1_0 = '<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 Mosaic6299645.76031498228.80image/jpeg4degreestruetruefalse'; + var polar = 'WMS viewerm'; function test_Format_WMC_read(t) { - t.plan(36); + t.plan(37); var format = new OpenLayers.Format.WMC(); var map, layer; @@ -53,7 +54,7 @@ map.destroy(); // test v1.1.0 - var map = format.read(v1_1_0, {map: "map"}); + map = format.read(v1_1_0, {map: "map"}); t.eq(map.center.lon.toPrecision(6), (-95).toPrecision(6), "(v1.1.0) map center correctly set"); t.eq(map.center.lat.toPrecision(6), (34.5).toPrecision(6), "(v1.1.0) map center correctly set"); t.eq(map.maxExtent.left.toPrecision(6), (-130).toPrecision(6), "(v1.1.0) map maxExtent correctly set"); @@ -91,8 +92,14 @@ "(v1.1.0) layer opacity correctly set"); map.destroy(); + // Check if maxResolution is set correctly + map = format.read(polar, {map: "map"}); + t.eq(map.maxResolution, 39062.5, + "maxResolution correctly set"); + map.destroy(); + // test mapOptions - var map = format.read(v1_1_0, {map: {foo: 'bar', div: 'map'}}); + map = format.read(v1_1_0, {map: {foo: 'bar', div: 'map'}}); t.eq(map.foo, "bar", "mapOptions correctly passed to the created map object"); map.destroy();