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:
+29
-56
@@ -1581,21 +1581,20 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
this.moveByPx(dx, dy);
|
this.moveByPx(dx, dy);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if we don't have a center, we were using moveByPx previously
|
|
||||||
var forceSetCenter = !this.center;
|
|
||||||
|
|
||||||
// getCenter
|
// getCenter
|
||||||
var centerPx = this.getViewPortPxFromLonLat(this.getCachedCenter());
|
var centerPx = this.getViewPortPxFromLonLat(this.getCachedCenter());
|
||||||
|
|
||||||
// adjust
|
// adjust
|
||||||
var newCenterPx = centerPx.add(dx, dy);
|
var newCenterPx = centerPx.add(dx, dy);
|
||||||
|
|
||||||
if (forceSetCenter || !newCenterPx.equals(centerPx)) {
|
if (this.dragging || !newCenterPx.equals(centerPx)) {
|
||||||
var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx);
|
var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx);
|
||||||
if (options.animate) {
|
if (options.animate) {
|
||||||
this.panTo(newCenterLonLat);
|
this.panTo(newCenterLonLat);
|
||||||
} else {
|
} 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();
|
var center = this.getCachedCenter();
|
||||||
|
|
||||||
// center will not change, don't do nothing
|
// center will not change, don't do nothing
|
||||||
if (lonlat.lon == center.lon &&
|
if (lonlat.equals(center)) {
|
||||||
lonlat.lat == center.lat) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1630,9 +1628,6 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
|
|
||||||
this.panTween.start( { x: 0, y: 0 }, vector, this.panDuration, {
|
this.panTween.start( { x: 0, y: 0 }, vector, this.panDuration, {
|
||||||
callbacks: {
|
callbacks: {
|
||||||
start: OpenLayers.Function.bind(function() {
|
|
||||||
this.events.triggerEvent("movestart");
|
|
||||||
}, this),
|
|
||||||
eachStep: OpenLayers.Function.bind(function(px) {
|
eachStep: OpenLayers.Function.bind(function(px) {
|
||||||
var x = px.x - last.x,
|
var x = px.x - last.x,
|
||||||
y = px.y - last.y;
|
y = px.y - last.y;
|
||||||
@@ -1641,7 +1636,8 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
last.y = Math.round(px.y);
|
last.y = Math.round(px.y);
|
||||||
}, this),
|
}, this),
|
||||||
done: OpenLayers.Function.bind(function(px) {
|
done: OpenLayers.Function.bind(function(px) {
|
||||||
this.moveTo(lonlat, this.zoom, {noEvent: true});
|
this.moveTo(lonlat);
|
||||||
|
this.dragging = false;
|
||||||
this.events.triggerEvent("moveend");
|
this.events.triggerEvent("moveend");
|
||||||
}, this)
|
}, this)
|
||||||
}
|
}
|
||||||
@@ -1666,10 +1662,10 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
* TBD: reconsider forceZoomChange in 3.0
|
* TBD: reconsider forceZoomChange in 3.0
|
||||||
*/
|
*/
|
||||||
setCenter: function(lonlat, zoom, dragging, forceZoomChange) {
|
setCenter: function(lonlat, zoom, dragging, forceZoomChange) {
|
||||||
|
this.panTween && this.panTween.stop();
|
||||||
this.moveTo(lonlat, zoom, {
|
this.moveTo(lonlat, zoom, {
|
||||||
'dragging': dragging,
|
'dragging': dragging,
|
||||||
'forceZoomChange': forceZoomChange,
|
'forceZoomChange': forceZoomChange
|
||||||
'caller': 'setCenter'
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1705,6 +1701,10 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
x >= this.minPx.x + xRestriction;
|
x >= this.minPx.x + xRestriction;
|
||||||
}
|
}
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
if (!this.dragging) {
|
||||||
|
this.dragging = true;
|
||||||
|
this.events.triggerEvent("movestart");
|
||||||
|
}
|
||||||
this.center = null;
|
this.center = null;
|
||||||
if (dx) {
|
if (dx) {
|
||||||
this.layerContainerDiv.style.left =
|
this.layerContainerDiv.style.left =
|
||||||
@@ -1757,16 +1757,10 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// dragging is false by default
|
// dragging is false by default
|
||||||
var dragging = options.dragging;
|
var dragging = options.dragging || this.dragging;
|
||||||
// forceZoomChange is false by default
|
// forceZoomChange is false by default
|
||||||
var forceZoomChange = options.forceZoomChange;
|
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)) {
|
if (!this.getCachedCenter() && !this.isValidLonLat(lonlat)) {
|
||||||
lonlat = this.maxExtent.getCenterLonLat();
|
lonlat = this.maxExtent.getCenterLonLat();
|
||||||
}
|
}
|
||||||
@@ -1812,13 +1806,9 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
var centerChanged = (this.isValidLonLat(lonlat)) &&
|
var centerChanged = (this.isValidLonLat(lonlat)) &&
|
||||||
(!lonlat.equals(this.center));
|
(!lonlat.equals(this.center));
|
||||||
|
|
||||||
|
|
||||||
// if neither center nor zoom will change, no need to do anything
|
// if neither center nor zoom will change, no need to do anything
|
||||||
if (zoomChanged || centerChanged || !dragging) {
|
if (zoomChanged || centerChanged || dragging) {
|
||||||
|
dragging || this.events.triggerEvent("movestart");
|
||||||
if (!this.dragging && !noEvent) {
|
|
||||||
this.events.triggerEvent("movestart");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (centerChanged) {
|
if (centerChanged) {
|
||||||
if (!zoomChanged && this.center) {
|
if (!zoomChanged && this.center) {
|
||||||
@@ -1860,14 +1850,10 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
//send the move call to the baselayer and all the overlays
|
//send the move call to the baselayer and all the overlays
|
||||||
|
|
||||||
if(this.baseLayer.visibility) {
|
if(this.baseLayer.visibility) {
|
||||||
this.baseLayer.moveTo(bounds, zoomChanged, dragging);
|
this.baseLayer.moveTo(bounds, zoomChanged, options.dragging);
|
||||||
if(dragging) {
|
options.dragging || this.baseLayer.events.triggerEvent(
|
||||||
this.baseLayer.events.triggerEvent("move");
|
"moveend", {zoomChanged: zoomChanged}
|
||||||
} else {
|
);
|
||||||
this.baseLayer.events.triggerEvent("moveend",
|
|
||||||
{"zoomChanged": zoomChanged}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bounds = this.baseLayer.getExtent();
|
bounds = this.baseLayer.getExtent();
|
||||||
@@ -1890,38 +1876,25 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (inRange && layer.visibility) {
|
if (inRange && layer.visibility) {
|
||||||
layer.moveTo(bounds, zoomChanged, dragging);
|
layer.moveTo(bounds, zoomChanged, options.dragging);
|
||||||
if(dragging) {
|
options.dragging || layer.events.triggerEvent(
|
||||||
layer.events.triggerEvent("move");
|
"moveend", {zoomChanged: zoomChanged}
|
||||||
} else {
|
);
|
||||||
layer.events.triggerEvent("moveend",
|
|
||||||
{"zoomChanged": zoomChanged}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.events.triggerEvent("move");
|
||||||
|
dragging || this.events.triggerEvent("moveend");
|
||||||
|
|
||||||
if (zoomChanged) {
|
if (zoomChanged) {
|
||||||
//redraw popups
|
//redraw popups
|
||||||
for (var i=0, len=this.popups.length; i<len; i++) {
|
for (var i=0, len=this.popups.length; i<len; i++) {
|
||||||
this.popups[i].updatePosition();
|
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;
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+58
-6
@@ -163,8 +163,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Map_center(t) {
|
function test_Map_center(t) {
|
||||||
t.plan(8);
|
t.plan(11);
|
||||||
map = new OpenLayers.Map('map');
|
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",
|
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
||||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||||
{map: "/mapdata/vmap_wms.map", layers: "basic"} );
|
{map: "/mapdata/vmap_wms.map", layers: "basic"} );
|
||||||
@@ -180,7 +187,11 @@
|
|||||||
map.zoomOut();
|
map.zoomOut();
|
||||||
t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter,zoom in, zoom out");
|
t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter,zoom in, zoom out");
|
||||||
|
|
||||||
|
log = [];
|
||||||
map.zoomTo(5);
|
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" );
|
t.eq( map.getZoom(), 5, "map.zoom is correct after calling zoomTo" );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1527,19 +1538,60 @@
|
|||||||
|
|
||||||
function test_panTo(t) {
|
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(
|
map.addLayer(
|
||||||
new OpenLayers.Layer(null, {isBaseLayer: true})
|
new OpenLayers.Layer(null, {isBaseLayer: true})
|
||||||
);
|
);
|
||||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
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));
|
map.panTo(new OpenLayers.LonLat(1, 0));
|
||||||
t.eq(map.panTween.playing, true, "the map pan tween is playing before destroy");
|
t.eq(map.panTween.playing, true, "the map pan tween is playing before destroy");
|
||||||
|
|
||||||
map.destroy();
|
t.delay_call(2, function() {
|
||||||
t.ok(!map.panTween || !map.panTween.playing, "the map pan tween is not playing after destroy");
|
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) {
|
function test_updateSize(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user