Skip to content

Commit af3265f

Browse files
clairethompsonLauren Budorick
authored andcommitted
Double click zooms the map instead of placing pins for directions
Add a new click handler to deal with delegating to the single click or the double click.
1 parent 9e5d0a1 commit af3265f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/directions.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default class MapboxDirections {
5656
this.onDragMove = this._onDragMove.bind(this);
5757
this.onDragUp = this._onDragUp.bind(this);
5858
this.move = this._move.bind(this);
59-
this.onClick = this._onClick.bind(this);
59+
this.onClick = this._clickHandler().bind(this);
6060
}
6161

6262
onAdd(map) {
@@ -231,7 +231,27 @@ export default class MapboxDirections {
231231
});
232232
}
233233

234-
_onClick(e) {
234+
_clickHandler() {
235+
var timer = null;
236+
var delay = 250;
237+
return function(event) {
238+
if (!timer) {
239+
var singleClickHandler = this._onSingleClick.bind(this);
240+
241+
timer = setTimeout(function() {
242+
singleClickHandler(event);
243+
timer = null;
244+
}, delay);
245+
246+
} else {
247+
clearTimeout(timer);
248+
timer = null;
249+
this._map.zoomIn();
250+
}
251+
};
252+
}
253+
254+
_onSingleClick(e) {
235255
const { origin } = store.getState();
236256
const coords = [e.lngLat.lng, e.lngLat.lat];
237257

0 commit comments

Comments
 (0)