Skip to content

Commit

Permalink
Remap Safari gesture events to wheel events - #5492
Browse files Browse the repository at this point in the history
(still needs some more testing)
  • Loading branch information
bhousel committed Nov 17, 2018
1 parent f61c482 commit b7e218a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
32 changes: 31 additions & 1 deletion modules/renderer/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,45 @@ export function rendererMap(context) {
.selectAll('.surface')
.attr('id', 'surface');


var prevScale;

surface
.call(drawLabels.observe)
.on('gesturestart.surface', function() {
prevScale = d3_event.scale;
})
.on('gesturechange.surface', function() {
// Remap Safari gesture events to wheel events - #5492
// We want these disabled most places, but enabled for zoom/unzoom on map surface
// https://developer.mozilla.org/en-US/docs/Web/API/GestureEvent
var e = d3_event;
e.preventDefault();

var deltaY = (e.scale > prevScale) ? -15 : 20;
prevScale = e.scale;

var props = {
deltaY: deltaY ,
clientX: e.clientX,
clientY: e.clientY,
screenX: e.screenX,
screenY: e.screenY,
x: e.x,
y: e.y
};
var e2 = new WheelEvent('wheel', props);
_selection.node().dispatchEvent(e2);
})
.on('mousedown.zoom', function() {
if (d3_event.button === 2) {
d3_event.stopPropagation();
}
}, true)
.on('mouseup.zoom', function() {
if (resetTransform()) immediateRedraw();
if (resetTransform()) {
immediateRedraw();
}
})
.on('mousemove.map', function() {
mousemove = d3_event;
Expand Down
8 changes: 7 additions & 1 deletion modules/ui/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,14 @@ export function uiInit(context) {
window.onbeforeunload = function() {
return context.save();
};

window.onunload = function() {
context.history().unlock();
};

d3_select(window)
.on('gesturestart.editor', eventCancel)
.on('gesturechange.editor', eventCancel)
.on('gestureend.editor', eventCancel)
.on('resize.editor', ui.onResize);


Expand Down Expand Up @@ -349,6 +351,10 @@ export function uiInit(context) {
context.pan(d, 100);
};
}

function eventCancel() {
d3_event.preventDefault();
}
}


Expand Down

0 comments on commit b7e218a

Please sign in to comment.