@@ -12,6 +12,7 @@
|
||||
],
|
||||
"externs": [
|
||||
"externs/bingmaps.js",
|
||||
"externs/cartodb.js",
|
||||
"externs/bootstrap.js",
|
||||
"externs/closure-compiler.js",
|
||||
"externs/esrijson.js",
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"externs": [
|
||||
"externs/bingmaps.js",
|
||||
"externs/bootstrap.js",
|
||||
"externs/cartodb.js",
|
||||
"externs/closure-compiler.js",
|
||||
"externs/esrijson.js",
|
||||
"externs/example.js",
|
||||
|
||||
@@ -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
34
externs/cartodb.js
Normal 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;
|
||||
@@ -6210,7 +6210,8 @@ olx.source.XYZOptions.prototype.urls;
|
||||
olx.source.XYZOptions.prototype.wrapX;
|
||||
|
||||
/**
|
||||
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
|
||||
* @typedef {{attributions: (olx.source.AttributionOption|undefined),
|
||||
* cacheSize: (number|undefined),
|
||||
* crossOrigin: (null|string|undefined),
|
||||
* logo: (string|olx.LogoOptions|undefined),
|
||||
* projection: ol.proj.ProjectionLike,
|
||||
@@ -6219,7 +6220,7 @@ olx.source.XYZOptions.prototype.wrapX;
|
||||
* wrapX: (boolean|undefined),
|
||||
* config: (Object|undefined),
|
||||
* map: (string|undefined),
|
||||
* account: (string|undefined)}}
|
||||
* account: string}}
|
||||
* @api
|
||||
*/
|
||||
olx.source.CartoDBOptions;
|
||||
@@ -6227,12 +6228,20 @@ olx.source.CartoDBOptions;
|
||||
|
||||
/**
|
||||
* Attributions.
|
||||
* @type {Array.<ol.Attribution>|undefined}
|
||||
* @type {olx.source.AttributionOption|undefined}
|
||||
* @api stable
|
||||
*/
|
||||
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
|
||||
@@ -6269,6 +6278,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}
|
||||
@@ -6279,10 +6296,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 +6309,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
|
||||
|
||||
@@ -14,12 +14,41 @@ 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.<string, CartoDBLayerInfo>}
|
||||
* @private
|
||||
*/
|
||||
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_();
|
||||
};
|
||||
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) {
|
||||
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;
|
||||
@@ -111,6 +140,7 @@ ol.source.CartoDB.prototype.handleInitResponse_ = function(paramHash, event) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Event} event Event.
|
||||
@@ -119,14 +149,14 @@ 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.
|
||||
* @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);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user