# all files / ol/interaction/ dragrotateinteraction.js

40.82% Statements 20/49
22.22% Branches 4/18
50% Functions 2/4
40.82% Lines 20/49

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    1331×

    1×
    1×
    1×
    1×
    1×
    1×

    1×

    114×

    114×

    114×

    114×

    114×

    1×

    1×

    1×

    1×
    60×
    60×

    1×
     goog.provide('ol.interaction.DragRotate');

    goog.require('ol');
    goog.require('ol.ViewHint');
    goog.require('ol.events.ConditionType');
    goog.require('ol.events.condition');
    goog.require('ol.interaction.Interaction');
    goog.require('ol.interaction.Pointer');

    /**
     * @classdesc
     * Allows the user to rotate the map by clicking and dragging on the map,
     * normally combined with an {@link ol.events.condition} that limits
     * it to when the alt and shift keys are held down.
     *
     * This interaction is only supported for mouse devices.
     *
     * @constructor
     * @extends {ol.interaction.Pointer}
     * @param {olx.interaction.DragRotateOptions=} opt_options Options.
     * @api stable
     */
    ol.interaction.DragRotate = function(opt_options) {

      var options = opt_options ? opt_options : {};

      goog.base(this, {
        handleDownEvent: ol.interaction.DragRotate.handleDownEvent_,
        handleDragEvent: ol.interaction.DragRotate.handleDragEvent_,
        handleUpEvent: ol.interaction.DragRotate.handleUpEvent_
      });

      /**
       * @private
       * @type {ol.events.ConditionType}
       */
      this.condition_ = options.condition ?
          options.condition : ol.events.condition.altShiftKeysOnly;

      /**
       * @private
       * @type {number|undefined}
       */
      this.lastAngle_ = undefined;

      /**
       * @private
       * @type {number}
       */
      this.duration_ = options.duration ? options.duration : 250;
    };
    goog.inherits(ol.interaction.DragRotate, ol.interaction.Pointer);

    /**
     * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
     * @this {ol.interaction.DragRotate}
     * @private
     */
    ol.interaction.DragRotate.handleDragEvent_ = function(mapBrowserEvent) {
      if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
        return;
      }

      var map = mapBrowserEvent.map;
      var size = map.getSize();
      var offset = mapBrowserEvent.pixel;
      var theta =
          Math.atan2(size[1] / 2 - offset[1], offset[0] - size[0] / 2);
      if (this.lastAngle_ !== undefined) {
        var delta = theta - this.lastAngle_;
        var view = map.getView();
        var rotation = view.getRotation();
        map.render();
        ol.interaction.Interaction.rotateWithoutConstraints(
            map, view, rotation - delta);
      }
      this.lastAngle_ = theta;
    };

    /**
     * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
     * @return {boolean} Stop drag sequence?
     * @this {ol.interaction.DragRotate}
     * @private
     */
    ol.interaction.DragRotate.handleUpEvent_ = function(mapBrowserEvent) {
      if (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
        return true;
      }

      var map = mapBrowserEvent.map;
      var view = map.getView();
      view.setHint(ol.ViewHint.INTERACTING, -1);
      var rotation = view.getRotation();
      ol.interaction.Interaction.rotate(map, view, rotation,
          undefined, this.duration_);
      return false;
    };

    /**
     * @param {ol.MapBrowserPointerEvent} mapBrowserEvent Event.
     * @return {boolean} Start drag sequence?
     * @this {ol.interaction.DragRotate}
     * @private
     */
    ol.interaction.DragRotate.handleDownEvent_ = function(mapBrowserEvent) {
      Eif (!ol.events.condition.mouseOnly(mapBrowserEvent)) {
        return false;
      }

      var browserEvent = mapBrowserEvent.browserEvent;
      if (browserEvent.isMouseActionButton() && this.condition_(mapBrowserEvent)) {
        var map = mapBrowserEvent.map;
        map.getView().setHint(ol.ViewHint.INTERACTING, 1);
        map.render();
        this.lastAngle_ = undefined;
        return true;
      } else {
        return false;
      }
    };

    /**
     * @inheritDoc
     */
    ol.interaction.DragRotate.prototype.shouldStopEvent = goog.functions.FALSE;