Add click event as responsive alternative to singleclick
The singleclick event makes the application feel slow because of the 250 ms delay that is used to rule out a dblclick.
This commit is contained in:
@@ -149,6 +149,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
||||
displayFeatureInfo(pixel);
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
displayFeatureInfo(evt.pixel);
|
||||
});
|
||||
|
||||
@@ -146,6 +146,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
||||
displayFeatureInfo(pixel);
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
displayFeatureInfo(evt.pixel);
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ var map = new ol.Map({
|
||||
view: view
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
document.getElementById('info').innerHTML = '';
|
||||
var viewResolution = /** @type {number} */ (view.getResolution());
|
||||
var url = wmsSource.getGetFeatureInfoUrl(
|
||||
|
||||
@@ -87,6 +87,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
||||
displayFeatureInfo(pixel);
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
displayFeatureInfo(evt.pixel);
|
||||
});
|
||||
|
||||
@@ -64,7 +64,7 @@ var popup = new ol.Overlay({
|
||||
map.addOverlay(popup);
|
||||
|
||||
// display popup on click
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
var feature = map.forEachFeatureAtPixel(evt.pixel,
|
||||
function(feature, layer) {
|
||||
return feature;
|
||||
|
||||
@@ -126,7 +126,7 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
||||
displaySnap(coordinate);
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
displaySnap(evt.coordinate);
|
||||
});
|
||||
|
||||
|
||||
@@ -86,6 +86,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
||||
displayFeatureInfo(pixel);
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
displayFeatureInfo(evt.pixel);
|
||||
});
|
||||
|
||||
@@ -89,6 +89,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
||||
displayFeatureInfo(map.getEventPixel(evt.originalEvent));
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
displayFeatureInfo(evt.pixel);
|
||||
});
|
||||
|
||||
@@ -96,6 +96,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
||||
displayFeatureInfo(map.getEventPixel(evt.originalEvent));
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
displayFeatureInfo(evt.pixel);
|
||||
});
|
||||
|
||||
@@ -53,6 +53,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
||||
displayFeatureInfo(pixel);
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
displayFeatureInfo(evt.pixel);
|
||||
});
|
||||
|
||||
@@ -45,7 +45,7 @@ var popup = new ol.Overlay({
|
||||
});
|
||||
map.addOverlay(popup);
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
var element = popup.getElement();
|
||||
var coordinate = evt.coordinate;
|
||||
var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
|
||||
|
||||
@@ -60,7 +60,7 @@ var map = new ol.Map({
|
||||
/**
|
||||
* 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 hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
|
||||
coordinate, 'EPSG:3857', 'EPSG:4326'));
|
||||
|
||||
@@ -95,7 +95,7 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
||||
displaySnap(coordinate);
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
displaySnap(evt.coordinate);
|
||||
});
|
||||
|
||||
|
||||
@@ -123,6 +123,6 @@ $(map.getViewport()).on('mousemove', function(evt) {
|
||||
displayFeatureInfo(pixel);
|
||||
});
|
||||
|
||||
map.on('singleclick', function(evt) {
|
||||
map.on('click', function(evt) {
|
||||
displayFeatureInfo(evt.pixel);
|
||||
});
|
||||
|
||||
@@ -248,11 +248,15 @@ ol.MapBrowserEventHandler.prototype.emulateClickLegacyIE_ =
|
||||
* @private
|
||||
*/
|
||||
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) {
|
||||
// double-click
|
||||
goog.global.clearTimeout(this.clickTimeoutId_);
|
||||
this.clickTimeoutId_ = 0;
|
||||
var newEvent = new ol.MapBrowserPointerEvent(
|
||||
newEvent = new ol.MapBrowserPointerEvent(
|
||||
ol.MapBrowserEvent.EventType.DBLCLICK, this.map_, pointerEvent);
|
||||
this.dispatchEvent(newEvent);
|
||||
} else {
|
||||
@@ -470,6 +474,12 @@ ol.MapBrowserEvent.EventType = {
|
||||
* @todo stability experimental
|
||||
*/
|
||||
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.
|
||||
* @event ol.MapBrowserEvent#dblclick
|
||||
|
||||
@@ -54,12 +54,13 @@ describe('ol.MapBrowserEventHandler', function() {
|
||||
});
|
||||
|
||||
it('emulates dblclick', function() {
|
||||
handler.emulateClick_({
|
||||
handler.emulateClick_(new ol.pointer.PointerEvent('pointerdown',
|
||||
new goog.events.BrowserEvent({
|
||||
type: 'mousedown',
|
||||
target: target,
|
||||
clientX: 0,
|
||||
clientY: 0
|
||||
});
|
||||
})));
|
||||
expect(singleclickSpy.called).to.not.be.ok();
|
||||
expect(dblclickSpy.called).to.not.be.ok();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user