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,16 +1757,10 @@ 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,14 +1850,10 @@ 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("move");
|
||||
|
||||
if (zoomChanged) { this.events.triggerEvent("zoomend"); }
|
||||
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;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user