gesture_handler.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * DevExtreme (viz/vector_map/gesture_handler.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var _ln = Math.log;
  11. var _LN2 = Math.LN2;
  12. function GestureHandler(params) {
  13. var that = this;
  14. that._projection = params.projection;
  15. that._renderer = params.renderer;
  16. that._x = that._y = 0;
  17. that._subscribeToTracker(params.tracker)
  18. }
  19. GestureHandler.prototype = {
  20. constructor: GestureHandler,
  21. dispose: function() {
  22. this._offTracker();
  23. this._offTracker = null
  24. },
  25. _subscribeToTracker: function(tracker) {
  26. var that = this;
  27. var isActive = false;
  28. that._offTracker = tracker.on({
  29. start: function(arg) {
  30. isActive = "control-bar" !== arg.data.name;
  31. if (isActive) {
  32. that._processStart(arg)
  33. }
  34. },
  35. move: function(arg) {
  36. if (isActive) {
  37. that._processMove(arg)
  38. }
  39. },
  40. end: function() {
  41. if (isActive) {
  42. that._processEnd()
  43. }
  44. },
  45. zoom: function(arg) {
  46. that._processZoom(arg)
  47. }
  48. })
  49. },
  50. setInteraction: function(options) {
  51. this._processEnd();
  52. this._centeringEnabled = options.centeringEnabled;
  53. this._zoomingEnabled = options.zoomingEnabled
  54. },
  55. _processStart: function(arg) {
  56. if (this._centeringEnabled) {
  57. this._x = arg.x;
  58. this._y = arg.y;
  59. this._projection.beginMoveCenter()
  60. }
  61. },
  62. _processMove: function(arg) {
  63. var that = this;
  64. if (that._centeringEnabled) {
  65. that._renderer.root.attr({
  66. cursor: "move"
  67. });
  68. that._projection.moveCenter([that._x - arg.x, that._y - arg.y]);
  69. that._x = arg.x;
  70. that._y = arg.y
  71. }
  72. },
  73. _processEnd: function() {
  74. if (this._centeringEnabled) {
  75. this._renderer.root.attr({
  76. cursor: "default"
  77. });
  78. this._projection.endMoveCenter()
  79. }
  80. },
  81. _processZoom: function(arg) {
  82. var that = this;
  83. var delta;
  84. var screenPosition;
  85. var coords;
  86. if (that._zoomingEnabled) {
  87. if (arg.delta) {
  88. delta = arg.delta
  89. } else {
  90. if (arg.ratio) {
  91. delta = _ln(arg.ratio) / _LN2
  92. }
  93. }
  94. if (that._centeringEnabled) {
  95. screenPosition = that._renderer.getRootOffset();
  96. screenPosition = [arg.x - screenPosition.left, arg.y - screenPosition.top];
  97. coords = that._projection.fromScreenPoint(screenPosition)
  98. }
  99. that._projection.changeScaledZoom(delta);
  100. if (that._centeringEnabled) {
  101. that._projection.setCenterByPoint(coords, screenPosition)
  102. }
  103. }
  104. }
  105. };
  106. exports.GestureHandler = GestureHandler;