# all files / ol/source/ stamensource.js

55.56% Statements 10/18
0% Branches 0/4
0% Functions 0/1
55.56% Lines 10/18

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

    1×
    1×
    1×
    1×

    1×

    1×

    1×

    1×

    1×

     goog.provide('ol.source.Stamen');

    goog.require('goog.asserts');
    goog.require('ol.Attribution');
    goog.require('ol.source.OSM');
    goog.require('ol.source.XYZ');

    /**
     * @type {Object.<string, {extension: string, opaque: boolean}>}
     */
    ol.source.StamenLayerConfig = {
      'terrain': {
        extension: 'jpg',
        opaque: true
      },
      'terrain-background': {
        extension: 'jpg',
        opaque: true
      },
      'terrain-labels': {
        extension: 'png',
        opaque: false
      },
      'terrain-lines': {
        extension: 'png',
        opaque: false
      },
      'toner-background': {
        extension: 'png',
        opaque: true
      },
      'toner': {
        extension: 'png',
        opaque: true
      },
      'toner-hybrid': {
        extension: 'png',
        opaque: false
      },
      'toner-labels': {
        extension: 'png',
        opaque: false
      },
      'toner-lines': {
        extension: 'png',
        opaque: false
      },
      'toner-lite': {
        extension: 'png',
        opaque: true
      },
      'watercolor': {
        extension: 'jpg',
        opaque: true
      }
    };

    /**
     * @type {Object.<string, {minZoom: number, maxZoom: number}>}
     */
    ol.source.StamenProviderConfig = {
      'terrain': {
        minZoom: 4,
        maxZoom: 18
      },
      'toner': {
        minZoom: 0,
        maxZoom: 20
      },
      'watercolor': {
        minZoom: 3,
        maxZoom: 16
      }
    };

    /**
     * @classdesc
     * Layer source for the Stamen tile server.
     *
     * @constructor
     * @extends {ol.source.XYZ}
     * @param {olx.source.StamenOptions} options Stamen options.
     * @api stable
     */
    ol.source.Stamen = function(options) {

      var i = options.layer.indexOf('-');
      var provider = i == -1 ? options.layer : options.layer.slice(0, i);
      goog.asserts.assert(provider in ol.source.StamenProviderConfig,
          'known provider configured');
      var providerConfig = ol.source.StamenProviderConfig[provider];

      goog.asserts.assert(options.layer in ol.source.StamenLayerConfig,
          'known layer configured');
      var layerConfig = ol.source.StamenLayerConfig[options.layer];

      var url = options.url !== undefined ? options.url :
          'https://stamen-tiles-{a-d}.a.ssl.fastly.net/' + options.layer +
          '/{z}/{x}/{y}.' + layerConfig.extension;

      goog.base(this, {
        attributions: ol.source.Stamen.ATTRIBUTIONS,
        crossOrigin: 'anonymous',
        maxZoom: providerConfig.maxZoom,
        // FIXME uncomment the following when tilegrid supports minZoom
        //minZoom: providerConfig.minZoom,
        opaque: layerConfig.opaque,
        reprojectionErrorThreshold: options.reprojectionErrorThreshold,
        tileLoadFunction: options.tileLoadFunction,
        url: url
      });

    };
    goog.inherits(ol.source.Stamen, ol.source.XYZ);

    /**
     * @const
     * @type {Array.<ol.Attribution>}
     */
    ol.source.Stamen.ATTRIBUTIONS = [
      new ol.Attribution({
        html: 'Map tiles by <a href="http://stamen.com/">Stamen Design</a>, ' +
            'under <a href="http://creativecommons.org/licenses/by/3.0/">CC BY' +
            ' 3.0</a>.'
      }),
      ol.source.OSM.ATTRIBUTION
    ];