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 = 'landsat7NASA Global Mosaicimage/jpeg4degreestruetruefalsebasicOpenLayers WMSimage/jpeg4degreestruetruefalsena_road:CCRSTransportation Networkimage/pngTRUE4degreesfalse0.6falsefalse3:1Radar 3:1image/pngTRUE4degreesfalse0.8falsetrue';
var v1_1_0 = 'landsat7NASA Global Mosaic6299645.76031498228.80image/jpeg4degreestruetruefalsebasicOpenLayers WMS6299645.76031498228.80image/jpeg4degreestruetruefalsena_road:CCRSTransportation Network6200000.00032000000.00image/pngTRUE4degreesfalse0.6falsefalse3:1Radar 3:16299645.76031498228.80image/pngTRUE4degreesfalse0.8truetrue';
+ var polar = 'WMS viewermworldThe Worldimage/jpegimage/png';
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();