# all files / ol/ attribution.js

27.59% Statements 8/29
11.11% Branches 2/18
33.33% Functions 1/3
27.59% Lines 8/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
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    991×

    1×
    1×

    1×

    34×

    34×

    1×

    1×

     goog.provide('ol.Attribution');

    goog.require('goog.math');
    goog.require('ol.TileRange');

    /**
     * @classdesc
     * An attribution for a layer source.
     *
     * Example:
     *
     *     source: new ol.source.OSM({
     *       attributions: [
     *         new ol.Attribution({
     *           html: 'All maps &copy; ' +
     *               '<a href="http://www.opencyclemap.org/">OpenCycleMap</a>'
     *         }),
     *         ol.source.OSM.ATTRIBUTION
     *       ],
     *     ..
     *
     * @constructor
     * @param {olx.AttributionOptions} options Attribution options.
     * @struct
     * @api stable
     */
    ol.Attribution = function(options) {

      /**
       * @private
       * @type {string}
       */
      this.html_ = options.html;

      /**
       * @private
       * @type {Object.<string, Array.<ol.TileRange>>}
       */
      this.tileRanges_ = options.tileRanges ? options.tileRanges : null;

    };

    /**
     * Get the attribution markup.
     * @return {string} The attribution HTML.
     * @api stable
     */
    ol.Attribution.prototype.getHTML = function() {
      return this.html_;
    };

    /**
     * @param {Object.<string, ol.TileRange>} tileRanges Tile ranges.
     * @param {!ol.tilegrid.TileGrid} tileGrid Tile grid.
     * @param {!ol.proj.Projection} projection Projection.
     * @return {boolean} Intersects any tile range.
     */
    ol.Attribution.prototype.intersectsAnyTileRange =
        function(tileRanges, tileGrid, projection) {
      if (!this.tileRanges_) {
        return true;
      }
      var i, ii, tileRange, zKey;
      for (zKey in tileRanges) {
        if (!(zKey in this.tileRanges_)) {
          continue;
        }
        tileRange = tileRanges[zKey];
        var testTileRange;
        for (i = 0, ii = this.tileRanges_[zKey].length; i < ii; ++i) {
          testTileRange = this.tileRanges_[zKey][i];
          if (testTileRange.intersects(tileRange)) {
            return true;
          }
          var extentTileRange = tileGrid.getTileRangeForExtentAndZ(
              projection.getExtent(), parseInt(zKey, 10));
          var width = extentTileRange.getWidth();
          if (tileRange.minX < extentTileRange.minX ||
              tileRange.maxX > extentTileRange.maxX) {
            if (testTileRange.intersects(new ol.TileRange(
                goog.math.modulo(tileRange.minX, width),
                goog.math.modulo(tileRange.maxX, width),
                tileRange.minY, tileRange.maxY))) {
              return true;
            }
            if (tileRange.getWidth() > width &&
                testTileRange.intersects(extentTileRange)) {
              return true;
            }
          }
        }
      }
      return false;
    };