2018-06-01 18:08:34 +08:00
|
|
|
function getVectorMapConfig(opts) {
|
|
|
|
return {
|
|
|
|
buffersize: {
|
|
|
|
mvt: 1
|
|
|
|
},
|
2018-06-05 16:10:56 +08:00
|
|
|
layers: _generateLayers(opts),
|
2018-06-05 14:58:44 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-05 16:10:56 +08:00
|
|
|
function _generateLayers(opts) {
|
|
|
|
const numberOfLayers = opts.numberOfLayers || 1;
|
|
|
|
const layers = [];
|
2018-06-12 01:30:48 +08:00
|
|
|
for (let index = 0; index < numberOfLayers; index++) {
|
|
|
|
const layerOptions = (opts.layerOptions || {})[index] || {};
|
|
|
|
layers.push(_generateLayerConfig(layerOptions));
|
2018-06-05 16:10:56 +08:00
|
|
|
}
|
|
|
|
return layers;
|
|
|
|
}
|
2018-06-05 14:58:44 +08:00
|
|
|
|
|
|
|
function _generateLayerConfig(opts) {
|
2018-06-18 19:14:17 +08:00
|
|
|
const additionalColumns = opts.additionalColumns ? opts.additionalColumns.join(',')+',' : '';
|
2018-06-05 14:58:44 +08:00
|
|
|
return {
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: `
|
|
|
|
SELECT
|
2018-06-18 19:14:17 +08:00
|
|
|
${additionalColumns}
|
2018-06-05 14:58:44 +08:00
|
|
|
(DATE '2018-06-01' + x) as date,
|
|
|
|
x as cartodb_id,
|
|
|
|
st_makepoint(x * 10, x * 10) as the_geom,
|
|
|
|
st_makepoint(x * 10, x * 10) as the_geom_webmercator
|
2018-06-18 19:14:17 +08:00
|
|
|
FROM
|
2018-06-05 14:58:44 +08:00
|
|
|
generate_series(0, 1) x`,
|
|
|
|
aggregation: {
|
|
|
|
columns: {},
|
|
|
|
dimensions: {
|
|
|
|
date: 'date'
|
|
|
|
},
|
|
|
|
placement: 'centroid',
|
|
|
|
resolution: 1,
|
|
|
|
threshold: 1
|
|
|
|
},
|
|
|
|
dates_as_numbers: opts.dates_as_numbers,
|
|
|
|
metadata: {
|
|
|
|
geometryType: true,
|
|
|
|
columnStats: {
|
|
|
|
topCategories: 32768,
|
|
|
|
includeNulls: true
|
|
|
|
},
|
|
|
|
sample: {
|
|
|
|
num_rows: 1000,
|
|
|
|
include_columns: [
|
|
|
|
'date'
|
|
|
|
]
|
2018-06-01 18:08:34 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-05 14:58:44 +08:00
|
|
|
}
|
2018-06-01 18:08:34 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = { getVectorMapConfig };
|