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);
|
displayFeatureInfo(pixel);
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
displayFeatureInfo(evt.pixel);
|
displayFeatureInfo(evt.pixel);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -146,6 +146,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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ var map = new ol.Map({
|
|||||||
view: view
|
view: view
|
||||||
});
|
});
|
||||||
|
|
||||||
map.on('singleclick', function(evt) {
|
map.on('click', function(evt) {
|
||||||
document.getElementById('info').innerHTML = '';
|
document.getElementById('info').innerHTML = '';
|
||||||
var viewResolution = /** @type {number} */ (view.getResolution());
|
var viewResolution = /** @type {number} */ (view.getResolution());
|
||||||
var url = wmsSource.getGetFeatureInfoUrl(
|
var url = wmsSource.getGetFeatureInfoUrl(
|
||||||
|
|||||||
@@ -87,6 +87,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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -64,7 +64,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;
|
||||||
|
|||||||
@@ -126,7 +126,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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -89,6 +89,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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -96,6 +96,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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -53,6 +53,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);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
@@ -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'));
|
||||||
|
|||||||
@@ -95,7 +95,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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,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
|
||||||
|
|||||||
@@ -54,12 +54,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