add a click handler
This commit is contained in:
@@ -7,6 +7,7 @@ goog.require('ol.control.Control');
|
|||||||
goog.require('ol.renderer.MapRenderer');
|
goog.require('ol.renderer.MapRenderer');
|
||||||
goog.require('ol.handler.Drag');
|
goog.require('ol.handler.Drag');
|
||||||
goog.require('ol.handler.MouseWheel');
|
goog.require('ol.handler.MouseWheel');
|
||||||
|
goog.require('ol.handler.Click');
|
||||||
|
|
||||||
goog.require('goog.dom');
|
goog.require('goog.dom');
|
||||||
goog.require('goog.math');
|
goog.require('goog.math');
|
||||||
@@ -23,6 +24,11 @@ ol.ENABLE_DRAG_HANDLER = true;
|
|||||||
*/
|
*/
|
||||||
ol.ENABLE_MOUSEWHEEL_HANDLER = true;
|
ol.ENABLE_MOUSEWHEEL_HANDLER = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @define {boolean} Whether to enable the click handler.
|
||||||
|
*/
|
||||||
|
ol.ENABLE_CLICK_HANDLER = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @export
|
* @export
|
||||||
* @constructor
|
* @constructor
|
||||||
@@ -529,6 +535,10 @@ ol.Map.prototype.initHandlers = function() {
|
|||||||
handler = new ol.handler.MouseWheel(this, this.viewport_, states);
|
handler = new ol.handler.MouseWheel(this, this.viewport_, states);
|
||||||
this.registerDisposable(handler);
|
this.registerDisposable(handler);
|
||||||
}
|
}
|
||||||
|
if (ol.ENABLE_CLICK_HANDLER) {
|
||||||
|
handler = new ol.handler.Click(this, this.viewport_, states);
|
||||||
|
this.registerDisposable(handler);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ol.Map.prototype.createRenderer = function() {
|
ol.Map.prototype.createRenderer = function() {
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/**
|
||||||
|
* @fileoverview Click Handler.
|
||||||
|
*
|
||||||
|
* Provides a class for listening to click events on a DOM element
|
||||||
|
* and re-dispatching to a map instance.
|
||||||
|
*
|
||||||
|
* This handler has no default behaviour.
|
||||||
|
*/
|
||||||
|
|
||||||
|
goog.provide('ol.handler.Click');
|
||||||
|
|
||||||
|
goog.require('goog.asserts');
|
||||||
|
goog.require('goog.events');
|
||||||
|
goog.require('goog.events.EventType');
|
||||||
|
goog.require('goog.Disposable');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @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.Click = function(map, elt, states) {
|
||||||
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.Map}
|
||||||
|
*/
|
||||||
|
this.map_ = map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Element}
|
||||||
|
*/
|
||||||
|
this.elt_ = elt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Object}
|
||||||
|
*/
|
||||||
|
this.states_ = states;
|
||||||
|
|
||||||
|
goog.events.listen(this.elt_, goog.events.EventType.CLICK,
|
||||||
|
this.handleClick, undefined, this);
|
||||||
|
};
|
||||||
|
goog.inherits(ol.handler.Click, goog.Disposable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.handler.Click.prototype.disposeInternal = function() {
|
||||||
|
goog.events.unlisten(this.elt_, goog.events.EventType.CLICK,
|
||||||
|
this.handleClick, undefined, this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {goog.events.BrowserEvent} e
|
||||||
|
*/
|
||||||
|
ol.handler.Click.prototype.handleClick = function(e) {
|
||||||
|
if (!this.states_.dragged) {
|
||||||
|
goog.events.dispatchEvent(this.map_, e);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -89,6 +89,7 @@
|
|||||||
<script type="text/javascript" src="spec/ol/geom/Collection.test.js"></script>
|
<script type="text/javascript" src="spec/ol/geom/Collection.test.js"></script>
|
||||||
<script type="text/javascript" src="spec/ol/handler/Drag.test.js"></script>
|
<script type="text/javascript" src="spec/ol/handler/Drag.test.js"></script>
|
||||||
<script type="text/javascript" src="spec/ol/handler/MouseWheel.test.js"></script>
|
<script type="text/javascript" src="spec/ol/handler/MouseWheel.test.js"></script>
|
||||||
|
<script type="text/javascript" src="spec/ol/handler/Click.test.js"></script>
|
||||||
<script type="text/javascript" src="spec/ol/layer/TileLayer.test.js"></script>
|
<script type="text/javascript" src="spec/ol/layer/TileLayer.test.js"></script>
|
||||||
<script type="text/javascript" src="spec/ol/layer/XYZ.test.js"></script>
|
<script type="text/javascript" src="spec/ol/layer/XYZ.test.js"></script>
|
||||||
<script type="text/javascript" src="spec/ol/layer/WMS.test.js"></script>
|
<script type="text/javascript" src="spec/ol/layer/WMS.test.js"></script>
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
describe('ol.handler.Click', function() {
|
||||||
|
var map, elt;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
map = new ol.Map();
|
||||||
|
elt = goog.dom.createDom('div');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('create a drag handler', function() {
|
||||||
|
|
||||||
|
it('returns an ol.handler.Click instance', function() {
|
||||||
|
var handler = new ol.handler.Click(map, elt, {});
|
||||||
|
expect(handler).toBeA(ol.handler.Click);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user