Permalink
Browse files

Correct Stamen source

  • Loading branch information...
1 parent cae2340 commit 78780fa09538c5e4103edfc965f8e601519d5408 @twpayne twpayne committed with tschaub Mar 4, 2013
Showing with 82 additions and 77 deletions.
  1. +5 −2 src/objectliterals.exports
  2. +0 −20 src/ol/source/stamen.exports
  3. +77 −55 src/ol/source/stamensource.js
@@ -118,8 +118,11 @@
@exportObjectLiteralProperty ol.source.SourceOptions.projection ol.Projection|undefined
@exportObjectLiteral ol.source.StamenOptions
-@exportObjectLiteralProperty ol.source.StamenOptions.flavor string|undefined
-@exportObjectLiteralProperty ol.source.StamenOptions.provider string
+@exportObjectLiteralProperty ol.source.StamenOptions.layer string
+@exportObjectLiteralProperty ol.source.StamenOptions.minZoom number|undefined
+@exportObjectLiteralProperty ol.source.StamenOptions.maxZoom number|undefined
+@exportObjectLiteralProperty ol.source.StamenOptions.opaque boolean|undefined
+@exportObjectLiteralProperty ol.source.StamenOptions.url string|undefined
@exportObjectLiteral ol.source.StaticImageOptions
@exportObjectLiteralProperty ol.source.StaticImageOptions.attributions Array.<ol.Attribution>|undefined
@@ -1,21 +1 @@
@exportSymbol ol.source.Stamen
-
-@exportSymbol ol.source.StamenFlavor
-@exportProperty ol.source.StamenFlavor.TERRAIN_BACKGROUND
-@exportProperty ol.source.StamenFlavor.TERRAIN_LABELS
-@exportProperty ol.source.StamenFlavor.TERRAIN_LINES
-@exportProperty ol.source.StamenFlavor.TONER_2010
-@exportProperty ol.source.StamenFlavor.TONER_2011
-@exportProperty ol.source.StamenFlavor.TONER_2011_LABELS
-@exportProperty ol.source.StamenFlavor.TONER_2011_LINES
-@exportProperty ol.source.StamenFlavor.TONER_2011_LITE
-@exportProperty ol.source.StamenFlavor.TONER_BACKGROUND
-@exportProperty ol.source.StamenFlavor.TONER_HYBRID
-@exportProperty ol.source.StamenFlavor.TONER_LABELS
-@exportProperty ol.source.StamenFlavor.TONER_LINES
-@exportProperty ol.source.StamenFlavor.TONER_LITE
-
-@exportSymbol ol.source.StamenProvider
-@exportProperty ol.source.StamenProvider.TERRAIN
-@exportProperty ol.source.StamenProvider.TONER
-@exportProperty ol.source.StamenProvider.WATERCOLOR
@@ -1,71 +1,86 @@
-// FIXME Configure minZoom when supported by TileGrid
-
goog.provide('ol.source.Stamen');
-goog.provide('ol.source.StamenFlavor');
-goog.provide('ol.source.StamenProvider');
goog.require('ol.Attribution');
goog.require('ol.source.XYZ');
/**
- * @enum {string}
- */
-ol.source.StamenFlavor = {
- TERRAIN_BACKGROUND: 'background',
- TERRAIN_LABELS: 'labels',
- TERRAIN_LINES: 'lines',
- TONER_2010: '2010',
- TONER_2011: '2011',
- TONER_2011_LABELS: '2011-labels',
- TONER_2011_LINES: '2011-lines',
- TONER_2011_LITE: '2011-lite',
- TONER_BACKGROUND: 'background',
- TONER_HYBRID: 'hybrid',
- TONER_LABELS: 'labels',
- TONER_LINES: 'lines',
- TONER_LITE: 'lite'
-};
-
-
-/**
- * @enum {string}
+ * @type {Object.<string, {extension: string, opaque: boolean}>}
*/
-ol.source.StamenProvider = {
- TERRAIN: 'terrain',
- TONER: 'toner',
- WATERCOLOR: 'watercolor'
+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, {type: string, minZoom: number, maxZoom: number}>}
+ * @type {Object.<string, {minZoom: number, maxZoom: number}>}
*/
-ol.source.StamenProviderConfig = {};
-ol.source.StamenProviderConfig[ol.source.StamenProvider.TERRAIN] = {
- type: 'jpg',
- minZoom: 4,
- maxZoom: 18
-};
-ol.source.StamenProviderConfig[ol.source.StamenProvider.TONER] = {
- type: 'png',
- minZoom: 0,
- maxZoom: 20
-};
-ol.source.StamenProviderConfig[ol.source.StamenProvider.WATERCOLOR] = {
- type: 'jpg',
- minZoom: 3,
- maxZoom: 16
+ol.source.StamenProviderConfig = {
+ 'terrain': {
+ minZoom: 4,
+ maxZoom: 18
+ },
+ 'toner': {
+ minZoom: 0,
+ maxZoom: 20
+ },
+ 'watercolor': {
+ minZoom: 3,
+ maxZoom: 16
+ }
};
/**
* @constructor
* @extends {ol.source.XYZ}
- * @param {ol.source.StamenOptions} stamenOptions Stamen options.
+ * @param {ol.source.StamenOptions} options Options.
*/
-ol.source.Stamen = function(stamenOptions) {
+ol.source.Stamen = function(options) {
var attribution = new ol.Attribution(
'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ' +
@@ -75,18 +90,25 @@ ol.source.Stamen = function(stamenOptions) {
'under ' +
'<a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.');
- var layer = stamenOptions.provider;
- if (goog.isDef(stamenOptions.flavor)) {
- layer += '-' + stamenOptions.flavor;
- }
+ var i = options.layer.indexOf('-');
+ var provider = i == -1 ? options.layer : options.layer.slice(0, i);
+ goog.asserts.assert(provider in ol.source.StamenProviderConfig);
+ var providerConfig = ol.source.StamenProviderConfig[provider];
+
+ goog.asserts.assert(options.layer in ol.source.StamenLayerConfig);
+ var layerConfig = ol.source.StamenLayerConfig[options.layer];
- var config = ol.source.StamenProviderConfig[stamenOptions.provider];
+ var url = goog.isDef(options.url) ? options.url :
+ 'http://{a-d}.tile.stamen.com/' + options.layer + '/{z}/{x}/{y}.' +
+ layerConfig.extension;
goog.base(this, {
attributions: [attribution],
- maxZoom: config.maxZoom,
- opaque: false,
- url: 'http://{a-d}.tile.stamen.com/' + layer + '/{z}/{x}/{y}.' + config.type
+ maxZoom: providerConfig.maxZoom,
+ // FIXME uncomment the following when tilegrid supports minZoom
+ //minZoom: providerConfig.minZoom,
+ opaque: layerConfig.opaque,
+ url: url
});
};

0 comments on commit 78780fa

Please sign in to comment.