Add externs for CartoDB response

This commit is contained in:
Frederic Junod
2016-04-01 10:55:38 +02:00
parent b96de85044
commit e222409f50
5 changed files with 42 additions and 6 deletions

View File

@@ -12,6 +12,7 @@
],
"externs": [
"externs/bingmaps.js",
"externs/cartodb.js",
"externs/bootstrap.js",
"externs/closure-compiler.js",
"externs/esrijson.js",

View File

@@ -13,6 +13,7 @@
"externs": [
"externs/bingmaps.js",
"externs/bootstrap.js",
"externs/cartodb.js",
"externs/closure-compiler.js",
"externs/esrijson.js",
"externs/example.js",

View File

@@ -4,6 +4,7 @@
"compile": {
"externs": [
"externs/bingmaps.js",
"externs/cartodb.js",
"externs/closure-compiler.js",
"externs/esrijson.js",
"externs/geojson.js",

34
externs/cartodb.js Normal file
View File

@@ -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;

View File

@@ -34,7 +34,7 @@ ol.source.CartoDB = function(options) {
this.config_ = options.config || {};
/**
* @type {Object.<string, Object>}
* @type {!Object.<string, CartoDBLayerInfo>}
* @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);
};