Dataviews adapter: skip layers not containing SQL or widgets
This commit is contained in:
@@ -14,6 +14,10 @@ DataviewsWidgetsMapConfigAdapter.prototype.getMapConfig = function(user, request
|
||||
requestMapConfig.dataviews = requestMapConfig.dataviews || {};
|
||||
|
||||
requestMapConfig.layers.forEach(function(layer, index) {
|
||||
if (!layer.options.widgets || !layer.options.sql) {
|
||||
return;
|
||||
}
|
||||
|
||||
var layerSourceId = getLayerSourceId(layer);
|
||||
var dataviewSourceId = layerSourceId || 'cdb-layer-source-' + index;
|
||||
// Append a new analysis if layer has no source id but sql.
|
||||
|
||||
@@ -218,6 +218,62 @@ describe('widgets', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with layers not containing sql', function(done) {
|
||||
var basemapUrl = "https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png";
|
||||
|
||||
var aggregationSumMapConfig = {
|
||||
version: '1.5.0',
|
||||
layers: [
|
||||
{
|
||||
type: 'mapnik',
|
||||
options: {
|
||||
sql: 'select * from populated_places_simple_reduced',
|
||||
cartocss: '#layer0 { marker-fill: red; marker-width: 10; }',
|
||||
cartocss_version: '2.0.1',
|
||||
widgets: {
|
||||
adm0name: {
|
||||
type: 'aggregation',
|
||||
options: {
|
||||
column: 'adm0name',
|
||||
aggregation: 'sum',
|
||||
aggregationColumn: 'pop_max'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "http",
|
||||
"options": {
|
||||
"urlTemplate": basemapUrl,
|
||||
"subdomains": "abcd"
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
this.testClient = new TestClient(aggregationSumMapConfig);
|
||||
this.testClient.getWidget('adm0name', { own_filter: 0 }, function (err, res, aggregation) {
|
||||
assert.ok(!err, err);
|
||||
assert.ok(aggregation);
|
||||
assert.equal(aggregation.type, 'aggregation');
|
||||
|
||||
assert.equal(aggregation.categories.length, 6);
|
||||
|
||||
assert.deepEqual(
|
||||
aggregation.categories[0],
|
||||
{ category: 'China', value: 374537585, agg: false }
|
||||
);
|
||||
|
||||
assert.deepEqual(
|
||||
aggregation.categories[aggregation.categories.length - 1],
|
||||
{ category: 'Other', value: 1412626289, agg: true }
|
||||
);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
var filteredCategoriesSumScenarios = [
|
||||
{ accept: [], values: [] },
|
||||
{ accept: ['Canada'], values: [23955084] },
|
||||
|
||||
Reference in New Issue
Block a user