Refactor setCenter to do most of its work through a smarter function called
moveTo. In moveTo, we also have knowledge of whether the event was fired through setCenter, allowing us to know the difference between an 'internal' move and an external one. git-svn-id: http://svn.openlayers.org/trunk/openlayers@6099 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1259,9 +1259,33 @@ 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.dragging = !!dragging;
|
this.moveTo(lonlat, zoom, {
|
||||||
|
'dragging': dragging,
|
||||||
|
'forceZoomChange': forceZoomChange,
|
||||||
|
'caller': 'setCenter'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: moveTo
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* lonlat - {<OpenLayers.LonLat>}
|
||||||
|
* zoom - {Integer}
|
||||||
|
* options - {Object}
|
||||||
|
*/
|
||||||
|
moveTo: function(lonlat, zoom, options) {
|
||||||
|
if (!options) {
|
||||||
|
options = {};
|
||||||
|
}
|
||||||
|
// dragging is false by default
|
||||||
|
var dragging = options.dragging;
|
||||||
|
// forceZoomChange is false by default
|
||||||
|
var forceZoomChange = options.forceZoomChange;
|
||||||
|
// noEvent is false by default
|
||||||
|
var noEvent = options.noEvent;
|
||||||
|
|
||||||
if (!this.center && !this.isValidLonLat(lonlat)) {
|
if (!this.center && !this.isValidLonLat(lonlat)) {
|
||||||
lonlat = this.maxExtent.getCenterLonLat();
|
lonlat = this.maxExtent.getCenterLonLat();
|
||||||
}
|
}
|
||||||
@@ -1311,7 +1335,9 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
// 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) {
|
||||||
|
|
||||||
if (!dragging) { this.events.triggerEvent("movestart"); }
|
if (!dragging && !noEvent) {
|
||||||
|
this.events.triggerEvent("movestart");
|
||||||
|
}
|
||||||
|
|
||||||
if (centerChanged) {
|
if (centerChanged) {
|
||||||
if ((!zoomChanged) && (this.center)) {
|
if ((!zoomChanged) && (this.center)) {
|
||||||
@@ -1377,7 +1403,9 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// even if nothing was done, we want to notify of this
|
// even if nothing was done, we want to notify of this
|
||||||
if (!dragging) { this.events.triggerEvent("moveend"); }
|
if (!dragging && !noEvent) {
|
||||||
|
this.events.triggerEvent("moveend");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -726,7 +726,7 @@
|
|||||||
t.eq( ct, 3, "raiseLayer triggered changelayer the right # of times" );
|
t.eq( ct, 3, "raiseLayer triggered changelayer the right # of times" );
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_15_Map_setCenter(t) {
|
function test_15_Map_moveTo(t) {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
|
|
||||||
map = new OpenLayers.Map('map');
|
map = new OpenLayers.Map('map');
|
||||||
@@ -736,7 +736,7 @@
|
|||||||
{maxResolution: 'auto', maxExtent: new OpenLayers.Bounds(-10,-10,10,10)});
|
{maxResolution: 'auto', maxExtent: new OpenLayers.Bounds(-10,-10,10,10)});
|
||||||
map.addLayer(baseLayer);
|
map.addLayer(baseLayer);
|
||||||
var ll = new OpenLayers.LonLat(-100,-150);
|
var ll = new OpenLayers.LonLat(-100,-150);
|
||||||
map.setCenter(ll, 0);
|
map.moveTo(ll, 0);
|
||||||
t.ok(map.getCenter().equals(new OpenLayers.LonLat(0,0)), "safely sets out-of-bounds lonlat");
|
t.ok(map.getCenter().equals(new OpenLayers.LonLat(0,0)), "safely sets out-of-bounds lonlat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user