From 33c37ef78bf1dc3642689a6631ce5453465caa74 Mon Sep 17 00:00:00 2001 From: euzuro Date: Thu, 5 Oct 2006 06:20:47 +0000 Subject: [PATCH] fix for #191 - graceful dealing with setCenter() on lonlat out of maxexteng (on first setcenter() call). added test git-svn-id: http://svn.openlayers.org/trunk/openlayers@1585 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 5 +++++ tests/test_Map.html | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 39de0da4ea..1e5ae3279a 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -576,6 +576,11 @@ OpenLayers.Map.prototype = { * trigger movestart/end events */ setCenter: function (lonlat, zoom, dragging) { + + if (!this.center && !this.isValidLonLat(lonlat)) { + lonlat = this.maxExtent.getCenterLonLat(); + } + var zoomChanged = (this.isValidZoomLevel(zoom)) && (zoom != this.getZoom()); diff --git a/tests/test_Map.html b/tests/test_Map.html index 314453e065..29f0f69c3f 100644 --- a/tests/test_Map.html +++ b/tests/test_Map.html @@ -247,6 +247,19 @@ } + function test_088_Map_setCenter(t) { + t.plan(1); + map = new OpenLayers.Map($('map')); + var baseLayer = new OpenLayers.Layer.WMS("Test Layer", + "http://octo.metacarta.com/cgi-bin/mapserv?", + {map: "/mapdata/vmap_wms.map", layers: "basic"}, + {maxResolution: 'auto', maxExtent: new OpenLayers.Bounds(-10,-10,10,10)}); + map.addLayer(baseLayer); + var ll = new OpenLayers.LonLat(-100,-150); + map.setCenter(ll, 0); + t.ok(map.getCenter().equals(new OpenLayers.LonLat(0,0)), "safely sets out-of-bounds lonlat"); + } + function test_99_Map_destroy (t) { t.plan( 2 );