Merge pull request #511 from CartoDB/dataview-the_geom-query
Dataview the geom query
This commit is contained in:
commit
1544a5622d
@ -16,6 +16,9 @@ var overviewsQueryRewriter = new OverviewsQueryRewriter({
|
|||||||
zoom_level: 'CDB_ZoomFromScale(!scale_denominator!)'
|
zoom_level: 'CDB_ZoomFromScale(!scale_denominator!)'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var dot = require('dot');
|
||||||
|
dot.templateSettings.strip = false;
|
||||||
|
|
||||||
function DataviewBackend(analysisBackend) {
|
function DataviewBackend(analysisBackend) {
|
||||||
this.analysisBackend = analysisBackend;
|
this.analysisBackend = analysisBackend;
|
||||||
}
|
}
|
||||||
@ -105,15 +108,7 @@ DataviewBackend.prototype.getDataview = function (mapConfigProvider, user, param
|
|||||||
var ownFilter = +params.own_filter;
|
var ownFilter = +params.own_filter;
|
||||||
ownFilter = !!ownFilter;
|
ownFilter = !!ownFilter;
|
||||||
|
|
||||||
var query;
|
var query = layerQuery(node, dataviewName, ownFilter);
|
||||||
|
|
||||||
if (ownFilter) {
|
|
||||||
query = node.getQuery();
|
|
||||||
} else {
|
|
||||||
var applyFilters = {};
|
|
||||||
applyFilters[dataviewName] = false;
|
|
||||||
query = node.getQuery(applyFilters);
|
|
||||||
}
|
|
||||||
|
|
||||||
var sourceId = dataviewDefinition.source.id; // node.id
|
var sourceId = dataviewDefinition.source.id; // node.id
|
||||||
var layer = _.find(
|
var layer = _.find(
|
||||||
@ -260,14 +255,7 @@ DataviewBackend.prototype.search = function (mapConfigProvider, user, params, ca
|
|||||||
var ownFilter = +params.own_filter;
|
var ownFilter = +params.own_filter;
|
||||||
ownFilter = !!ownFilter;
|
ownFilter = !!ownFilter;
|
||||||
|
|
||||||
var query;
|
var query = layerQuery(node, dataviewName, ownFilter);
|
||||||
if (ownFilter) {
|
|
||||||
query = node.getQuery();
|
|
||||||
} else {
|
|
||||||
var applyFilters = {};
|
|
||||||
applyFilters[dataviewName] = false;
|
|
||||||
query = node.getQuery(applyFilters);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params.bbox) {
|
if (params.bbox) {
|
||||||
var bboxFilter = new BBoxFilter({column: 'the_geom', srid: 4326}, {bbox: params.bbox});
|
var bboxFilter = new BBoxFilter({column: 'the_geom', srid: 4326}, {bbox: params.bbox});
|
||||||
@ -321,3 +309,31 @@ function dbParamsFromReqParams(params) {
|
|||||||
}
|
}
|
||||||
return dbParams;
|
return dbParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var SKIP_COLUMNS = {
|
||||||
|
'the_geom': true,
|
||||||
|
'the_geom_webmercator': true
|
||||||
|
};
|
||||||
|
|
||||||
|
function skipColumns(columnNames) {
|
||||||
|
return columnNames
|
||||||
|
.filter(function(columnName) { return !SKIP_COLUMNS[columnName]; });
|
||||||
|
}
|
||||||
|
|
||||||
|
var layerQueryTemplate = dot.template([
|
||||||
|
'SELECT {{=it._columns}}',
|
||||||
|
'FROM ({{=it._query}}) _cdb_analysis_query'
|
||||||
|
].join('\n'));
|
||||||
|
|
||||||
|
function layerQuery(node, dataviewName, ownFilter) {
|
||||||
|
var applyFilters = {};
|
||||||
|
if (!ownFilter) {
|
||||||
|
applyFilters[dataviewName] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.type === 'source') {
|
||||||
|
return node.getQuery(applyFilters);
|
||||||
|
}
|
||||||
|
var _columns = ['ST_Transform(the_geom, 3857) the_geom_webmercator'].concat(skipColumns(node.getColumns()));
|
||||||
|
return layerQueryTemplate({ _query: node.getQuery(applyFilters), _columns: _columns.join(', ') });
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user