make ol.Map inherit from goog.EventTarget, and add an ol.handler.Drag

This commit is contained in:
Éric Lemoine
2012-06-28 22:33:29 +02:00
parent d8e8e55b44
commit 946cd33350
5 changed files with 91 additions and 113 deletions

63
src/ol/handler/Drag.js Normal file
View File

@@ -0,0 +1,63 @@
goog.provide('ol.handler.Drag');
goog.require('goog.fx.Dragger');
goog.require('goog.events');
goog.require('goog.Disposable');
/**
* @constructor
* @extends {goog.Disposable}
* @param {ol.Map} map The map instance.
* @param {Element} elt The element that will be dragged.
*/
ol.handler.Drag = function(map, elt) {
this.dragger_ = new goog.fx.Dragger(elt);
this.dragger_.defaultAction = function() {};
var prevX = 0, prevY = 0;
var handleDragStart = function(e) {
prevX = e.clientX;
prevY = e.clientY;
var newE = {
type: 'dragstart'
};
goog.events.dispatchEvent(map, newE);
};
var handleDrag = function(e) {
var newE = {
type: 'drag',
deltaX: e.clientX - prevX,
deltaY: e.clientY - prevY
};
prevX = e.clientX;
prevY = e.clientY;
goog.events.dispatchEvent(map, newE);
};
var handleDragEnd = function(e) {
var newE = {
type: 'dragend'
};
goog.events.dispatchEvent(map, newE);
};
goog.events.listen(this.dragger_, goog.fx.Dragger.EventType.START,
handleDragStart, false, this);
goog.events.listen(this.dragger_, goog.fx.Dragger.EventType.DRAG,
handleDrag, false, this);
goog.events.listen(this.dragger_, goog.fx.Dragger.EventType.END,
handleDragEnd, false, this);
};
goog.inherits(ol.handler.Drag, goog.Disposable);
/**
* @inheritDoc
*/
ol.handler.Drag.prototype.disposeInternal = function() {
goog.base(this, 'disposeInternal');
this.dragger_.dispose();
delete this.dragger_;
};