Merge pull request #5152 from fredj/cartodb_cleanup

Cartodb cleanup
This commit is contained in:
Frédéric Junod
2016-04-04 09:38:41 +02:00
7 changed files with 98 additions and 14 deletions
+1
View File
@@ -12,6 +12,7 @@
], ],
"externs": [ "externs": [
"externs/bingmaps.js", "externs/bingmaps.js",
"externs/cartodb.js",
"externs/bootstrap.js", "externs/bootstrap.js",
"externs/closure-compiler.js", "externs/closure-compiler.js",
"externs/esrijson.js", "externs/esrijson.js",
+1
View File
@@ -13,6 +13,7 @@
"externs": [ "externs": [
"externs/bingmaps.js", "externs/bingmaps.js",
"externs/bootstrap.js", "externs/bootstrap.js",
"externs/cartodb.js",
"externs/closure-compiler.js", "externs/closure-compiler.js",
"externs/esrijson.js", "externs/esrijson.js",
"externs/example.js", "externs/example.js",
+1
View File
@@ -4,6 +4,7 @@
"compile": { "compile": {
"externs": [ "externs": [
"externs/bingmaps.js", "externs/bingmaps.js",
"externs/cartodb.js",
"externs/closure-compiler.js", "externs/closure-compiler.js",
"externs/esrijson.js", "externs/esrijson.js",
"externs/geojson.js", "externs/geojson.js",
+34
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;
+23 -6
View File
@@ -6210,7 +6210,8 @@ olx.source.XYZOptions.prototype.urls;
olx.source.XYZOptions.prototype.wrapX; olx.source.XYZOptions.prototype.wrapX;
/** /**
* @typedef {{attributions: (Array.<ol.Attribution>|undefined), * @typedef {{attributions: (olx.source.AttributionOption|undefined),
* cacheSize: (number|undefined),
* crossOrigin: (null|string|undefined), * crossOrigin: (null|string|undefined),
* logo: (string|olx.LogoOptions|undefined), * logo: (string|olx.LogoOptions|undefined),
* projection: ol.proj.ProjectionLike, * projection: ol.proj.ProjectionLike,
@@ -6219,7 +6220,7 @@ olx.source.XYZOptions.prototype.wrapX;
* wrapX: (boolean|undefined), * wrapX: (boolean|undefined),
* config: (Object|undefined), * config: (Object|undefined),
* map: (string|undefined), * map: (string|undefined),
* account: (string|undefined)}} * account: string}}
* @api * @api
*/ */
olx.source.CartoDBOptions; olx.source.CartoDBOptions;
@@ -6227,12 +6228,20 @@ olx.source.CartoDBOptions;
/** /**
* Attributions. * Attributions.
* @type {Array.<ol.Attribution>|undefined} * @type {olx.source.AttributionOption|undefined}
* @api stable * @api stable
*/ */
olx.source.CartoDBOptions.prototype.attributions; 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 * 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 * `crossOrigin` value if you are using the WebGL renderer or if you want to
@@ -6269,6 +6278,14 @@ olx.source.CartoDBOptions.prototype.projection;
olx.source.CartoDBOptions.prototype.maxZoom; 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`. * Whether to wrap the world horizontally. Default is `true`.
* @type {boolean|undefined} * @type {boolean|undefined}
@@ -6279,10 +6296,10 @@ olx.source.CartoDBOptions.prototype.wrapX;
/** /**
* If using anonymous maps, the CartoDB config to use. See * 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. * for more detail.
* If using named maps, a key-value lookup with the template parameters. * 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. * for more detail.
* @type {Object|undefined} * @type {Object|undefined}
* @api * @api
@@ -6292,7 +6309,7 @@ olx.source.CartoDBOptions.prototype.config;
/** /**
* If using named maps, this will be the name of the template to load. * 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. * for more detail.
* @type {string|undefined} * @type {string|undefined}
* @api * @api
+37 -7
View File
@@ -14,12 +14,41 @@ goog.require('ol.source.XYZ');
* @api * @api
*/ */
ol.source.CartoDB = function(options) { ol.source.CartoDB = function(options) {
/**
* @type {string}
* @private
*/
this.account_ = options.account; this.account_ = options.account;
/**
* @type {string}
* @private
*/
this.mapId_ = options.map || ''; this.mapId_ = options.map || '';
/**
* @type {Object}
* @private
*/
this.config_ = options.config || {}; this.config_ = options.config || {};
/**
* @type {!Object.<string, CartoDBLayerInfo>}
* @private
*/
this.templateCache_ = {}; this.templateCache_ = {};
delete options.map;
goog.base(this, options); goog.base(this, {
attributions: options.attributions,
cacheSize: options.cacheSize,
crossOrigin: options.crossOrigin,
logo: options.logo,
maxZoom: options.maxZoom !== undefined ? options.maxZoom : 18,
minZoom: options.minZoom,
projection: options.projection,
wrapX: options.wrapX
});
this.initializeMap_(); this.initializeMap_();
}; };
goog.inherits(ol.source.CartoDB, ol.source.XYZ); goog.inherits(ol.source.CartoDB, ol.source.XYZ);
@@ -99,7 +128,7 @@ ol.source.CartoDB.prototype.handleInitResponse_ = function(paramHash, event) {
if (client.status >= 200 && client.status < 300) { if (client.status >= 200 && client.status < 300) {
var response; var response;
try { try {
response = /** @type {Object} */(JSON.parse(client.responseText)); response = /** @type {CartoDBLayerInfo} */(JSON.parse(client.responseText));
} catch (err) { } catch (err) {
this.setState(ol.source.State.ERROR); this.setState(ol.source.State.ERROR);
return; return;
@@ -111,6 +140,7 @@ ol.source.CartoDB.prototype.handleInitResponse_ = function(paramHash, event) {
} }
}; };
/** /**
* @private * @private
* @param {Event} event Event. * @param {Event} event Event.
@@ -119,14 +149,14 @@ ol.source.CartoDB.prototype.handleInitError_ = function(event) {
this.setState(ol.source.State.ERROR); this.setState(ol.source.State.ERROR);
} }
/** /**
* Apply the new tile urls returned by carto db * 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 * @private
*/ */
ol.source.CartoDB.prototype.applyTemplate_ = function(data) { ol.source.CartoDB.prototype.applyTemplate_ = function(data) {
var layerId = data['layergroupid']; var tilesUrl = 'https://' + data.cdn_url.https + '/' + this.account_ +
var tilesUrl = 'https://' + data['cdn_url']['https'] + '/' + this.account_ + '/api/v1/map/' + data.layergroupid + '/{z}/{x}/{y}.png';
'/api/v1/map/' + layerId + '/{z}/{x}/{y}.png';
this.setUrl(tilesUrl); this.setUrl(tilesUrl);
}; };
+1 -1
View File
@@ -8,7 +8,7 @@ describe('ol.source.CartoDB', function() {
describe('constructor', function() { describe('constructor', function() {
it('returns a CartoDB source', function() { it('returns a CartoDB source', function() {
var source = new ol.source.CartoDB({ var source = new ol.source.CartoDB({
map: 'example', account: 'documentation',
config: {} config: {}
}); });
expect(source).to.be.a(ol.source.XYZ); expect(source).to.be.a(ol.source.XYZ);