# all files / ol/renderer/dom/ domimagelayerrenderer.js

24% Statements 18/75
0% Branches 0/21
0% Functions 0/6
24% Lines 18/75

    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
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    1621×

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

    1×

    1×

    1×

    1×

    1×

    1×

     goog.provide('ol.renderer.dom.ImageLayer');

    goog.require('goog.asserts');
    goog.require('goog.dom');
    goog.require('goog.vec.Mat4');
    goog.require('ol.ImageBase');
    goog.require('ol.ViewHint');
    goog.require('ol.dom');
    goog.require('ol.extent');
    goog.require('ol.layer.Image');
    goog.require('ol.proj');
    goog.require('ol.renderer.dom.Layer');
    goog.require('ol.vec.Mat4');

    /**
     * @constructor
     * @extends {ol.renderer.dom.Layer}
     * @param {ol.layer.Image} imageLayer Image layer.
     */
    ol.renderer.dom.ImageLayer = function(imageLayer) {
      var target = document.createElement('DIV');
      target.style.position = 'absolute';

      goog.base(this, imageLayer, target);

      /**
       * The last rendered image.
       * @private
       * @type {?ol.ImageBase}
       */
      this.image_ = null;

      /**
       * @private
       * @type {goog.vec.Mat4.Number}
       */
      this.transform_ = goog.vec.Mat4.createNumberIdentity();

    };
    goog.inherits(ol.renderer.dom.ImageLayer, ol.renderer.dom.Layer);

    /**
     * @inheritDoc
     */
    ol.renderer.dom.ImageLayer.prototype.forEachFeatureAtCoordinate =
        function(coordinate, frameState, callback, thisArg) {
      var layer = this.getLayer();
      var source = layer.getSource();
      var resolution = frameState.viewState.resolution;
      var rotation = frameState.viewState.rotation;
      var skippedFeatureUids = frameState.skippedFeatureUids;
      return source.forEachFeatureAtCoordinate(
          coordinate, resolution, rotation, skippedFeatureUids,
          /**
           * @param {ol.Feature|ol.render.Feature} feature Feature.
           * @return {?} Callback result.
           */
          function(feature) {
            return callback.call(thisArg, feature, layer);
          });
    };

    /**
     * @inheritDoc
     */
    ol.renderer.dom.ImageLayer.prototype.clearFrame = function() {
      goog.dom.removeChildren(this.target);
      this.image_ = null;
    };

    /**
     * @inheritDoc
     */
    ol.renderer.dom.ImageLayer.prototype.prepareFrame =
        function(frameState, layerState) {

      var viewState = frameState.viewState;
      var viewCenter = viewState.center;
      var viewResolution = viewState.resolution;
      var viewRotation = viewState.rotation;

      var image = this.image_;
      var imageLayer = this.getLayer();
      goog.asserts.assertInstanceof(imageLayer, ol.layer.Image,
          'layer is an instance of ol.layer.Image');
      var imageSource = imageLayer.getSource();

      var hints = frameState.viewHints;

      var renderedExtent = frameState.extent;
      if (layerState.extent !== undefined) {
        renderedExtent = ol.extent.getIntersection(
            renderedExtent, layerState.extent);
      }

      if (!hints[ol.ViewHint.ANIMATING] && !hints[ol.ViewHint.INTERACTING] &&
          !ol.extent.isEmpty(renderedExtent)) {
        var projection = viewState.projection;
        if (!ol.ENABLE_RASTER_REPROJECTION) {
          var sourceProjection = imageSource.getProjection();
          if (sourceProjection) {
            goog.asserts.assert(ol.proj.equivalent(projection, sourceProjection),
                'projection and sourceProjection are equivalent');
            projection = sourceProjection;
          }
        }
        var image_ = imageSource.getImage(renderedExtent, viewResolution,
            frameState.pixelRatio, projection);
        if (image_) {
          var loaded = this.loadImage(image_);
          if (loaded) {
            image = image_;
          }
        }
      }

      if (image) {
        var imageExtent = image.getExtent();
        var imageResolution = image.getResolution();
        var transform = goog.vec.Mat4.createNumber();
        ol.vec.Mat4.makeTransform2D(transform,
            frameState.size[0] / 2, frameState.size[1] / 2,
            imageResolution / viewResolution, imageResolution / viewResolution,
            viewRotation,
            (imageExtent[0] - viewCenter[0]) / imageResolution,
            (viewCenter[1] - imageExtent[3]) / imageResolution);
        if (image != this.image_) {
          var imageElement = image.getImage(this);
          // Bootstrap sets the style max-width: 100% for all images, which breaks
          // prevents the image from being displayed in FireFox.  Workaround by
          // overriding the max-width style.
          imageElement.style.maxWidth = 'none';
          imageElement.style.position = 'absolute';
          goog.dom.removeChildren(this.target);
          this.target.appendChild(imageElement);
          this.image_ = image;
        }
        this.setTransform_(transform);
        this.updateAttributions(frameState.attributions, image.getAttributions());
        this.updateLogos(frameState, imageSource);
      }

      return true;
    };

    /**
     * @param {goog.vec.Mat4.Number} transform Transform.
     * @private
     */
    ol.renderer.dom.ImageLayer.prototype.setTransform_ = function(transform) {
      if (!ol.vec.Mat4.equals2D(transform, this.transform_)) {
        ol.dom.transformElement2D(this.target, transform, 6);
        goog.vec.Mat4.setFromArray(this.transform_, transform);
      }
    };