Fixed zoomend event code; changed semantics of the argument to moveToNewExtent to make the argument be the *previous* zoom level. Added tests.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@66 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Schuyler Erle
2006-05-16 23:46:41 +00:00
parent c494b8ef2d
commit ed9b57b6df
2 changed files with 24 additions and 17 deletions

View File

@@ -241,10 +241,10 @@ OpenLayers.Map.prototype = {
this.moveLayerContainer(latlon);
}
this.center = latlon.copyOf();
var zoomChanged = false;
if (zoom != null) {
if (this.zoom && zoom != this.zoom)
zoomChanged = true;
var zoomChanged = null;
if (zoom != null && zoom != this.zoom
&& zoom >= 0 && zoom <= this.getZoomLevels()) {
zoomChanged = (this.zoom == null ? 0 : this.zoom);
this.zoom = zoom;
}
@@ -254,17 +254,18 @@ OpenLayers.Map.prototype = {
},
moveToNewExtent: function (zoomChanged) {
if (zoomChanged) { // reset the layerContainerDiv's location
if (zoomChanged != null) { // reset the layerContainerDiv's location
this.layerContainerDiv.style.left = "0px";
this.layerContainerDiv.style.top = "0px";
}
var bounds = this.getExtent();
for (var i = 0; i < this.layers.length; i++) {
this.layers[i].moveTo(bounds, zoomChanged);
this.layers[i].moveTo(bounds, (zoomChanged != null));
}
this.events.triggerEvent("move");
if (zoomChanged)
this.events.triggerEvent("zoomend");
if (zoomChanged != null)
this.events.triggerEvent("zoomend",
{oldZoom: zoomChanged, newZoom: this.zoom});
},
/**
@@ -286,8 +287,7 @@ OpenLayers.Map.prototype = {
if (zoom >= 0 && zoom <= this.getZoomLevels()) {
var oldZoom = this.zoom;
this.zoom = zoom;
this.moveToNewExtent(true);
this.events.triggerEvent("zoomend", {oldZoom: oldZoom, newZoom: this.zoom});
this.moveToNewExtent(oldZoom);
}
},
@@ -303,7 +303,7 @@ OpenLayers.Map.prototype = {
zoomExtent: function() {
var fullExtent = this.getFullExtent();
var oldZoom = this.zoom;
this.zoom = this.getZoomForExtent( fullExtent );
this.setCenter(
new OpenLayers.LatLon(
@@ -311,8 +311,6 @@ OpenLayers.Map.prototype = {
(fullExtent.minlon+fullExtent.maxlon)/2
)
);
this.moveToNewExtent(true);
},
/**
@@ -337,8 +335,7 @@ OpenLayers.Map.prototype = {
*/
defaultDblClick: function (evt) {
var newCenter = this.getLatLonFromPixel( evt.xy );
this.zoomIn();
this.setCenter(newCenter);
this.setCenter(newCenter, this.zoom + 1);
},
/**

View File

@@ -54,17 +54,27 @@
t.eq( map.maxResolution, 3.14159, "map.maxResolution set correctly via options hash" );
}
function test_05_Map_center(t) {
t.plan(5);
t.plan(4);
map = new OpenLayers.Map($('map'));
map.setCenter(new OpenLayers.LatLon(1,2), 0);
map.zoomIn();
t.ok( map.getCenter() instanceof OpenLayers.LatLon, "map.getCenter returns a LatLon");
t.eq( map.getZoom(), 1, "map.zoom is correct after calling setCenter,zoom in");
t.eq( map.getCenter().lat, 1, "map center lat is correct after calling setCenter,zoom in");
t.eq( map.getCenter().lon, 2, "map center lon is correct after calling setCenter, zoom in");
map.zoomOut();
t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter,zoom in, zoom out");
}
function test_06_Map_zoomend_event (t) {
t.plan(3);
map = new OpenLayers.Map('map');
map.events.register("zoomend", {count: 0}, function() {
this.count++;
t.ok(true, "zoomend event was triggered " + this.count + " times");
});
map.setCenter(new OpenLayers.LatLon(1,2), 0);
map.zoomIn();
map.zoomOut();
}
function test_99_Map_destroy (t) {
t.plan( 2 );
map = new OpenLayers.Map($('map'));