strips tilejson from windshaft specific stuff

This commit is contained in:
Francisco Dans 2015-09-22 11:42:57 +02:00
parent a88a0474d3
commit efa11680c4

View File

@ -361,33 +361,6 @@
return opts.maps_api_template.replace('{user}', user);
},
url: function () {
var opts = this.options;
var cdn_host = opts.cdn_url;
var has_empty_cdn = !cdn_host || (cdn_host && (!cdn_host.http && !cdn_host.https));
if (opts.no_cdn || has_empty_cdn) {
return this._tilerHost();
} else {
var protocol = this.isHttps() ? 'https': 'http';
var h = protocol + "://";
if (!this.isHttps()) {
h += "{s}.";
}
var cdn_url = cdn_host[protocol];
// build default template url if the cdn url is not templatized
// this is for backwards compatiblity, ideally we should use the url
// that tiler sends to us right away
if (!this._isUserTemplateUrl(cdn_url)) {
cdn_url = cdn_url + "/{user}";
}
var user = opts.user_name || opts.user;
h += cdn_url.replace('{user}', user)
return h;
}
},
_isUserTemplateUrl: function(t) {
return t && t.indexOf('{user}') !== -1;
},
@ -396,113 +369,23 @@
return this.options.maps_api_template.indexOf('https') === 0;
},
_generateCartoCSS: function() {
var attr = {
'-torque-frame-count': this.options.steps,
'-torque-resolution': this.options.resolution,
'-torque-aggregation-function': "'" + this.options.countby + "'",
'-torque-time-attribute': "'" + this.options.column + "'",
'-torque-data-aggregation': this.options.cumulative ? 'cumulative': 'linear',
};
var st = 'Map{';
for (var k in attr) {
st += k + ":" + attr[k] + ";";
}
return st + "}";
},
_fetchMap: function(callback) {
var self = this;
var layergroup = {};
var host = this.options.dynamic_cdn ? this.url().replace('{s}', '0'): this._tilerHost();
var url = host + "/api/v1/map";
var named = this.options.named_map;
var allParams = {};
if(named) {
//tiles/template
url = host + "/api/v1/map/named/" + named.name + "/jsonp";
if(typeof named.params !== "undefined"){
layergroup = named.params;
}
} else {
layergroup = {
"version": "1.0.1",
"stat_tag": this.options.stat_tag || 'torque',
"layers": [{
"type": "torque",
"options": {
"cartocss_version": "1.0.0",
"cartocss": this._generateCartoCSS(),
"sql": this.getSQL()
}
}]
};
}
if (this.options.stat_tag){
allParams["stat_tag"] = this.options.stat_tag;
}
extra = this._extraParams(allParams);
// tiler needs map_key instead of api_key
// so replace it
if (extra) {
extra = extra.replace('api_key=', 'map_key=');
}
url = url +
"?config=" + encodeURIComponent(JSON.stringify(layergroup)) +
"&callback=?" + (extra ? "&" + extra: '');
var map_instance_time = Profiler.metric('torque.provider.windshaft.layergroup.time').start();
if (this.options.tileJSON) {
torque.net.get(this.options.tileJSON, function (data) {
data = JSON.parse(data.response);
map_instance_time.end();
if (data) {
if (data.errors){
self.options.errorCallback && self.options.errorCallback(data.errors);
return;
}
for(var k in data) {
self.options[k] = data[k];
}
self.templateUrl = data.tiles[0];
self._setReady(true);
torque.net.get(this.options.tileJSON, function (data) {
data = JSON.parse(data.response);
if (data) {
if (data.errors){
self.options.errorCallback && self.options.errorCallback(data.errors);
return;
}
});
} else {
torque.net.jsonp(url, function (data) {
map_instance_time.end();
if (data) {
if (data.errors){
self.options.errorCallback && self.options.errorCallback(data.errors);
return;
}
else{
var torque_key = Object.keys(data.metadata.torque)[0]
var opt = data.metadata.torque[torque_key];
for(var k in opt) {
self.options[k] = opt[k];
}
// use cdn_url if present
if (data.cdn_url) {
var c = self.options.cdn_url = self.options.cdn_url || {};
c.http = data.cdn_url.http || c.http;
c.https = data.cdn_url.https || c.https;
}
self.templateUrl = self.url() + "/api/v1/map/" + data.layergroupid + "/" + torque_key + "/{z}/{x}/{y}.json.torque";
self._setReady(true);
}
} else {
Profiler.metric('torque.provider.windshaft.layergroup.error').inc();
}
}, { callbackName: self.options.instanciateCallback });
}
}
for(var k in data) {
self.options[k] = data[k];
}
self.templateUrl = data.tiles[0];
self._setReady(true);
}
});
}
};