Revert "Replace the navigation control by two controls, namely DragPan and MouseWheelZoom. DragPan is the map default drag control. MouseWheelZoom is the map default mouse wheel control."

This reverts commit c2a30f4ac4.
This commit is contained in:
Éric Lemoine
2012-07-13 15:37:39 +02:00
parent dd5182c55c
commit f34aa03109
9 changed files with 96 additions and 108 deletions

View File

@@ -2,8 +2,7 @@ goog.provide("ol");
goog.require('ol.base');
goog.require('ol.bounds');
goog.require('ol.control.DragPan');
goog.require('ol.control.MouseWheelZoom');
goog.require('ol.control.Navigation');
goog.require('ol.control.Attribution');
goog.require('ol.control.Zoom');
goog.require('ol.handler.Drag');

View File

@@ -91,15 +91,9 @@ ol.Map = function() {
/**
* @private
* @type {ol.control.Control}
* @type {ol.control.DefaultControl}
*/
this.defaultDragControl_ = null;
/**
* @private
* @type {ol.control.Control}
*/
this.defaultMouseWheelControl_ = null;
this.defaultControl_ = null;
/**
* @private
@@ -169,7 +163,7 @@ ol.Map.DEFAULT_TILE_SIZE = 256;
@const
@type {Array.<string>}
*/
ol.Map.CONTROLS = ["dragpan", "mousewheelzoom", "attribution", "zoom"];
ol.Map.CONTROLS = ["navigation", "attribution", "zoom"];
/**
* @return {ol.Loc} Map center in map projection.
@@ -456,35 +450,17 @@ ol.Map.prototype.addLayers = function(layers) {
/**
* @param {ol.control.Control} control
* @returns {ol.control.DefaultControl}
*/
ol.Map.prototype.setDefaultDragControl = function(control) {
this.defaultDragControl_ = control;
ol.Map.prototype.getDefaultControl = function() {
return this.defaultControl_;
};
/**
* @param {ol.events.MapEvent} e
* @param {ol.control.DefaultControl} control
*/
ol.Map.prototype.handleDragEvent = function(e) {
if (!goog.isNull(this.defaultDragControl_)) {
this.defaultDragControl_.handleEvent(e);
}
};
/**
* @param {ol.control.Control} control
*/
ol.Map.prototype.setDefaultMouseWheelControl = function(control) {
this.defaultMouseWheelControl_ = control;
};
/**
* @param {ol.events.MapEvent} e
*/
ol.Map.prototype.handleMouseWheelEvent = function(e) {
if (!goog.isNull(this.defaultMouseWheelControl_)) {
this.defaultMouseWheelControl_.handleEvent(e);
}
ol.Map.prototype.setDefaultControl = function(control) {
this.defaultControl_ = control;
};
/**

View File

@@ -0,0 +1,50 @@
goog.provide('ol.control.DefaultControl');
goog.require('ol.control.Control');
/**
* @constructor
* @extends {ol.control.Control}
* @param {boolean|undefined} opt_autoActivate
*/
ol.control.DefaultControl = function(opt_autoActivate) {
goog.base(this, opt_autoActivate);
/**
* Activate this control when it is added to a map. Default is true.
*
* @type {boolean} autoActivate
*/
this.autoActivate_ =
goog.isDef(opt_autoActivate) ? opt_autoActivate : true;
};
goog.inherits(ol.control.DefaultControl, ol.control.Control);
/** @inheritDoc */
ol.control.DefaultControl.prototype.activate = function() {
var active = goog.base(this, 'activate');
if (active) {
this.map_.setDefaultControl(this);
}
return active;
};
/** @inheritDoc */
ol.control.DefaultControl.prototype.deactivate = function() {
var inactive = goog.base(this, 'deactivate');
if (inactive) {
this.map_.setDefaultControl(null);
}
return inactive;
};
/**
* @param {ol.events.MapEvent} e
*/
ol.control.DefaultControl.prototype.defaultDrag = function(e) {};
/**
* @param {ol.events.MapEvent} e
*/
ol.control.DefaultControl.prototype.defaultMouseWheel = function(e) {};

View File

@@ -1,41 +0,0 @@
/**
* @fileoverview Drag Pan Control.
*
* This control registers itself in the map as the default drag control.
*/
goog.provide('ol.control.DragPan');
goog.require('ol.control.Control');
/**
* @constructor
* @extends {ol.control.Control}
* @param {boolean|undefined} opt_autoActivate
*/
ol.control.DragPan = function(opt_autoActivate) {
goog.base(this, opt_autoActivate);
};
goog.inherits(ol.control.DragPan, ol.control.Control);
/**
* @param {ol.Map} map
*/
ol.control.DragPan.prototype.setMap = function(map) {
goog.base(this, 'setMap', map);
this.map_.setDefaultDragControl(this);
};
/**
* @param {ol.events.MapEvent} e
*/
ol.control.DragPan.prototype.handleEvent = function(e) {
// FIXME do we want to test ENABLE_DRAG_HANDLER here?
if (ol.ENABLE_DRAG_HANDLER) {
var deltaX = /** @type {number} */ e.deltaX;
var deltaY = /** @type {number} */ e.deltaY;
this.map_.moveByViewportPx(deltaX, deltaY);
}
};
ol.control.addControl('dragpan', ol.control.DragPan);

View File

@@ -1,36 +1,34 @@
/**
* @fileoverview Mouse Wheel Zoom Control.
*
* This control registers itself in the map as the default mouse wheel control.
*/
goog.provide('ol.control.Navigation');
goog.provide('ol.control.MouseWheelZoom');
goog.require('ol.control.Control');
goog.require('ol.control.DefaultControl');
goog.require('ol.Map');
/**
* @constructor
* @extends {ol.control.Control}
* @extends {ol.control.DefaultControl}
* @param {boolean|undefined} opt_autoActivate
*/
ol.control.MouseWheelZoom = function(opt_autoActivate) {
ol.control.Navigation = function(opt_autoActivate) {
goog.base(this, opt_autoActivate);
};
goog.inherits(ol.control.MouseWheelZoom, ol.control.Control);
goog.inherits(ol.control.Navigation, ol.control.DefaultControl);
/**
* @param {ol.Map} map
* @inheritDoc
*/
ol.control.MouseWheelZoom.prototype.setMap = function(map) {
goog.base(this, 'setMap', map);
this.map_.setDefaultMouseWheelControl(this);
ol.control.Navigation.prototype.defaultDrag = function(e) {
if (ol.ENABLE_DRAG_HANDLER) {
var deltaX = /** @type {number} */ e.deltaX;
var deltaY = /** @type {number} */ e.deltaY;
this.map_.moveByViewportPx(deltaX, deltaY);
}
};
/**
* @param {ol.events.MapEvent} e
* @inheritDoc
*/
ol.control.MouseWheelZoom.prototype.handleEvent = function(e) {
// FIXME do we want to test ENABLE_DRAG_HANDLER here?
ol.control.Navigation.prototype.defaultMouseWheel = function(e) {
if (ol.ENABLE_MOUSEWHEEL_HANDLER) {
var me = this,
originalE = e.originalEvent;
@@ -53,4 +51,4 @@ ol.control.MouseWheelZoom.prototype.handleEvent = function(e) {
}
};
ol.control.addControl('mousewheelzoom', ol.control.MouseWheelZoom);
ol.control.addControl('navigation', ol.control.Navigation);

View File

@@ -4,8 +4,7 @@
* Provides a class for listening to drag sequences on a DOM element and
* dispatching dragstart, drag and dragend events to a map object.
*
* Calls handleDragEvent on the map if default is not prevented by
* listeners.
* The default behavior for the drag event is moving the map.
*/
goog.provide('ol.handler.Drag');
@@ -102,7 +101,10 @@ ol.handler.Drag.prototype.handleDrag = function(e) {
this.prevY_ = e.clientY;
var rt = goog.events.dispatchEvent(this.map_, newE);
if (rt) {
this.map_.handleDragEvent(newE);
var defaultControl = this.map_.getDefaultControl();
if (defaultControl) {
defaultControl.defaultDrag(newE);
}
}
};

View File

@@ -4,8 +4,7 @@
* Provides a class for listening to mousewheel events on a DOM element
* and dispatching mousewheel events to a map instance.
*
* Calls handleMouseWheelEvent on the map if default is not prevented by
* listeners.
* The default behavior for the mousewheel event is zooming the map.
*/
goog.provide('ol.handler.MouseWheel');
@@ -48,6 +47,9 @@ ol.handler.MouseWheel.prototype.handleMouseWheel = function(e) {
var newE = new ol.events.MapEvent(ol.events.MapEventType.MOUSEWHEEL, e);
var rt = goog.events.dispatchEvent(this.map_, newE);
if (rt) {
this.map_.handleMouseWheelEvent(newE);
var defaultControl = this.map_.getDefaultControl();
if (defaultControl) {
defaultControl.defaultMouseWheel(newE);
}
}
};
};

View File

@@ -61,12 +61,13 @@ describe('ol.handler.Drag', function() {
});
it('calls the default action on the default control', function() {
var control = {handleEvent: jasmine.createSpy()};
map.setDefaultDragControl(control);
var control = new ol.control.DefaultControl();
spyOn(control, 'defaultDrag');
map.setDefaultControl(control);
var handler = new ol.handler.Drag(map, {});
handler.dragger_.dispatchEvent({type: 'drag'});
expect(control.handleEvent).toHaveBeenCalled();
expect(control.defaultDrag).toHaveBeenCalled();
});
});
});

View File

@@ -32,12 +32,13 @@ describe('ol.handler.MouseWheel', function() {
});
it('calls the default action on the default control', function() {
var control = {handleEvent: jasmine.createSpy()};
map.setDefaultMouseWheelControl(control);
var control = new ol.control.DefaultControl();
spyOn(control, 'defaultMouseWheel');
map.setDefaultControl(control);
var handler = new ol.handler.MouseWheel(map, {});
handler.handleMouseWheel(new goog.events.MouseWheelEvent(1, 'foo', 0, 1));
expect(control.handleEvent).toHaveBeenCalled();
expect(control.defaultMouseWheel).toHaveBeenCalled();
});
});