devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
99 lines (98 loc) • 2.96 kB
JavaScript
/**
* DevExtreme (esm/__internal/viz/vector_map/gesture_handler.js)
* Version: 26.1.6
* Build date: Fri Oct 16 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
const _ln = Math.log;
const _LN2 = Math.LN2;
export let GestureHandler = class {
constructor(params) {
this._projection = params.projection;
this._renderer = params.renderer;
this._x = this._y = 0;
this._subscribeToTracker(params.tracker)
}
dispose() {
this._offTracker();
this._offTracker = null
}
_subscribeToTracker(tracker) {
const that = this;
let isActive = false;
that._offTracker = tracker.on({
start(arg) {
isActive = "control-bar" !== arg.data.name;
if (isActive) {
that._processStart(arg)
}
},
move(arg) {
if (isActive) {
that._processMove(arg)
}
},
end() {
if (isActive) {
that._processEnd()
}
},
zoom(arg) {
that._processZoom(arg)
}
})
}
setInteraction(options) {
this._processEnd();
this._centeringEnabled = options.centeringEnabled;
this._zoomingEnabled = options.zoomingEnabled
}
_processStart(arg) {
if (this._centeringEnabled) {
this._x = arg.x;
this._y = arg.y;
this._projection.beginMoveCenter()
}
}
_processMove(arg) {
if (this._centeringEnabled) {
this._renderer.root.attr({
cursor: "move"
});
this._projection.moveCenter([this._x - arg.x, this._y - arg.y]);
this._x = arg.x;
this._y = arg.y
}
}
_processEnd() {
if (this._centeringEnabled) {
this._renderer.root.attr({
cursor: "default"
});
this._projection.endMoveCenter()
}
}
_processZoom(arg) {
let delta;
let screenPosition;
let coords;
if (this._zoomingEnabled) {
if (arg.delta) {
delta = arg.delta
} else if (arg.ratio) {
delta = _ln(arg.ratio) / _LN2
}
if (this._centeringEnabled) {
screenPosition = this._renderer.getRootOffset();
screenPosition = [arg.x - screenPosition.left, arg.y - screenPosition.top];
coords = this._projection.fromScreenPoint(screenPosition)
}
this._projection.changeScaledZoom(delta);
if (this._centeringEnabled) {
this._projection.setCenterByPoint(coords, screenPosition)
}
}
}
};