Merge pull request #1896 from ahocevar/nodragclick
Add click event as responsive alternative to singleclick
This commit is contained in:
@@ -149,6 +149,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
|||||||
displayFeatureInfo(pixel);
|
displayFeatureInfo(pixel);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
displayFeatureInfo(evt.pixel);
|
displayFeatureInfo(evt.pixel);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -145,6 +145,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
|||||||
displayFeatureInfo(pixel);
|
displayFeatureInfo(pixel);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
displayFeatureInfo(evt.pixel);
|
displayFeatureInfo(evt.pixel);
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -86,6 +86,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
|||||||
displayFeatureInfo(pixel);
|
displayFeatureInfo(pixel);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
displayFeatureInfo(evt.pixel);
|
displayFeatureInfo(evt.pixel);
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -63,7 +63,7 @@ var popup = new ol.Overlay({
|
|||||||
map.addOverlay(popup);
|
map.addOverlay(popup);
|
||||||
|
|
||||||
// display popup on click
|
// display popup on click
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
var feature = map.forEachFeatureAtPixel(evt.pixel,
|
var feature = map.forEachFeatureAtPixel(evt.pixel,
|
||||||
function(feature, layer) {
|
function(feature, layer) {
|
||||||
return feature;
|
return feature;
|
||||||
|
|||||||
+1
-1
@@ -125,7 +125,7 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
|||||||
displaySnap(coordinate);
|
displaySnap(coordinate);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
displaySnap(evt.coordinate);
|
displaySnap(evt.coordinate);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
|||||||
displayFeatureInfo(pixel);
|
displayFeatureInfo(pixel);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
displayFeatureInfo(evt.pixel);
|
displayFeatureInfo(evt.pixel);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -88,6 +88,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
|||||||
displayFeatureInfo(map.getEventPixel(evt.originalEvent));
|
displayFeatureInfo(map.getEventPixel(evt.originalEvent));
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
displayFeatureInfo(evt.pixel);
|
displayFeatureInfo(evt.pixel);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -95,6 +95,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
|||||||
displayFeatureInfo(map.getEventPixel(evt.originalEvent));
|
displayFeatureInfo(map.getEventPixel(evt.originalEvent));
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
displayFeatureInfo(evt.pixel);
|
displayFeatureInfo(evt.pixel);
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -52,6 +52,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
|||||||
displayFeatureInfo(pixel);
|
displayFeatureInfo(pixel);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
displayFeatureInfo(evt.pixel);
|
displayFeatureInfo(evt.pixel);
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -45,7 +45,7 @@ var popup = new ol.Overlay({
|
|||||||
});
|
});
|
||||||
map.addOverlay(popup);
|
map.addOverlay(popup);
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
var element = popup.getElement();
|
var element = popup.getElement();
|
||||||
var coordinate = evt.coordinate;
|
var coordinate = evt.coordinate;
|
||||||
var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
|
var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
|
||||||
|
|||||||
+1
-1
@@ -60,7 +60,7 @@ var map = new ol.Map({
|
|||||||
/**
|
/**
|
||||||
* Add a click handler to the map to render the popup.
|
* Add a click handler to the map to render the popup.
|
||||||
*/
|
*/
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
var coordinate = evt.coordinate;
|
var coordinate = evt.coordinate;
|
||||||
var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
|
var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
|
||||||
coordinate, 'EPSG:3857', 'EPSG:4326'));
|
coordinate, 'EPSG:3857', 'EPSG:4326'));
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
|||||||
displaySnap(coordinate);
|
displaySnap(coordinate);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
displaySnap(evt.coordinate);
|
displaySnap(evt.coordinate);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -122,6 +122,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
|||||||
displayFeatureInfo(pixel);
|
displayFeatureInfo(pixel);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
displayFeatureInfo(evt.pixel);
|
displayFeatureInfo(evt.pixel);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -248,11 +248,15 @@ ol.MapBrowserEventHandler.prototype.emulateClickLegacyIE_ =
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.MapBrowserEventHandler.prototype.emulateClick_ = function(pointerEvent) {
|
ol.MapBrowserEventHandler.prototype.emulateClick_ = function(pointerEvent) {
|
||||||
|
var newEvent;
|
||||||
|
newEvent = new ol.MapBrowserPointerEvent(
|
||||||
|
ol.MapBrowserEvent.EventType.CLICK, this.map_, pointerEvent);
|
||||||
|
this.dispatchEvent(newEvent);
|
||||||
if (this.clickTimeoutId_ !== 0) {
|
if (this.clickTimeoutId_ !== 0) {
|
||||||
// double-click
|
// double-click
|
||||||
goog.global.clearTimeout(this.clickTimeoutId_);
|
goog.global.clearTimeout(this.clickTimeoutId_);
|
||||||
this.clickTimeoutId_ = 0;
|
this.clickTimeoutId_ = 0;
|
||||||
var newEvent = new ol.MapBrowserPointerEvent(
|
newEvent = new ol.MapBrowserPointerEvent(
|
||||||
ol.MapBrowserEvent.EventType.DBLCLICK, this.map_, pointerEvent);
|
ol.MapBrowserEvent.EventType.DBLCLICK, this.map_, pointerEvent);
|
||||||
this.dispatchEvent(newEvent);
|
this.dispatchEvent(newEvent);
|
||||||
} else {
|
} else {
|
||||||
@@ -470,6 +474,12 @@ ol.MapBrowserEvent.EventType = {
|
|||||||
* @todo stability experimental
|
* @todo stability experimental
|
||||||
*/
|
*/
|
||||||
SINGLECLICK: 'singleclick',
|
SINGLECLICK: 'singleclick',
|
||||||
|
/**
|
||||||
|
* A click with no dragging. A double click will fire two of this.
|
||||||
|
* @event ol.MapBrowserEvent#click
|
||||||
|
* @todo stability experimental
|
||||||
|
*/
|
||||||
|
CLICK: goog.events.EventType.CLICK,
|
||||||
/**
|
/**
|
||||||
* A true double click, with no dragging.
|
* A true double click, with no dragging.
|
||||||
* @event ol.MapBrowserEvent#dblclick
|
* @event ol.MapBrowserEvent#dblclick
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ describe('ol.MapBrowserEventHandler', function() {
|
|||||||
describe('#emulateClick_', function() {
|
describe('#emulateClick_', function() {
|
||||||
var clock;
|
var clock;
|
||||||
var handler;
|
var handler;
|
||||||
|
var clickSpy;
|
||||||
var singleclickSpy;
|
var singleclickSpy;
|
||||||
var dblclickSpy;
|
var dblclickSpy;
|
||||||
var target;
|
var target;
|
||||||
@@ -15,6 +16,9 @@ describe('ol.MapBrowserEventHandler', function() {
|
|||||||
target: target
|
target: target
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
clickSpy = sinon.spy();
|
||||||
|
goog.events.listen(handler, 'click', clickSpy);
|
||||||
|
|
||||||
singleclickSpy = sinon.spy();
|
singleclickSpy = sinon.spy();
|
||||||
goog.events.listen(handler, 'singleclick', singleclickSpy);
|
goog.events.listen(handler, 'singleclick', singleclickSpy);
|
||||||
|
|
||||||
@@ -28,6 +32,17 @@ describe('ol.MapBrowserEventHandler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('emulates click', function() {
|
it('emulates click', function() {
|
||||||
|
handler.emulateClick_(new ol.pointer.PointerEvent('pointerdown',
|
||||||
|
new goog.events.BrowserEvent({
|
||||||
|
type: 'mousedown',
|
||||||
|
target: target,
|
||||||
|
clientX: 0,
|
||||||
|
clientY: 0
|
||||||
|
})));
|
||||||
|
expect(clickSpy.called).to.be.ok();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('emulates singleclick', function() {
|
||||||
handler.emulateClick_(new ol.pointer.PointerEvent('pointerdown',
|
handler.emulateClick_(new ol.pointer.PointerEvent('pointerdown',
|
||||||
new goog.events.BrowserEvent({
|
new goog.events.BrowserEvent({
|
||||||
type: 'mousedown',
|
type: 'mousedown',
|
||||||
@@ -54,12 +69,13 @@ describe('ol.MapBrowserEventHandler', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('emulates dblclick', function() {
|
it('emulates dblclick', function() {
|
||||||
handler.emulateClick_({
|
handler.emulateClick_(new ol.pointer.PointerEvent('pointerdown',
|
||||||
type: 'mousedown',
|
new goog.events.BrowserEvent({
|
||||||
target: target,
|
type: 'mousedown',
|
||||||
clientX: 0,
|
target: target,
|
||||||
clientY: 0
|
clientX: 0,
|
||||||
});
|
clientY: 0
|
||||||
|
})));
|
||||||
expect(singleclickSpy.called).to.not.be.ok();
|
expect(singleclickSpy.called).to.not.be.ok();
|
||||||
expect(dblclickSpy.called).to.not.be.ok();
|
expect(dblclickSpy.called).to.not.be.ok();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user