From c2749bbdd1b5526b86a67bd20204f15ffd4f6c04 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 1 Apr 2016 08:59:08 +0200 Subject: [PATCH 1/7] Fix olx.source.CartoDBOptions#attributions type --- externs/olx.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index 8348707365..22d6e28326 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -6210,7 +6210,7 @@ olx.source.XYZOptions.prototype.urls; olx.source.XYZOptions.prototype.wrapX; /** - * @typedef {{attributions: (Array.|undefined), + * @typedef {{attributions: (olx.source.AttributionOption|undefined), * crossOrigin: (null|string|undefined), * logo: (string|olx.LogoOptions|undefined), * projection: ol.proj.ProjectionLike, @@ -6227,7 +6227,7 @@ olx.source.CartoDBOptions; /** * Attributions. - * @type {Array.|undefined} + * @type {olx.source.AttributionOption|undefined} * @api stable */ olx.source.CartoDBOptions.prototype.attributions; From 24665747b365e0f17ec20572f9b6d308275c586d Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 1 Apr 2016 09:04:21 +0200 Subject: [PATCH 2/7] Fix cartodb links --- externs/olx.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index 22d6e28326..f3ddf4c7eb 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -6279,10 +6279,10 @@ olx.source.CartoDBOptions.prototype.wrapX; /** * If using anonymous maps, the CartoDB config to use. See - * {@link http://docs.cartodb.com/cartodb-platform/maps-api.html#anonymous-maps} + * {@link http://docs.cartodb.com/cartodb-platform/maps-api/anonymous-maps/} * for more detail. * If using named maps, a key-value lookup with the template parameters. - * See {@link http://docs.cartodb.com/cartodb-platform/maps-api.html#named-maps} + * See {@link http://docs.cartodb.com/cartodb-platform/maps-api/named-maps/} * for more detail. * @type {Object|undefined} * @api @@ -6292,7 +6292,7 @@ olx.source.CartoDBOptions.prototype.config; /** * If using named maps, this will be the name of the template to load. - * See {@link http://docs.cartodb.com/cartodb-platform/maps-api.html#named-maps} + * See {@link http://docs.cartodb.com/cartodb-platform/maps-api/named-maps/} * for more detail. * @type {string|undefined} * @api From fb6353a816b7757607320ad718a31e5f8cfbae31 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 1 Apr 2016 09:16:56 +0200 Subject: [PATCH 3/7] Fix olx.source.CartoDBOptions definition --- externs/olx.js | 10 +++++++++- src/ol/source/cartodb.js | 2 ++ test/spec/ol/source/cartodbsource.test.js | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/externs/olx.js b/externs/olx.js index f3ddf4c7eb..93613fe6d1 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -6219,7 +6219,7 @@ olx.source.XYZOptions.prototype.wrapX; * wrapX: (boolean|undefined), * config: (Object|undefined), * map: (string|undefined), - * account: (string|undefined)}} + * account: string}} * @api */ olx.source.CartoDBOptions; @@ -6269,6 +6269,14 @@ olx.source.CartoDBOptions.prototype.projection; olx.source.CartoDBOptions.prototype.maxZoom; +/** + * Minimum zoom. + * @type {number|undefined} + * @api + */ +olx.source.CartoDBOptions.prototype.minZoom; + + /** * Whether to wrap the world horizontally. Default is `true`. * @type {boolean|undefined} diff --git a/src/ol/source/cartodb.js b/src/ol/source/cartodb.js index afb9c8c262..2a8a0ae2f1 100644 --- a/src/ol/source/cartodb.js +++ b/src/ol/source/cartodb.js @@ -111,6 +111,7 @@ ol.source.CartoDB.prototype.handleInitResponse_ = function(paramHash, event) { } }; + /** * @private * @param {Event} event Event. @@ -119,6 +120,7 @@ ol.source.CartoDB.prototype.handleInitError_ = function(event) { this.setState(ol.source.State.ERROR); } + /** * Apply the new tile urls returned by carto db * @param {Object} data Result of carto db call. diff --git a/test/spec/ol/source/cartodbsource.test.js b/test/spec/ol/source/cartodbsource.test.js index 9f62f6981c..201d276d84 100644 --- a/test/spec/ol/source/cartodbsource.test.js +++ b/test/spec/ol/source/cartodbsource.test.js @@ -8,7 +8,7 @@ describe('ol.source.CartoDB', function() { describe('constructor', function() { it('returns a CartoDB source', function() { var source = new ol.source.CartoDB({ - map: 'example', + account: 'documentation', config: {} }); expect(source).to.be.a(ol.source.XYZ); From 13a0eb4ca7c33fc32e4d1484a0531482b63d74c1 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 1 Apr 2016 09:18:57 +0200 Subject: [PATCH 4/7] Add jsdoc tags in ol.source.CartoDB constructor --- src/ol/source/cartodb.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ol/source/cartodb.js b/src/ol/source/cartodb.js index 2a8a0ae2f1..9fdbd1355f 100644 --- a/src/ol/source/cartodb.js +++ b/src/ol/source/cartodb.js @@ -14,10 +14,31 @@ goog.require('ol.source.XYZ'); * @api */ ol.source.CartoDB = function(options) { + + /** + * @type {string} + * @private + */ this.account_ = options.account; + + /** + * @type {string} + * @private + */ this.mapId_ = options.map || ''; + + /** + * @type {Object} + * @private + */ this.config_ = options.config || {}; + + /** + * @type {Object.} + * @private + */ this.templateCache_ = {}; + delete options.map; goog.base(this, options); this.initializeMap_(); From 3f0de09dd72c5ce49046580467d78b5403b00a8e Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 1 Apr 2016 09:31:33 +0200 Subject: [PATCH 5/7] Fix ol.source.CartoDB goog.base params --- src/ol/source/cartodb.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ol/source/cartodb.js b/src/ol/source/cartodb.js index 9fdbd1355f..ebf1b77d8f 100644 --- a/src/ol/source/cartodb.js +++ b/src/ol/source/cartodb.js @@ -39,8 +39,15 @@ ol.source.CartoDB = function(options) { */ this.templateCache_ = {}; - delete options.map; - goog.base(this, options); + goog.base(this, { + attributions: options.attributions, + crossOrigin: options.crossOrigin, + logo: options.logo, + maxZoom: options.maxZoom !== undefined ? options.maxZoom : 18, + minZoom: options.minZoom, + projection: options.projection, + wrapX: options.wrapX + }); this.initializeMap_(); }; goog.inherits(ol.source.CartoDB, ol.source.XYZ); From b96de850446e2a6a392b04e92e88eeb7b89875ca Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 1 Apr 2016 09:44:18 +0200 Subject: [PATCH 6/7] Add cacheSize option to olx.source.CartoDBOptions --- externs/olx.js | 9 +++++++++ src/ol/source/cartodb.js | 1 + 2 files changed, 10 insertions(+) diff --git a/externs/olx.js b/externs/olx.js index 93613fe6d1..30907968f4 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -6211,6 +6211,7 @@ olx.source.XYZOptions.prototype.wrapX; /** * @typedef {{attributions: (olx.source.AttributionOption|undefined), + * cacheSize: (number|undefined), * crossOrigin: (null|string|undefined), * logo: (string|olx.LogoOptions|undefined), * projection: ol.proj.ProjectionLike, @@ -6233,6 +6234,14 @@ olx.source.CartoDBOptions; olx.source.CartoDBOptions.prototype.attributions; +/** + * Cache size. Default is `2048`. + * @type {number|undefined} + * @api + */ +olx.source.CartoDBOptions.prototype.cacheSize; + + /** * The `crossOrigin` attribute for loaded images. Note that you must provide a * `crossOrigin` value if you are using the WebGL renderer or if you want to diff --git a/src/ol/source/cartodb.js b/src/ol/source/cartodb.js index ebf1b77d8f..45f77f70fc 100644 --- a/src/ol/source/cartodb.js +++ b/src/ol/source/cartodb.js @@ -41,6 +41,7 @@ ol.source.CartoDB = function(options) { goog.base(this, { attributions: options.attributions, + cacheSize: options.cacheSize, crossOrigin: options.crossOrigin, logo: options.logo, maxZoom: options.maxZoom !== undefined ? options.maxZoom : 18, From e222409f50873d7465081e7440982635f845570e Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Fri, 1 Apr 2016 10:55:38 +0200 Subject: [PATCH 7/7] Add externs for CartoDB response --- config/example.json | 1 + config/examples-all.json | 1 + config/ol.json | 1 + externs/cartodb.js | 34 ++++++++++++++++++++++++++++++++++ src/ol/source/cartodb.js | 11 +++++------ 5 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 externs/cartodb.js diff --git a/config/example.json b/config/example.json index e5ac3aaf7b..8487b5159d 100644 --- a/config/example.json +++ b/config/example.json @@ -12,6 +12,7 @@ ], "externs": [ "externs/bingmaps.js", + "externs/cartodb.js", "externs/bootstrap.js", "externs/closure-compiler.js", "externs/esrijson.js", diff --git a/config/examples-all.json b/config/examples-all.json index 40d452b4b3..3eee28d504 100644 --- a/config/examples-all.json +++ b/config/examples-all.json @@ -13,6 +13,7 @@ "externs": [ "externs/bingmaps.js", "externs/bootstrap.js", + "externs/cartodb.js", "externs/closure-compiler.js", "externs/esrijson.js", "externs/example.js", diff --git a/config/ol.json b/config/ol.json index 37039fac71..eb542af685 100644 --- a/config/ol.json +++ b/config/ol.json @@ -4,6 +4,7 @@ "compile": { "externs": [ "externs/bingmaps.js", + "externs/cartodb.js", "externs/closure-compiler.js", "externs/esrijson.js", "externs/geojson.js", diff --git a/externs/cartodb.js b/externs/cartodb.js new file mode 100644 index 0000000000..7d3c15e029 --- /dev/null +++ b/externs/cartodb.js @@ -0,0 +1,34 @@ +/** + * @externs + */ + + + +/** + * @constructor + */ +var CartoDBLayerInfo = function() {}; + + +/** + * @type {string} + */ +CartoDBLayerInfo.prototype.layergroupid; + + +/** + * @type {string} + */ +CartoDBLayerInfo.prototype.updated_at; + + +/** + * @type {Object} + */ +CartoDBLayerInfo.prototype.metadata; + + +/** + * @type {{http: string, https: string}} + */ +CartoDBLayerInfo.prototype.cdn_url; diff --git a/src/ol/source/cartodb.js b/src/ol/source/cartodb.js index 45f77f70fc..9ff67ac463 100644 --- a/src/ol/source/cartodb.js +++ b/src/ol/source/cartodb.js @@ -34,7 +34,7 @@ ol.source.CartoDB = function(options) { this.config_ = options.config || {}; /** - * @type {Object.} + * @type {!Object.} * @private */ this.templateCache_ = {}; @@ -128,7 +128,7 @@ ol.source.CartoDB.prototype.handleInitResponse_ = function(paramHash, event) { if (client.status >= 200 && client.status < 300) { var response; try { - response = /** @type {Object} */(JSON.parse(client.responseText)); + response = /** @type {CartoDBLayerInfo} */(JSON.parse(client.responseText)); } catch (err) { this.setState(ol.source.State.ERROR); return; @@ -152,12 +152,11 @@ ol.source.CartoDB.prototype.handleInitError_ = function(event) { /** * Apply the new tile urls returned by carto db - * @param {Object} data Result of carto db call. + * @param {CartoDBLayerInfo} data Result of carto db call. * @private */ ol.source.CartoDB.prototype.applyTemplate_ = function(data) { - var layerId = data['layergroupid']; - var tilesUrl = 'https://' + data['cdn_url']['https'] + '/' + this.account_ + - '/api/v1/map/' + layerId + '/{z}/{x}/{y}.png'; + var tilesUrl = 'https://' + data.cdn_url.https + '/' + this.account_ + + '/api/v1/map/' + data.layergroupid + '/{z}/{x}/{y}.png'; this.setUrl(tilesUrl); };