cartodb-4.42/lib/assets/javascripts/builder/helpers/mapcard-preview.js

27 lines
872 B
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
var _ = require('underscore');
/**
* Mapcard preview url generator
*/
module.exports = {
urlForStaticMap: function (mapsApiTemplate, visualization, width, height) {
var formattedMapsApiTemplate = mapsApiTemplate.replace('{user}', visualization._permissionModel.get('owner').username);
var template = 'tpl_' + visualization.get('id').replace(/-/g, '_');
var imageUrl = formattedMapsApiTemplate + '/api/v1/map/static/named/' + template + '/' + width + '/' + height + '.png' + this._generateAuthTokensParams(visualization);
return imageUrl;
},
_generateAuthTokensParams: function (visualization) {
var authTokens = visualization.get('auth_tokens');
if (authTokens && authTokens.length > 0) {
return '?' + _.map(authTokens, function (t) {
return 'auth_token=' + t;
}).join('&');
} else {
return '';
}
}
};