# all files / ol/control/ zoomtoextentcontrol.js

72.41% Statements 21/29
41.67% Branches 5/12
33.33% Functions 1/3
72.41% Lines 21/29

    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
    791×

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

    1×
    1×

    1×

    1×

    1×
    1×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

    1×

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

    goog.require('goog.asserts');
    goog.require('goog.dom');
    goog.require('goog.events');
    goog.require('goog.events.EventType');
    goog.require('ol.control.Control');
    goog.require('ol.css');

    /**
     * @classdesc
     * A button control which, when pressed, changes the map view to a specific
     * extent. To style this control use the css selector `.ol-zoom-extent`.
     *
     * @constructor
     * @extends {ol.control.Control}
     * @param {olx.control.ZoomToExtentOptions=} opt_options Options.
     * @api stable
     */
    ol.control.ZoomToExtent = function(opt_options) {
      var options = opt_options ? opt_options : {};

      /**
       * @type {ol.Extent}
       * @private
       */
      this.extent_ = options.extent ? options.extent : null;

      var className = options.className ? options.className :
          'ol-zoom-extent';

      var label = options.label ? options.label : 'E';
      var tipLabel = options.tipLabel ?
          options.tipLabel : 'Fit to extent';
      var button = goog.dom.createDom('BUTTON', {
        'type': 'button',
        'title': tipLabel
      }, label);

      goog.events.listen(button, goog.events.EventType.CLICK,
          this.handleClick_, false, this);

      var cssClasses = className + ' ' + ol.css.CLASS_UNSELECTABLE + ' ' +
          ol.css.CLASS_CONTROL;
      var element = goog.dom.createDom('DIV', cssClasses, button);

      goog.base(this, {
        element: element,
        target: options.target
      });
    };
    goog.inherits(ol.control.ZoomToExtent, ol.control.Control);

    /**
     * @param {goog.events.BrowserEvent} event The event to handle
     * @private
     */
    ol.control.ZoomToExtent.prototype.handleClick_ = function(event) {
      event.preventDefault();
      this.handleZoomToExtent_();
    };

    /**
     * @private
     */
    ol.control.ZoomToExtent.prototype.handleZoomToExtent_ = function() {
      var map = this.getMap();
      var view = map.getView();
      var extent = !this.extent_ ?
          view.getProjection().getExtent() : this.extent_;
      var size = map.getSize();
      goog.asserts.assert(size, 'size should be defined');
      view.fit(extent, size);
    };