# Code coverage report for ol/tilegrid/xyztilegrid.js

## Statements: 82.14% (46 / 56) Branches: 62.5% (15 / 24) Functions: 100% (5 / 5) Lines: 82.14% (46 / 56) Ignored: none

All files » ol/tilegrid/ » xyztilegrid.js

    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
    1261

    1
    1
    1
    1
    1
    1
    1
    1
    1
    1

    1
    13

    13

    13

    1

    1
    8
    8
    8

    8
    8

    8

    16
    16

    16
    16
    16
    16
    2

    14

    14

    1

    14
    13
    13
    13

    1

    1

    7

    7
    7
    125
    125
    125

    7

     goog.provide('ol.tilegrid.XYZ');

    goog.require('goog.math');
    goog.require('ol');
    goog.require('ol.TileCoord');
    goog.require('ol.TileRange');
    goog.require('ol.extent');
    goog.require('ol.extent.Corner');
    goog.require('ol.proj');
    goog.require('ol.proj.EPSG3857');
    goog.require('ol.tilecoord');
    goog.require('ol.tilegrid.TileGrid');

    /**
     * @classdesc
     * Set the grid pattern for sources accessing XYZ tiled-image servers.
     *
     * @constructor
     * @extends {ol.tilegrid.TileGrid}
     * @param {olx.tilegrid.XYZOptions} options XYZ options.
     * @struct
     * @api
     */
    ol.tilegrid.XYZ = function(options) {
      var extent = goog.isDef(options.extent) ?
          options.extent : ol.proj.EPSG3857.EXTENT;
      var resolutions = ol.tilegrid.resolutionsFromExtent(
          extent, options.maxZoom, options.tileSize);

      goog.base(this, {
        minZoom: options.minZoom,
        origin: ol.extent.getCorner(extent, ol.extent.Corner.TOP_LEFT),
        resolutions: resolutions,
        tileSize: options.tileSize
      });

    };
    goog.inherits(ol.tilegrid.XYZ, ol.tilegrid.TileGrid);

    /**
     * @inheritDoc
     */
    ol.tilegrid.XYZ.prototype.createTileCoordTransform = function(opt_options) {
      var options = goog.isDef(opt_options) ? opt_options : {};
      var minZ = this.minZoom;
      var maxZ = this.maxZoom;
      /** @type {Array.<ol.TileRange>} */
      var tileRangeByZ = null;
      Iif (goog.isDef(options.extent)) {
        tileRangeByZ = new Array(maxZ + 1);
        var z;
        for (z = 0; z <= maxZ; ++z) {
          if (z < minZ) {
            tileRangeByZ[z] = null;
          } else {
            tileRangeByZ[z] = this.getTileRangeForExtentAndZ(options.extent, z);
          }
        }
      }
      return (
          /**
           * @param {ol.TileCoord} tileCoord Tile coordinate.
           * @param {ol.proj.Projection} projection Projection.
           * @param {ol.TileCoord=} opt_tileCoord Destination tile coordinate.
           * @return {ol.TileCoord} Tile coordinate.
           */
          function(tileCoord, projection, opt_tileCoord) {
            var z = tileCoord[0];
            Iif (z < minZ || maxZ < z) {
              return null;
            }
            var n = Math.pow(2, z);
            var x = tileCoord[1];
            var y = tileCoord[2];
            if (y < -n || -1 < y) {
              return null;
            }
            Iif (!goog.isNull(tileRangeByZ)) {
              if (!tileRangeByZ[z].containsXY(x, y)) {
                return null;
              }
            }
            return ol.tilecoord.createOrUpdate(z, x, -y - 1, opt_tileCoord);
          });
    };

    /**
     * @inheritDoc
     */
    ol.tilegrid.XYZ.prototype.getTileCoordChildTileRange =
        function(tileCoord, opt_tileRange) {
      if (tileCoord[0] < this.maxZoom) {
        var doubleX = 2 * tileCoord[1];
        var doubleY = 2 * tileCoord[2];
        return ol.TileRange.createOrUpdate(
            doubleX, doubleX + 1,
            doubleY, doubleY + 1,
            opt_tileRange);
      } else {
        return null;
      }
    };

    /**
     * @inheritDoc
     */
    ol.tilegrid.XYZ.prototype.forEachTileCoordParentTileRange =
        function(tileCoord, callback, opt_this, opt_tileRange) {
      var tileRange = ol.TileRange.createOrUpdate(
          0, tileCoord[1], 0, tileCoord[2], opt_tileRange);
      var z;
      for (z = tileCoord[0] - 1; z >= this.minZoom; --z) {
        tileRange.minX = tileRange.maxX >>= 1;
        tileRange.minY = tileRange.maxY >>= 1;
        Iif (callback.call(opt_this, z, tileRange)) {
          return true;
        }
      }
      return false;
    };