Skip to content

Commit f8fbca2

Browse files
committed
Fix zooming on some maps in Firefox
Some maps like OSM and ARCGIS use the deprecated DOMMouseScroll event on Firefox.
1 parent 7bf39b0 commit f8fbca2

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

gulpfile.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class BuildContext {
8282
}
8383

8484
copyImages() {
85-
return src(['images/**/*.png'])
85+
return src(['images/**/*.png'], { encoding: false })
8686
.pipe(newer(`${this.pluginDir()}/images`))
8787
.pipe(dest(`${this.pluginDir()}/images`))
8888
}
@@ -202,7 +202,7 @@ class BuildContext {
202202
}
203203

204204
zipExtension() {
205-
return src([this.pluginDir() + '/**'])
205+
return src([this.pluginDir() + '/**'], { encoding: false })
206206
.pipe(newer(`gen/scrollmaps-${this.version}-${this.browser}.zip`))
207207
.pipe(zip(`scrollmaps-${this.version}-${this.browser}.zip`))
208208
.pipe(dest('gen'));

src/ScrollableMap.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,31 @@ if (window.ScrollableMap === undefined) {
335335
}
336336

337337
const events = createBackdoorWheelEvents(originalEvent, isZoomIn, delta);
338-
for (const e of events) {
339-
target.dispatchEvent(e);
340-
target.dispatchEvent(new WheelEvent('mousewheel', e))
338+
for (const eventInit of events) {
339+
target.dispatchEvent(new WheelEvent('wheel', eventInit));
340+
target.dispatchEvent(new WheelEvent('mousewheel', {
341+
...eventInit,
342+
deltaY: eventInit.deltaY,
343+
detail: eventInit.deltaY,
344+
}));
345+
if (window.MouseScrollEvent) {
346+
// Very old and deprecated mouse scroll event used by Firefox.
347+
// OpenStreetMap still uses this event when it detects that the browser is Firefox.
348+
// https://developer.mozilla.org/en-US/docs/Web/API/Element/DOMMouseScroll_event
349+
const domMouseScrollEvent = new MouseEvent('DOMMouseScroll', {
350+
...eventInit,
351+
detail: eventInit.deltaY / 16,
352+
shiftKey: type === ScrollableMap.TYPE_ARCGIS,
353+
});
354+
target.dispatchEvent(domMouseScrollEvent);
355+
if (type === ScrollableMap.TYPE_ARCGIS) {
356+
target.dispatchEvent(new MouseEvent('MozMousePixelScroll', {
357+
...eventInit,
358+
detail: eventInit.deltaY / 16,
359+
shiftKey: true,
360+
}));
361+
}
362+
}
341363
}
342364
return;
343365
} else {
@@ -373,9 +395,9 @@ if (window.ScrollableMap === undefined) {
373395
// https://github.com/mapbox/mapbox-gl-js/blob/c708474eb65d9c6a117fe232b677db19525f70b4/src/ui/handler/scroll_zoom.js#L17-L22
374396
// Split the wheel event into many with small delta to make sure it's treated as trackpad
375397
const numEvents = Math.ceil(Math.abs(delta / 4));
376-
return Array(numEvents).fill(new WheelEvent('wheel', { ...init, deltaY: init.deltaY / numEvents }));
398+
return Array(numEvents).fill({ ...init, deltaY: init.deltaY / numEvents });
377399
} else {
378-
return [new WheelEvent('wheel', init)];
400+
return [init];
379401
}
380402
} else {
381403
console.log('Trying to create backdoor event out of non-wheel event', originalEvent);

0 commit comments

Comments
 (0)