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); };