<commit_before>// FIXME support touch events?
// FIXME use goog.fx.Dragger in ol.Map instead?

goog.provide('ol.control.Drag');

goog.require('goog.events.EventType');
goog.require('goog.functions');
goog.require('ol.Control');
goog.require('ol.MapBrowserEvent');



/**
 * @constructor
 * @extends {ol.Control}
 */
ol.control.Drag = function() {

  goog.base(this);

  /**
   * @private
   * @type {boolean}
   */
  this.dragging_ = false;

  /**
   * @type {number}
   */
  this.startX = 0;

  /**
   * @type {number}
   */
  this.startY = 0;

  /**
   * @type {number}
   */
  this.offsetX = 0;

  /**
   * @type {number}
   */
  this.offsetY = 0;

  /**
   * @type {goog.math.Coordinate}
   */
  this.startCenter = null;

  /**
   * @type {goog.math.Coordinate}
   */
  this.startCoordinate = null;

};
goog.inherits(ol.control.Drag, ol.Control);


/**
 * @param {ol.MapBrowserEvent} mapBrowserEvent Event.
 * @protected
 */
ol.control.Drag.prototype.handleDrag = goog.nullFunction;


/**
 * @param {ol.MapBrowserEvent} mapBrowserEvent Event.
 * @protected
 * @return {boolean} Capture dragging.
 */
ol.control.Drag.prototype.handleDragStart = goog.functions.FALSE;


/**
 * @param {ol.MapBrowserEvent} mapBrowserEvent Event.
 * @protected
 */
ol.control.Drag.prototype.handleDragEnd = goog.nullFunction;


/**
 * @inheritDoc
 */
ol.control.Drag.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
  var browserEventObject;
  if (this.dragging_) {
    if (mapBrowserEvent.type == goog.events.EventType.MOUSEMOVE ||
        mapBrowserEvent.type == goog.events.EventType.MOUSEOUT ||
        mapBrowserEvent.type == goog.events.EventType.MOUSEUP) {
      browserEventObject = mapBrowserEvent.getBrowserEventObject();
      this.deltaX = browserEventObject.offsetX - this.startX;
      this.deltaY = browserEventObject.offsetY - this.startY;
      if (mapBrowserEvent.type == goog.events.EventType.MOUSEMOVE) {
        this.handleDrag(mapBrowserEvent);
      } else {
        this.handleDragEnd(mapBrowserEvent);
        this.dragging_ = false;
      }
      mapBrowserEvent.preventDefault();
    }
  } else {
    if (mapBrowserEvent.type == goog.events.EventType.MOUSEDOWN) {
      browserEventObject = mapBrowserEvent.getBrowserEventObject();
      this.startX = browserEventObject.offsetX;
      this.startY = browserEventObject.offsetY;
      this.deltaX = 0;
      this.deltaY = 0;
      this.startCenter = mapBrowserEvent.map.getCenter();
      this.startCoordinate = mapBrowserEvent.getCoordinate();
      if (this.handleDragStart(mapBrowserEvent)) {<commit_msg>Don't drag on incompletely defined maps<commit_after>// FIXME support touch events?
// FIXME use goog.fx.Dragger in ol.Map instead?

goog.provide('ol.control.Drag');

goog.require('goog.events.EventType');
goog.require('goog.functions');
goog.require('ol.Control');
goog.require('ol.MapBrowserEvent');



/**
 * @constructor
 * @extends {ol.Control}
 */
ol.control.Drag = function() {

  goog.base(this);

  /**
   * @private
   * @type {boolean}
   */
  this.dragging_ = false;

  /**
   * @type {number}
   */
  this.startX = 0;

  /**
   * @type {number}
   */
  this.startY = 0;

  /**
   * @type {number}
   */
  this.offsetX = 0;

  /**
   * @type {number}
   */
  this.offsetY = 0;

  /**
   * @type {goog.math.Coordinate}
   */
  this.startCenter = null;

  /**
   * @type {goog.math.Coordinate}
   */
  this.startCoordinate = null;

};
goog.inherits(ol.control.Drag, ol.Control);


/**
 * @param {ol.MapBrowserEvent} mapBrowserEvent Event.
 * @protected
 */
ol.control.Drag.prototype.handleDrag = goog.nullFunction;


/**
 * @param {ol.MapBrowserEvent} mapBrowserEvent Event.
 * @protected
 * @return {boolean} Capture dragging.
 */
ol.control.Drag.prototype.handleDragStart = goog.functions.FALSE;


/**
 * @param {ol.MapBrowserEvent} mapBrowserEvent Event.
 * @protected
 */
ol.control.Drag.prototype.handleDragEnd = goog.nullFunction;


/**
 * @inheritDoc
 */
ol.control.Drag.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
  var center = mapBrowserEvent.map.getCenter();
  var resolution = mapBrowserEvent.map.getResolution();
  if (!goog.isDef(center) || !goog.isDef(resolution)) {
    return;
  }
  var browserEventObject;
  if (this.dragging_) {
    if (mapBrowserEvent.type == goog.events.EventType.MOUSEMOVE ||
        mapBrowserEvent.type == goog.events.EventType.MOUSEOUT ||
        mapBrowserEvent.type == goog.events.EventType.MOUSEUP) {
      browserEventObject = mapBrowserEvent.getBrowserEventObject();
      this.deltaX = browserEventObject.offsetX - this.startX;
      this.deltaY = browserEventObject.offsetY - this.startY;
      if (mapBrowserEvent.type == goog.events.EventType.MOUSEMOVE) {
        this.handleDrag(mapBrowserEvent);
      } else {
        this.handleDragEnd(mapBrowserEvent);
        this.dragging_ = false;
      }
      mapBrowserEvent.preventDefault();
    }
  } else {
    if (mapBrowserEvent.type == goog.events.EventType.MOUSEDOWN) {
      browserEventObject = mapBrowserEvent.getBrowserEventObject();
      this.startX = browserEventObject.offsetX;
      this.startY = browserEventObject.offsetY;
      this.deltaX = 0;
      this.deltaY = 0;
      this.startCenter = center;
      this.startCoordinate = mapBrowserEvent.getCoordinate();
      if (this.handleDragStart(mapBrowserEvent)) {
{'fraction_non_alphanumeric': 0.14545454545454545, 'fraction_numerical': 0.0022492970946579195, 'mean_word_length': 3.22486144101346, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4367216', 'n_tokens_mistral': 1784, 'n_tokens_neox': 1729, 'n_words': 273}