# all files / ol/layer/ vectortile.js

100% Statements 31/31
75% Branches 9/12
100% Functions 6/6
100% Lines 31/31

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

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

    1×
    26×

    26×

    26×
    26×
    26×

    26×
    26×

    26×

    25×

    25×

    1×

    1×
    24×

    1×
    68×

    1×
    65×

    1×
    26×

    1×
    26×

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

    goog.require('ol');
    goog.require('ol.LayerType');
    goog.require('ol.asserts');
    goog.require('ol.layer.TileProperty');
    goog.require('ol.layer.Vector');
    goog.require('ol.layer.VectorTileRenderType');
    goog.require('ol.obj');

    /**
     * @classdesc
     * Layer for vector tile data that is rendered client-side.
     * Note that any property set in the options is set as a {@link ol.Object}
     * property on the layer object; for example, setting `title: 'My Title'` in the
     * options means that `title` is observable, and has get/set accessors.
     *
     * @constructor
     * @extends {ol.layer.Vector}
     * @param {olx.layer.VectorTileOptions=} opt_options Options.
     * @api
     */
    ol.layer.VectorTile = function(opt_options) {
      var options = opt_options ? opt_options : {};

      var baseOptions = ol.obj.assign({}, options);

      delete baseOptions.preload;
      delete baseOptions.useInterimTilesOnError;
      ol.layer.Vector.call(this,  /** @type {olx.layer.VectorOptions} */ (baseOptions));

      this.setPreload(options.preload ? options.preload : 0);
      this.setUseInterimTilesOnError(options.useInterimTilesOnError ?
        options.useInterimTilesOnError : true);

      ol.asserts.assert(options.renderMode == undefined ||
          options.renderMode == ol.layer.VectorTileRenderType.IMAGE ||
          options.renderMode == ol.layer.VectorTileRenderType.HYBRID ||
          options.renderMode == ol.layer.VectorTileRenderType.VECTOR,
      28); // `renderMode` must be `'image'`, `'hybrid'` or `'vector'`

      /**
       * @private
       * @type {ol.layer.VectorTileRenderType|string}
       */
      this.renderMode_ = options.renderMode || ol.layer.VectorTileRenderType.HYBRID;

      /**
       * The layer type.
       * @protected
       * @type {ol.LayerType}
       */
      this.type = ol.LayerType.VECTOR_TILE;

    };
    ol.inherits(ol.layer.VectorTile, ol.layer.Vector);

    /**
     * Return the level as number to which we will preload tiles up to.
     * @return {number} The level to preload tiles up to.
     * @observable
     * @api
     */
    ol.layer.VectorTile.prototype.getPreload = function() {
      return /** @type {number} */ (this.get(ol.layer.TileProperty.PRELOAD));
    };

    /**
     * @return {ol.layer.VectorTileRenderType|string} The render mode.
     */
    ol.layer.VectorTile.prototype.getRenderMode = function() {
      return this.renderMode_;
    };

    /**
     * Whether we use interim tiles on error.
     * @return {boolean} Use interim tiles on error.
     * @observable
     * @api
     */
    ol.layer.VectorTile.prototype.getUseInterimTilesOnError = function() {
      return /** @type {boolean} */ (
        this.get(ol.layer.TileProperty.USE_INTERIM_TILES_ON_ERROR));
    };

    /**
     * Set the level as number to which we will preload tiles up to.
     * @param {number} preload The level to preload tiles up to.
     * @observable
     * @api
     */
    ol.layer.VectorTile.prototype.setPreload = function(preload) {
      this.set(ol.layer.TileProperty.PRELOAD, preload);
    };

    /**
     * Set whether we use interim tiles on error.
     * @param {boolean} useInterimTilesOnError Use interim tiles on error.
     * @observable
     * @api
     */
    ol.layer.VectorTile.prototype.setUseInterimTilesOnError = function(useInterimTilesOnError) {
      this.set(
          ol.layer.TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
    };

    /**
     * Return the associated {@link ol.source.VectorTile vectortilesource} of the layer.
     * @function
     * @return {ol.source.VectorTile} Source.
     * @api
     */
    ol.layer.VectorTile.prototype.getSource;