add ol.ENABLE_DRAG_HANDLER and ol.ENABLE_MOUSEWHEEL_HANDLER @defines, and pass a an object to the handlers for sharing states
This commit is contained in:
@@ -13,6 +13,15 @@ goog.require('goog.math');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.events.EventTarget');
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable the drag handler.
|
||||
*/
|
||||
ol.ENABLE_DRAG_HANDLER = true;
|
||||
|
||||
/**
|
||||
* @define {boolean} Whether to enable the mousewheel handler.
|
||||
*/
|
||||
ol.ENABLE_MOUSEWHEEL_HANDLER = true;
|
||||
|
||||
/**
|
||||
* @export
|
||||
@@ -509,14 +518,19 @@ ol.Map.prototype.setViewport = function() {
|
||||
ol.Map.prototype.initHandlers = function() {
|
||||
goog.asserts.assert(!goog.isNull(this.viewport_));
|
||||
|
||||
var dragHandler = new ol.handler.Drag(this, this.viewport_);
|
||||
this.registerDisposable(dragHandler);
|
||||
var handler,
|
||||
states = {};
|
||||
|
||||
var mouseWheelHandler = new ol.handler.MouseWheel(this, this.viewport_);
|
||||
this.registerDisposable(mouseWheelHandler);
|
||||
if (ol.ENABLE_DRAG_HANDLER) {
|
||||
handler = new ol.handler.Drag(this, this.viewport_, states);
|
||||
this.registerDisposable(handler);
|
||||
}
|
||||
if (ol.ENABLE_MOUSEWHEEL_HANDLER) {
|
||||
handler = new ol.handler.MouseWheel(this, this.viewport_, states);
|
||||
this.registerDisposable(handler);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ol.Map.prototype.createRenderer = function() {
|
||||
var Renderer = ol.renderer.MapRenderer.pickRendererType(
|
||||
ol.Map.preferredRenderers);
|
||||
|
||||
@@ -19,8 +19,9 @@ goog.require('goog.fx.Dragger');
|
||||
* @extends {goog.Disposable}
|
||||
* @param {ol.Map} map The map instance.
|
||||
* @param {Element} elt The element that will be dragged.
|
||||
* @param {Object} states An object for the handlers to share states.
|
||||
*/
|
||||
ol.handler.Drag = function(map, elt) {
|
||||
ol.handler.Drag = function(map, elt, states) {
|
||||
|
||||
/** */
|
||||
this.map_ = map;
|
||||
@@ -28,8 +29,11 @@ ol.handler.Drag = function(map, elt) {
|
||||
/** */
|
||||
this.elt_ = elt;
|
||||
|
||||
/** */
|
||||
var dragger = this.dragger_ = new goog.fx.Dragger(elt);
|
||||
/**
|
||||
* @type {Object}
|
||||
*/
|
||||
this.states_ = states;
|
||||
|
||||
dragger.defaultAction = function() {};
|
||||
|
||||
/** */
|
||||
@@ -65,7 +69,7 @@ ol.handler.Drag.prototype.disposeInternal = function() {
|
||||
/**
|
||||
*/
|
||||
ol.handler.Drag.prototype.handleDragStart = function(e) {
|
||||
this.dragged_ = false;
|
||||
this.states_.dragged = false;
|
||||
this.prevX_ = e.clientX;
|
||||
this.prevY_ = e.clientY;
|
||||
var newE = {
|
||||
@@ -84,7 +88,7 @@ ol.handler.Drag.prototype.handleDragStart = function(e) {
|
||||
/**
|
||||
*/
|
||||
ol.handler.Drag.prototype.handleDrag = function(e) {
|
||||
this.dragged_ = true;
|
||||
this.states_.dragged = true;
|
||||
var newE = {
|
||||
type: 'drag',
|
||||
deltaX: e.clientX - this.prevX_,
|
||||
|
||||
@@ -18,8 +18,9 @@ goog.require('goog.events.MouseWheelHandler');
|
||||
* @extends {goog.Disposable}
|
||||
* @param {ol.Map} map The map instance.
|
||||
* @param {Element} elt The element we listen to mousewheel on.
|
||||
* @param {Object} states An object for the handlers to share states.
|
||||
*/
|
||||
ol.handler.MouseWheel = function(map, elt) {
|
||||
ol.handler.MouseWheel = function(map, elt, states) {
|
||||
goog.base(this);
|
||||
|
||||
var handler = new goog.events.MouseWheelHandler(elt);
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('ol.handler.Drag', function() {
|
||||
describe('create a drag handler', function() {
|
||||
|
||||
it('returns an ol.handler.Drag instance', function() {
|
||||
var handler = new ol.handler.Drag(map, elt);
|
||||
var handler = new ol.handler.Drag(map, elt, {});
|
||||
expect(handler).toBeA(ol.handler.Drag);
|
||||
});
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('ol.handler.MouseWheel', function() {
|
||||
describe('create a mouse wheel handler', function() {
|
||||
|
||||
it('returns an ol.handler.MouseWheel instance', function() {
|
||||
var handler = new ol.handler.MouseWheel(map, elt);
|
||||
var handler = new ol.handler.MouseWheel(map, elt, {});
|
||||
expect(handler).toBeA(ol.handler.MouseWheel);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user