fixing the movestart-move-moveend sequence. r=bartvde (closes #3139)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11661 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1581,21 +1581,20 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
this.moveByPx(dx, dy);
|
||||
}
|
||||
} else {
|
||||
// if we don't have a center, we were using moveByPx previously
|
||||
var forceSetCenter = !this.center;
|
||||
|
||||
// getCenter
|
||||
var centerPx = this.getViewPortPxFromLonLat(this.getCachedCenter());
|
||||
|
||||
// adjust
|
||||
var newCenterPx = centerPx.add(dx, dy);
|
||||
|
||||
if (forceSetCenter || !newCenterPx.equals(centerPx)) {
|
||||
if (this.dragging || !newCenterPx.equals(centerPx)) {
|
||||
var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx);
|
||||
if (options.animate) {
|
||||
this.panTo(newCenterLonLat);
|
||||
} else {
|
||||
this.setCenter(newCenterLonLat, null, options.dragging);
|
||||
this.moveTo(newCenterLonLat);
|
||||
this.dragging = false;
|
||||
this.events.triggerEvent("moveend");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1618,8 +1617,7 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
var center = this.getCachedCenter();
|
||||
|
||||
// center will not change, don't do nothing
|
||||
if (lonlat.lon == center.lon &&
|
||||
lonlat.lat == center.lat) {
|
||||
if (lonlat.equals(center)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1630,9 +1628,6 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
|
||||
this.panTween.start( { x: 0, y: 0 }, vector, this.panDuration, {
|
||||
callbacks: {
|
||||
start: OpenLayers.Function.bind(function() {
|
||||
this.events.triggerEvent("movestart");
|
||||
}, this),
|
||||
eachStep: OpenLayers.Function.bind(function(px) {
|
||||
var x = px.x - last.x,
|
||||
y = px.y - last.y;
|
||||
@@ -1641,7 +1636,8 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
last.y = Math.round(px.y);
|
||||
}, this),
|
||||
done: OpenLayers.Function.bind(function(px) {
|
||||
this.moveTo(lonlat, this.zoom, {noEvent: true});
|
||||
this.moveTo(lonlat);
|
||||
this.dragging = false;
|
||||
this.events.triggerEvent("moveend");
|
||||
}, this)
|
||||
}
|
||||
@@ -1666,10 +1662,10 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
* TBD: reconsider forceZoomChange in 3.0
|
||||
*/
|
||||
setCenter: function(lonlat, zoom, dragging, forceZoomChange) {
|
||||
this.panTween && this.panTween.stop();
|
||||
this.moveTo(lonlat, zoom, {
|
||||
'dragging': dragging,
|
||||
'forceZoomChange': forceZoomChange,
|
||||
'caller': 'setCenter'
|
||||
'forceZoomChange': forceZoomChange
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1705,6 +1701,10 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
x >= this.minPx.x + xRestriction;
|
||||
}
|
||||
if (valid) {
|
||||
if (!this.dragging) {
|
||||
this.dragging = true;
|
||||
this.events.triggerEvent("movestart");
|
||||
}
|
||||
this.center = null;
|
||||
if (dx) {
|
||||
this.layerContainerDiv.style.left =
|
||||
@@ -1757,15 +1757,9 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
}
|
||||
}
|
||||
// dragging is false by default
|
||||
var dragging = options.dragging;
|
||||
var dragging = options.dragging || this.dragging;
|
||||
// forceZoomChange is false by default
|
||||
var forceZoomChange = options.forceZoomChange;
|
||||
// noEvent is false by default
|
||||
var noEvent = options.noEvent;
|
||||
|
||||
if (this.panTween && options.caller == "setCenter") {
|
||||
this.panTween.stop();
|
||||
}
|
||||
|
||||
if (!this.getCachedCenter() && !this.isValidLonLat(lonlat)) {
|
||||
lonlat = this.maxExtent.getCenterLonLat();
|
||||
@@ -1812,13 +1806,9 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
var centerChanged = (this.isValidLonLat(lonlat)) &&
|
||||
(!lonlat.equals(this.center));
|
||||
|
||||
|
||||
// if neither center nor zoom will change, no need to do anything
|
||||
if (zoomChanged || centerChanged || !dragging) {
|
||||
|
||||
if (!this.dragging && !noEvent) {
|
||||
this.events.triggerEvent("movestart");
|
||||
}
|
||||
if (zoomChanged || centerChanged || dragging) {
|
||||
dragging || this.events.triggerEvent("movestart");
|
||||
|
||||
if (centerChanged) {
|
||||
if (!zoomChanged && this.center) {
|
||||
@@ -1860,15 +1850,11 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
//send the move call to the baselayer and all the overlays
|
||||
|
||||
if(this.baseLayer.visibility) {
|
||||
this.baseLayer.moveTo(bounds, zoomChanged, dragging);
|
||||
if(dragging) {
|
||||
this.baseLayer.events.triggerEvent("move");
|
||||
} else {
|
||||
this.baseLayer.events.triggerEvent("moveend",
|
||||
{"zoomChanged": zoomChanged}
|
||||
this.baseLayer.moveTo(bounds, zoomChanged, options.dragging);
|
||||
options.dragging || this.baseLayer.events.triggerEvent(
|
||||
"moveend", {zoomChanged: zoomChanged}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bounds = this.baseLayer.getExtent();
|
||||
|
||||
@@ -1890,38 +1876,25 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
});
|
||||
}
|
||||
if (inRange && layer.visibility) {
|
||||
layer.moveTo(bounds, zoomChanged, dragging);
|
||||
if(dragging) {
|
||||
layer.events.triggerEvent("move");
|
||||
} else {
|
||||
layer.events.triggerEvent("moveend",
|
||||
{"zoomChanged": zoomChanged}
|
||||
layer.moveTo(bounds, zoomChanged, options.dragging);
|
||||
options.dragging || layer.events.triggerEvent(
|
||||
"moveend", {zoomChanged: zoomChanged}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.events.triggerEvent("move");
|
||||
dragging || this.events.triggerEvent("moveend");
|
||||
|
||||
if (zoomChanged) {
|
||||
//redraw popups
|
||||
for (var i=0, len=this.popups.length; i<len; i++) {
|
||||
this.popups[i].updatePosition();
|
||||
}
|
||||
this.events.triggerEvent("zoomend");
|
||||
}
|
||||
|
||||
this.events.triggerEvent("move");
|
||||
|
||||
if (zoomChanged) { this.events.triggerEvent("zoomend"); }
|
||||
}
|
||||
|
||||
// even if nothing was done, we want to notify of this
|
||||
if (!dragging && !noEvent) {
|
||||
this.events.triggerEvent("moveend");
|
||||
}
|
||||
|
||||
// Store the map dragging state for later use
|
||||
this.dragging = !!dragging;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -163,8 +163,15 @@
|
||||
}
|
||||
|
||||
function test_Map_center(t) {
|
||||
t.plan(8);
|
||||
map = new OpenLayers.Map('map');
|
||||
t.plan(11);
|
||||
var log = [];
|
||||
map = new OpenLayers.Map('map', {
|
||||
eventListeners: {
|
||||
"movestart": function() {log.push("movestart");},
|
||||
"move": function() {log.push("move");},
|
||||
"moveend": function() {log.push("moveend");}
|
||||
}
|
||||
});
|
||||
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"} );
|
||||
@@ -180,7 +187,11 @@
|
||||
map.zoomOut();
|
||||
t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter,zoom in, zoom out");
|
||||
|
||||
log = [];
|
||||
map.zoomTo(5);
|
||||
t.eq(log[0], "movestart", "zoomTo fires movestart event");
|
||||
t.eq(log[1], "move", "zoomTo fires move event");
|
||||
t.eq(log[2], "moveend", "zoomTo fires moveend event");
|
||||
t.eq( map.getZoom(), 5, "map.zoom is correct after calling zoomTo" );
|
||||
|
||||
/**
|
||||
@@ -1527,19 +1538,60 @@
|
||||
|
||||
function test_panTo(t) {
|
||||
|
||||
t.plan(2);
|
||||
t.plan(6);
|
||||
|
||||
var map = new OpenLayers.Map("map");
|
||||
var log = [];
|
||||
var map = new OpenLayers.Map("map", {
|
||||
eventListeners: {
|
||||
"movestart": function() {log.push("movestart");},
|
||||
"move": function() {log.push("move");},
|
||||
"moveend": function() {log.push("moveend");}
|
||||
}
|
||||
});
|
||||
map.addLayer(
|
||||
new OpenLayers.Layer(null, {isBaseLayer: true})
|
||||
);
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||
t.eq(log[log.length-1], "moveend", "moveend fired when map center is set");
|
||||
log = [];
|
||||
|
||||
map.panTo(new OpenLayers.LonLat(1, 0));
|
||||
t.eq(map.panTween.playing, true, "the map pan tween is playing before destroy");
|
||||
|
||||
t.delay_call(2, function() {
|
||||
t.eq(log[0], "movestart", "panTo starts with movestart event");
|
||||
t.eq(log[1], "move", "move events fired while panning");
|
||||
t.eq(log[log.length-1], "moveend", "panTo finishes with moveend event");
|
||||
map.destroy();
|
||||
t.ok(!map.panTween || !map.panTween.playing, "the map pan tween is not playing after destroy");
|
||||
});
|
||||
}
|
||||
|
||||
function test_pan(t) {
|
||||
t.plan(4);
|
||||
|
||||
var log = [];
|
||||
var map = new OpenLayers.Map("map");
|
||||
map.addLayer(
|
||||
new OpenLayers.Layer(null, {isBaseLayer: true})
|
||||
);
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 5);
|
||||
var log = [];
|
||||
map.events.on({
|
||||
"movestart": function() {log.push("movestart");},
|
||||
"move": function() {log.push("move");},
|
||||
"moveend": function() {log.push("moveend");}
|
||||
});
|
||||
|
||||
// simulate the drag sequence of the DragPan control;
|
||||
map.pan(5,5, {animate: false, dragging: true});
|
||||
map.pan(1,1, {animate: false, dragging: false});
|
||||
|
||||
t.eq(log[0], "movestart", "pan sequence starts with movestart");
|
||||
t.eq(log[1], "move", "followed by move,");
|
||||
t.eq(log[log.length-2], "move", "move again before we stop panning,");
|
||||
t.eq(log[log.length-1], "moveend", "and moveend when we're done.");
|
||||
|
||||
}
|
||||
|
||||
function test_updateSize(t) {
|
||||
|
||||
Reference in New Issue
Block a user