# all files / ol/ vectortile.js

98.25% Statements 56/57
75% Branches 3/4
93.75% Functions 15/16
98.25% Lines 56/57

    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
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    2491×

    1×
    1×
    1×

    1×

    30×

    30×

    30×

    30×

    30×

    30×

    30×

    30×

    30×

    30×

    1×

    1×
    8×
    8×
    8×
    8×
    8×

    1×
    6638×

    1×
    19×

    1×
    18×

    1×

    1×
    18×

    1×
    30×

    1×
    18×
    18×
    18×
    18×

    1×
    16×
    16×
    16×

    1×
    3×

    1×
    16×

    1×
    24×
    24×

    1×
    40×

    1×
    15×

    1×
    37×

    1×
     goog.provide('ol.VectorTile');

    goog.require('ol');
    goog.require('ol.Tile');
    goog.require('ol.TileState');

    /**
     * @constructor
     * @extends {ol.Tile}
     * @param {ol.TileCoord} tileCoord Tile coordinate.
     * @param {ol.TileState} state State.
     * @param {string} src Data source url.
     * @param {ol.format.Feature} format Feature format.
     * @param {ol.TileLoadFunctionType} tileLoadFunction Tile load function.
     */
    ol.VectorTile = function(tileCoord, state, src, format, tileLoadFunction) {

      ol.Tile.call(this, tileCoord, state);

      /**
       * @type {number}
       */
      this.consumers = 0;

      /**
       * @private
       * @type {ol.Extent}
       */
      this.extent_ = null;

      /**
       * @private
       * @type {ol.format.Feature}
       */
      this.format_ = format;

      /**
       * @private
       * @type {Array.<ol.Feature>}
       */
      this.features_ = null;

      /**
       * @private
       * @type {ol.FeatureLoader}
       */
      this.loader_;

      /**
       * Data projection
       * @private
       * @type {ol.proj.Projection}
       */
      this.projection_;

      /**
       * @private
       * @type {Object.<string, ol.render.ReplayGroup>}
       */
      this.replayGroups_ = {};

      /**
       * @private
       * @type {ol.TileLoadFunctionType}
       */
      this.tileLoadFunction_ = tileLoadFunction;

      /**
       * @private
       * @type {string}
       */
      this.url_ = src;

    };
    ol.inherits(ol.VectorTile, ol.Tile);

    /**
     * @inheritDoc
     */
    ol.VectorTile.prototype.disposeInternal = function() {
      this.features_ = null;
      this.replayGroups_ = {};
      this.state = ol.TileState.ABORT;
      this.changed();
      ol.Tile.prototype.disposeInternal.call(this);
    };

    /**
     * Gets the extent of the vector tile.
     * @return {ol.Extent} The extent.
     */
    ol.VectorTile.prototype.getExtent = function() {
      return this.extent_ || ol.VectorTile.DEFAULT_EXTENT;
    };

    /**
     * Get the feature format assigned for reading this tile's features.
     * @return {ol.format.Feature} Feature format.
     * @api
     */
    ol.VectorTile.prototype.getFormat = function() {
      return this.format_;
    };

    /**
     * Get the features for this tile. Geometries will be in the projection returned
     * by {@link ol.VectorTile#getProjection}.
     * @return {Array.<ol.Feature|ol.render.Feature>} Features.
     * @api
     */
    ol.VectorTile.prototype.getFeatures = function() {
      return this.features_;
    };

    /**
     * @inheritDoc
     */
    ol.VectorTile.prototype.getKey = function() {
      return this.url_;
    };

    /**
     * Get the feature projection of features returned by
     * {@link ol.VectorTile#getFeatures}.
     * @return {ol.proj.Projection} Feature projection.
     * @api
     */
    ol.VectorTile.prototype.getProjection = function() {
      return this.projection_;
    };

    /**
     * @param {ol.layer.Layer} layer Layer.
     * @param {string} key Key.
     * @return {ol.render.ReplayGroup} Replay group.
     */
    ol.VectorTile.prototype.getReplayGroup = function(layer, key) {
      return this.replayGroups_[ol.getUid(layer) + ',' + key];
    };

    /**
     * @inheritDoc
     */
    ol.VectorTile.prototype.load = function() {
      Eif (this.state == ol.TileState.IDLE) {
        this.setState(ol.TileState.LOADING);
        this.tileLoadFunction_(this, this.url_);
        this.loader_(null, NaN, null);
      }
    };

    /**
     * Handler for successful tile load.
     * @param {Array.<ol.Feature>} features The loaded features.
     * @param {ol.proj.Projection} dataProjection Data projection.
     * @param {ol.Extent} extent Extent.
     */
    ol.VectorTile.prototype.onLoad = function(features, dataProjection, extent) {
      this.setProjection(dataProjection);
      this.setFeatures(features);
      this.setExtent(extent);
    };

    /**
     * Handler for tile load errors.
     */
    ol.VectorTile.prototype.onError = function() {
      this.setState(ol.TileState.ERROR);
    };

    /**
     * Function for use in an {@link ol.source.VectorTile}'s `tileLoadFunction`.
     * Sets the extent of the vector tile. This is only required for tiles in
     * projections with `tile-pixels` as units. The extent should be set to
     * `[0, 0, tilePixelSize, tilePixelSize]`, where `tilePixelSize` is calculated
     * by multiplying the tile size with the tile pixel ratio. For sources using
     * {@link ol.format.MVT} as feature format, the
     * {@link ol.format.MVT#getLastExtent} method will return the correct extent.
     * The default is `[0, 0, 4096, 4096]`.
     * @param {ol.Extent} extent The extent.
     * @api
     */
    ol.VectorTile.prototype.setExtent = function(extent) {
      this.extent_ = extent;
    };

    /**
     * Function for use in an {@link ol.source.VectorTile}'s `tileLoadFunction`.
     * Sets the features for the tile.
     * @param {Array.<ol.Feature>} features Features.
     * @api
     */
    ol.VectorTile.prototype.setFeatures = function(features) {
      this.features_ = features;
      this.setState(ol.TileState.LOADED);
    };

    /**
     * Function for use in an {@link ol.source.VectorTile}'s `tileLoadFunction`.
     * Sets the projection of the features that were added with
     * {@link ol.VectorTile#setFeatures}.
     * @param {ol.proj.Projection} projection Feature projection.
     * @api
     */
    ol.VectorTile.prototype.setProjection = function(projection) {
      this.projection_ = projection;
    };

    /**
     * @param {ol.layer.Layer} layer Layer.
     * @param {string} key Key.
     * @param {ol.render.ReplayGroup} replayGroup Replay group.
     */
    ol.VectorTile.prototype.setReplayGroup = function(layer, key, replayGroup) {
      this.replayGroups_[ol.getUid(layer) + ',' + key] = replayGroup;
    };

    /**
     * Set the feature loader for reading this tile's features.
     * @param {ol.FeatureLoader} loader Feature loader.
     * @api
     */
    ol.VectorTile.prototype.setLoader = function(loader) {
      this.loader_ = loader;
    };

    /**
     * @const
     * @type {ol.Extent}
     */
    ol.VectorTile.DEFAULT_EXTENT = [0, 0, 4096, 4096];