# all files / ol/ imagecanvas.js

61.54% Statements 16/26
25% Branches 2/8
40% Functions 2/5
61.54% Lines 16/26

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

    1×
    1×
    1×

    1×

    9×

    9×

    9×

    9×

    9×

    1×

    1×

    1×

    1×

    1×
    2×

     goog.provide('ol.ImageCanvas');

    goog.require('ol');
    goog.require('ol.ImageBase');
    goog.require('ol.ImageState');

    /**
     * @constructor
     * @extends {ol.ImageBase}
     * @param {ol.Extent} extent Extent.
     * @param {number} resolution Resolution.
     * @param {number} pixelRatio Pixel ratio.
     * @param {Array.<ol.Attribution>} attributions Attributions.
     * @param {HTMLCanvasElement} canvas Canvas.
     * @param {ol.ImageCanvasLoader=} opt_loader Optional loader function to
     *     support asynchronous canvas drawing.
     */
    ol.ImageCanvas = function(extent, resolution, pixelRatio, attributions,
        canvas, opt_loader) {

      /**
       * Optional canvas loader function.
       * @type {?ol.ImageCanvasLoader}
       * @private
       */
      this.loader_ = opt_loader !== undefined ? opt_loader : null;

      var state = opt_loader !== undefined ?
        ol.ImageState.IDLE : ol.ImageState.LOADED;

      ol.ImageBase.call(this, extent, resolution, pixelRatio, state, attributions);

      /**
       * @private
       * @type {HTMLCanvasElement}
       */
      this.canvas_ = canvas;

      /**
       * @private
       * @type {Error}
       */
      this.error_ = null;

    };
    ol.inherits(ol.ImageCanvas, ol.ImageBase);

    /**
     * Get any error associated with asynchronous rendering.
     * @return {Error} Any error that occurred during rendering.
     */
    ol.ImageCanvas.prototype.getError = function() {
      return this.error_;
    };

    /**
     * Handle async drawing complete.
     * @param {Error} err Any error during drawing.
     * @private
     */
    ol.ImageCanvas.prototype.handleLoad_ = function(err) {
      if (err) {
        this.error_ = err;
        this.state = ol.ImageState.ERROR;
      } else {
        this.state = ol.ImageState.LOADED;
      }
      this.changed();
    };

    /**
     * @inheritDoc
     */
    ol.ImageCanvas.prototype.load = function() {
      if (this.state == ol.ImageState.IDLE) {
        this.state = ol.ImageState.LOADING;
        this.changed();
        this.loader_(this.handleLoad_.bind(this));
      }
    };

    /**
     * @inheritDoc
     */
    ol.ImageCanvas.prototype.getImage = function(opt_context) {
      return this.canvas_;
    };