mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-03-27 18:43:51 +03:00
Added a patch to help slow down the scroll devices that fire too fast. This new code reduces the number of 'canvas-scroll' events that fire and slows down the zoom process.
This commit is contained in:
parent
fb8e19b50d
commit
19c6179533
@ -255,6 +255,11 @@
|
|||||||
* @property {Boolean} [preserveImageSizeOnResize=false]
|
* @property {Boolean} [preserveImageSizeOnResize=false]
|
||||||
* Set to true to have the image size preserved when the viewer is resized. This requires autoResize=true (default).
|
* Set to true to have the image size preserved when the viewer is resized. This requires autoResize=true (default).
|
||||||
*
|
*
|
||||||
|
* @property {Number} [minScrollDelta=3]
|
||||||
|
* Number of milliseconds between canvas-scroll events. This value helps normalize the rate of canvas-scroll
|
||||||
|
* events between different devices, causing the faster devices to slow down enough to make the zoom control
|
||||||
|
* more manageable.
|
||||||
|
*
|
||||||
* @property {Number} [pixelsPerWheelLine=40]
|
* @property {Number} [pixelsPerWheelLine=40]
|
||||||
* For pixel-resolution scrolling devices, the number of pixels equal to one scroll line.
|
* For pixel-resolution scrolling devices, the number of pixels equal to one scroll line.
|
||||||
*
|
*
|
||||||
@ -1003,6 +1008,7 @@ if (typeof define === 'function' && define.amd) {
|
|||||||
pixelsPerWheelLine: 40,
|
pixelsPerWheelLine: 40,
|
||||||
autoResize: true,
|
autoResize: true,
|
||||||
preserveImageSizeOnResize: false, // requires autoResize=true
|
preserveImageSizeOnResize: false, // requires autoResize=true
|
||||||
|
minScrollDelta: 3,
|
||||||
|
|
||||||
//DEFAULT CONTROL SETTINGS
|
//DEFAULT CONTROL SETTINGS
|
||||||
showSequenceControl: true, //SEQUENCE
|
showSequenceControl: true, //SEQUENCE
|
||||||
|
@ -604,7 +604,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
var originalSuccess = options.success;
|
var originalSuccess = options.success;
|
||||||
options.success = function(event) {
|
options.success = function(event) {
|
||||||
successes++;
|
successes++;
|
||||||
|
|
||||||
// TODO: now that options has other things besides tileSource, the overlays
|
// TODO: now that options has other things besides tileSource, the overlays
|
||||||
// should probably be at the options level, not the tileSource level.
|
// should probably be at the options level, not the tileSource level.
|
||||||
if (options.tileSource.overlays) {
|
if (options.tileSource.overlays) {
|
||||||
@ -2735,42 +2735,54 @@ function onCanvasPinch( event ) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lastScroll = new Date().getTime();
|
||||||
function onCanvasScroll( event ) {
|
function onCanvasScroll( event ) {
|
||||||
var gestureSettings,
|
var gestureSettings,
|
||||||
factor;
|
factor,
|
||||||
|
thisScroll,
|
||||||
|
deltaScroll;
|
||||||
|
|
||||||
if ( !event.preventDefaultAction && this.viewport ) {
|
/* Certain scroll devices fire the scroll event way too fast so we are injecting a simple adjustment to keep things
|
||||||
gestureSettings = this.gestureSettingsByDeviceType( event.pointerType );
|
* partially normalized. If we have already fired an event within the last 'minScrollDelta' milliseconds we skip
|
||||||
if ( gestureSettings.scrollToZoom ) {
|
* this one and wait for the next event. */
|
||||||
factor = Math.pow( this.zoomPerScroll, event.scroll );
|
thisScroll = new Date().getTime();
|
||||||
this.viewport.zoomBy(
|
deltaScroll = thisScroll - lastScroll;
|
||||||
factor,
|
if (deltaScroll > this.minScrollDelta) {
|
||||||
this.viewport.pointFromPixel( event.position, true )
|
lastScroll = thisScroll;
|
||||||
);
|
|
||||||
this.viewport.applyConstraints();
|
if ( !event.preventDefaultAction && this.viewport ) {
|
||||||
|
gestureSettings = this.gestureSettingsByDeviceType( event.pointerType );
|
||||||
|
if ( gestureSettings.scrollToZoom ) {
|
||||||
|
factor = Math.pow( this.zoomPerScroll, event.scroll );
|
||||||
|
this.viewport.zoomBy(
|
||||||
|
factor,
|
||||||
|
this.viewport.pointFromPixel( event.position, true )
|
||||||
|
);
|
||||||
|
this.viewport.applyConstraints();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Raised when a scroll event occurs on the {@link OpenSeadragon.Viewer#canvas} element (mouse wheel).
|
||||||
|
*
|
||||||
|
* @event canvas-scroll
|
||||||
|
* @memberof OpenSeadragon.Viewer
|
||||||
|
* @type {object}
|
||||||
|
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
|
||||||
|
* @property {OpenSeadragon.MouseTracker} tracker - A reference to the MouseTracker which originated this event.
|
||||||
|
* @property {OpenSeadragon.Point} position - The position of the event relative to the tracked element.
|
||||||
|
* @property {Number} scroll - The scroll delta for the event.
|
||||||
|
* @property {Boolean} shift - True if the shift key was pressed during this event.
|
||||||
|
* @property {Object} originalEvent - The original DOM event.
|
||||||
|
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
||||||
|
*/
|
||||||
|
this.raiseEvent( 'canvas-scroll', {
|
||||||
|
tracker: event.eventSource,
|
||||||
|
position: event.position,
|
||||||
|
scroll: event.scroll,
|
||||||
|
shift: event.shift,
|
||||||
|
originalEvent: event.originalEvent
|
||||||
|
});
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Raised when a scroll event occurs on the {@link OpenSeadragon.Viewer#canvas} element (mouse wheel).
|
|
||||||
*
|
|
||||||
* @event canvas-scroll
|
|
||||||
* @memberof OpenSeadragon.Viewer
|
|
||||||
* @type {object}
|
|
||||||
* @property {OpenSeadragon.Viewer} eventSource - A reference to the Viewer which raised this event.
|
|
||||||
* @property {OpenSeadragon.MouseTracker} tracker - A reference to the MouseTracker which originated this event.
|
|
||||||
* @property {OpenSeadragon.Point} position - The position of the event relative to the tracked element.
|
|
||||||
* @property {Number} scroll - The scroll delta for the event.
|
|
||||||
* @property {Boolean} shift - True if the shift key was pressed during this event.
|
|
||||||
* @property {Object} originalEvent - The original DOM event.
|
|
||||||
* @property {?Object} userData - Arbitrary subscriber-defined object.
|
|
||||||
*/
|
|
||||||
this.raiseEvent( 'canvas-scroll', {
|
|
||||||
tracker: event.eventSource,
|
|
||||||
position: event.position,
|
|
||||||
scroll: event.scroll,
|
|
||||||
shift: event.shift,
|
|
||||||
originalEvent: event.originalEvent
|
|
||||||
});
|
|
||||||
|
|
||||||
if (gestureSettings && gestureSettings.scrollToZoom) {
|
if (gestureSettings && gestureSettings.scrollToZoom) {
|
||||||
//cancels event
|
//cancels event
|
||||||
|
Loading…
x
Reference in New Issue
Block a user