Append dataviews related columns to layers
This commit is contained in:
parent
b787ee1033
commit
755dfe6822
@ -135,11 +135,15 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(analysisConfiguration
|
|||||||
var missingNodesErrors = [];
|
var missingNodesErrors = [];
|
||||||
|
|
||||||
requestMapConfig.layers = requestMapConfig.layers.map(function(layer, layerIndex) {
|
requestMapConfig.layers = requestMapConfig.layers.map(function(layer, layerIndex) {
|
||||||
if (layer.options.source && layer.options.source.id) {
|
if (getLayerSourceId(layer)) {
|
||||||
var layerSourceId = layer.options.source.id;
|
var layerSourceId = getLayerSourceId(layer);
|
||||||
var layerNode = sourceId2Node[layerSourceId];
|
var layerNode = sourceId2Node[layerSourceId];
|
||||||
if (layerNode) {
|
if (layerNode) {
|
||||||
layer.options.sql = layerQuery(layerNode.getQuery(), layerNode.getColumns());
|
layer.options.sql = layerQuery(layerNode.getQuery(), layerNode.getColumns());
|
||||||
|
var layerDataviews = getLayerDataviews(layer, dataviews);
|
||||||
|
layer.options.columns = layerDataviews.reduce(function(columns, dataview) {
|
||||||
|
return columns.concat(getDataviewColumns(dataview));
|
||||||
|
}, []);
|
||||||
} else {
|
} else {
|
||||||
missingNodesErrors.push(
|
missingNodesErrors.push(
|
||||||
new Error('Missing analysis node.id="' + layerSourceId +'" for layer='+layerIndex)
|
new Error('Missing analysis node.id="' + layerSourceId +'" for layer='+layerIndex)
|
||||||
@ -159,6 +163,45 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(analysisConfiguration
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getLayerSourceId(layer) {
|
||||||
|
return layer.options.source && layer.options.source.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDataviewSourceId(dataview) {
|
||||||
|
return dataview.source && dataview.source.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLayerDataviews(layer, dataviews) {
|
||||||
|
var layerDataviews = [];
|
||||||
|
|
||||||
|
var layerSourceId = getLayerSourceId(layer);
|
||||||
|
if (layerSourceId) {
|
||||||
|
var dataviewsList = getDataviewsList(dataviews);
|
||||||
|
dataviewsList.forEach(function(dataview) {
|
||||||
|
if (getDataviewSourceId(dataview) === layerSourceId) {
|
||||||
|
layerDataviews.push(dataview);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return layerDataviews;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDataviewColumns(dataview) {
|
||||||
|
var columns = [];
|
||||||
|
var options = dataview.options;
|
||||||
|
['column', 'aggregationColumn'].forEach(function(opt) {
|
||||||
|
if (options.hasOwnProperty(opt)) {
|
||||||
|
columns.push(options[opt]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDataviewsList(dataviews) {
|
||||||
|
return Object.keys(dataviews).map(function(dataviewKey) { return dataviews[dataviewKey]; });
|
||||||
|
}
|
||||||
|
|
||||||
function getDataviewsErrors(dataviews) {
|
function getDataviewsErrors(dataviews) {
|
||||||
var errors = [];
|
var errors = [];
|
||||||
|
|
||||||
|
14
npm-shrinkwrap.json
generated
14
npm-shrinkwrap.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "windshaft-cartodb",
|
"name": "windshaft-cartodb",
|
||||||
"version": "2.34.1",
|
"version": "2.34.2",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": {
|
"body-parser": {
|
||||||
"version": "1.14.2",
|
"version": "1.14.2",
|
||||||
@ -73,14 +73,14 @@
|
|||||||
},
|
},
|
||||||
"unpipe": {
|
"unpipe": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"from": "unpipe@1.0.0",
|
"from": "unpipe@>=1.0.0 <1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz"
|
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type-is": {
|
"type-is": {
|
||||||
"version": "1.6.12",
|
"version": "1.6.12",
|
||||||
"from": "type-is@>=1.6.10 <1.7.0",
|
"from": "type-is@>=1.6.6 <1.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.12.tgz",
|
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.12.tgz",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"media-typer": {
|
"media-typer": {
|
||||||
@ -111,7 +111,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": {
|
"async": {
|
||||||
"version": "1.5.2",
|
"version": "1.5.2",
|
||||||
"from": "async@>=1.5.2 <2.0.0",
|
"from": "async@>=1.0.0 <2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz"
|
"resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz"
|
||||||
},
|
},
|
||||||
"request": {
|
"request": {
|
||||||
@ -1291,9 +1291,9 @@
|
|||||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz"
|
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz"
|
||||||
},
|
},
|
||||||
"windshaft": {
|
"windshaft": {
|
||||||
"version": "1.17.3",
|
"version": "1.18.0",
|
||||||
"from": "windshaft@1.17.3",
|
"from": "windshaft@1.18.0",
|
||||||
"resolved": "https://registry.npmjs.org/windshaft/-/windshaft-1.17.3.tgz",
|
"resolved": "https://registry.npmjs.org/windshaft/-/windshaft-1.18.0.tgz",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"abaculus": {
|
"abaculus": {
|
||||||
"version": "1.1.0-cdb4",
|
"version": "1.1.0-cdb4",
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
"node-statsd": "~0.0.7",
|
"node-statsd": "~0.0.7",
|
||||||
"underscore" : "~1.6.0",
|
"underscore" : "~1.6.0",
|
||||||
"dot": "~1.0.2",
|
"dot": "~1.0.2",
|
||||||
"windshaft": "1.17.3",
|
"windshaft": "1.18.0",
|
||||||
"step": "~0.0.6",
|
"step": "~0.0.6",
|
||||||
"queue-async": "~1.0.7",
|
"queue-async": "~1.0.7",
|
||||||
"request": "~2.62.0",
|
"request": "~2.62.0",
|
||||||
|
81
test/acceptance/analysis/analysis-layers-geojson.js
Normal file
81
test/acceptance/analysis/analysis-layers-geojson.js
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
require('../../support/test_helper');
|
||||||
|
|
||||||
|
var assert = require('../../support/assert');
|
||||||
|
var TestClient = require('../../support/test-client');
|
||||||
|
|
||||||
|
describe('analysis-layers-dataviews-geojson', function() {
|
||||||
|
|
||||||
|
function createMapConfig(layers, dataviews, analysis) {
|
||||||
|
return {
|
||||||
|
version: '1.5.0',
|
||||||
|
layers: layers,
|
||||||
|
dataviews: dataviews || {},
|
||||||
|
analyses: analysis || []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var CARTOCSS = [
|
||||||
|
"#points {",
|
||||||
|
" marker-fill-opacity: 1.0;",
|
||||||
|
" marker-line-color: #FFF;",
|
||||||
|
" marker-line-width: 0.5;",
|
||||||
|
" marker-line-opacity: 1.0;",
|
||||||
|
" marker-placement: point;",
|
||||||
|
" marker-type: ellipse;",
|
||||||
|
" marker-width: 8;",
|
||||||
|
" marker-fill: red;",
|
||||||
|
" marker-allow-overlap: true;",
|
||||||
|
"}"
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
|
var mapConfig = createMapConfig(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "cartodb",
|
||||||
|
"options": {
|
||||||
|
"source": {
|
||||||
|
"id": "2570e105-7b37-40d2-bdf4-1af889598745"
|
||||||
|
},
|
||||||
|
"cartocss": CARTOCSS,
|
||||||
|
"cartocss_version": "2.3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
{
|
||||||
|
pop_max_histogram: {
|
||||||
|
source: {
|
||||||
|
id: '2570e105-7b37-40d2-bdf4-1af889598745'
|
||||||
|
},
|
||||||
|
type: 'histogram',
|
||||||
|
options: {
|
||||||
|
column: 'pop_max'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "2570e105-7b37-40d2-bdf4-1af889598745",
|
||||||
|
"type": "source",
|
||||||
|
"params": {
|
||||||
|
"query": "select * from populated_places_simple_reduced"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
it('should get pop_max column from dataview', function(done) {
|
||||||
|
var testClient = new TestClient(mapConfig, 1234);
|
||||||
|
|
||||||
|
testClient.getTile(0, 0, 0, {format: 'geojson', layers: 0}, function(err, res, geojson) {
|
||||||
|
assert.ok(!err, err);
|
||||||
|
|
||||||
|
assert.ok(Array.isArray(geojson.features));
|
||||||
|
assert.ok(geojson.features.length > 0);
|
||||||
|
var feature = geojson.features[0];
|
||||||
|
assert.ok(feature.properties.hasOwnProperty('pop_max'), 'Missing pop_max property');
|
||||||
|
|
||||||
|
testClient.drain(done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -313,13 +313,15 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) {
|
|||||||
assert.response(server, request, expectedResponse, function(res, err) {
|
assert.response(server, request, expectedResponse, function(res, err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
|
|
||||||
var image;
|
var obj;
|
||||||
|
|
||||||
if (isPng) {
|
if (isPng) {
|
||||||
image = mapnik.Image.fromBytes(new Buffer(res.body, 'binary'));
|
obj = mapnik.Image.fromBytes(new Buffer(res.body, 'binary'));
|
||||||
|
} else {
|
||||||
|
obj = JSON.parse(res.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
next(null, res, image);
|
next(null, res, obj);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function finish(err, res, image) {
|
function finish(err, res, image) {
|
||||||
|
Loading…
Reference in New Issue
Block a user