cartodb/lib/assets/javascripts/builder/editor/map-operations/zoom-to-data.js

32 lines
788 B
JavaScript
Raw Normal View History

2020-06-15 10:58:47 +08:00
var cdb = require('internal-carto.js');
var ongoingQuery = false;
var zoomToData = function (configModel, stateModel, query) {
if (!configModel) throw new Error('configModel is required');
if (!stateModel) throw new Error('stateModel is required');
if (!query) throw new Error('query is required');
var queryLauncher = new cdb.SQL({
user: configModel.get('user_name'),
sql_api_template: configModel.get('sql_api_template'),
api_key: configModel.get('api_key')
});
if (!ongoingQuery) {
ongoingQuery = true;
queryLauncher.getBounds(query)
.done(function (bounds) {
ongoingQuery = false;
stateModel.setBounds(bounds);
})
.error(function () {
ongoingQuery = false;
});
}
};
module.exports = zoomToData;