Making it so moveTo is only called once when creating a map with center and layers options. r=crschmidt (closes #3114)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11480 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -600,6 +600,14 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
|
|
||||||
// add any initial layers
|
// add any initial layers
|
||||||
if (options && options.layers) {
|
if (options && options.layers) {
|
||||||
|
/**
|
||||||
|
* If you have set options.center, the map center property will be
|
||||||
|
* set at this point. However, since setCenter has not been caleld,
|
||||||
|
* addLayers gets confused. So we delete the map center in this
|
||||||
|
* case. Because the check below uses options.center, it will
|
||||||
|
* be properly set below.
|
||||||
|
*/
|
||||||
|
delete this.center;
|
||||||
this.addLayers(options.layers);
|
this.addLayers(options.layers);
|
||||||
// set center (and optionally zoom)
|
// set center (and optionally zoom)
|
||||||
if (options.center) {
|
if (options.center) {
|
||||||
|
|||||||
@@ -1602,7 +1602,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_center_option(t) {
|
function test_center_option(t) {
|
||||||
t.plan(6);
|
t.plan(7);
|
||||||
|
|
||||||
var map, msg;
|
var map, msg;
|
||||||
|
|
||||||
@@ -1625,6 +1625,12 @@
|
|||||||
map.destroy();
|
map.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var log = [];
|
||||||
|
var meth = OpenLayers.Layer.prototype.moveTo;
|
||||||
|
OpenLayers.Layer.prototype.moveTo = function() {
|
||||||
|
log.push(arguments);
|
||||||
|
meth.apply(this, arguments);
|
||||||
|
};
|
||||||
|
|
||||||
// set center without zoom
|
// set center without zoom
|
||||||
var center = new OpenLayers.LonLat(1, 2);
|
var center = new OpenLayers.LonLat(1, 2);
|
||||||
@@ -1635,8 +1641,10 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
t.ok(center.equals(map.getCenter()), "map center set without zoom");
|
t.ok(center.equals(map.getCenter()), "map center set without zoom");
|
||||||
|
t.eq(log.length, 1, "moveTo called once");
|
||||||
|
|
||||||
map.destroy();
|
map.destroy();
|
||||||
|
OpenLayers.Layer.prototype.moveTo = meth;
|
||||||
|
|
||||||
// set center and zoom
|
// set center and zoom
|
||||||
var zoom = 3;
|
var zoom = 3;
|
||||||
|
|||||||
Reference in New Issue
Block a user