2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2017-12-04 19:40:53 +08:00
|
|
|
|
|
|
|
const assert = require('../support/assert');
|
|
|
|
const TestClient = require('../support/test-client');
|
2019-10-07 16:10:51 +08:00
|
|
|
const serverOptions = require('../../lib/server-options');
|
2017-12-04 19:40:53 +08:00
|
|
|
|
2019-09-13 22:32:37 +08:00
|
|
|
const WebMercatorHelper = require('cartodb-query-tables').utils.webMercatorHelper;
|
|
|
|
const webmercator = new WebMercatorHelper();
|
2019-07-03 22:13:54 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
const suites = [
|
2019-07-09 20:02:34 +08:00
|
|
|
{
|
|
|
|
desc: 'mvt (mapnik)',
|
|
|
|
usePostGIS: false
|
|
|
|
},
|
2019-02-22 15:31:22 +08:00
|
|
|
{
|
2017-12-04 19:40:53 +08:00
|
|
|
desc: 'mvt (postgis)',
|
|
|
|
usePostGIS: true
|
2019-02-22 15:31:22 +08:00
|
|
|
}
|
|
|
|
];
|
2017-12-04 19:40:53 +08:00
|
|
|
|
2018-10-08 04:46:02 +08:00
|
|
|
// Generate points with values and times.
|
|
|
|
// The point location is spanned over a given length, by default it is 0 so
|
|
|
|
// all points have the same location, which can be used to test aggregation dimensions
|
|
|
|
// the default point is in tile
|
2019-10-22 01:07:24 +08:00
|
|
|
function pointsWithTimeSQL (n, startTime, endTime, span = 0, x0 = 0.1, y0 = 0.1) {
|
2018-10-08 04:46:02 +08:00
|
|
|
return `
|
|
|
|
WITH params AS (
|
|
|
|
SELECT
|
|
|
|
'${startTime}'::timestamp with time zone AS min_t,
|
|
|
|
'${endTime}'::timestamp with time zone AS max_t,
|
|
|
|
${x0} AS x0, ${y0} AS y0,
|
|
|
|
${span} AS length,
|
|
|
|
${n} AS n
|
|
|
|
),
|
|
|
|
positions AS (
|
|
|
|
SELECT
|
|
|
|
step::float8/n AS s,
|
|
|
|
x0 + (step::float8/n - 0.5)*length AS x, y0 AS y
|
|
|
|
FROM params, generate_series(1, n) AS step
|
|
|
|
)
|
|
|
|
SELECT
|
|
|
|
row_number() over () AS cartodb_id,
|
|
|
|
n*10 AS value,
|
|
|
|
min_t + (max_t - min_t)*s AS date,
|
|
|
|
ST_SetSRID(ST_MakePoint(x, y), 4326) AS the_geom,
|
|
|
|
ST_Transform(ST_SetSRID(ST_MakePoint(x, y), 4326), 3857) AS the_geom_webmercator
|
|
|
|
FROM params, positions
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2017-12-04 19:40:53 +08:00
|
|
|
describe('aggregation', function () {
|
|
|
|
const POINTS_SQL_1 = `
|
|
|
|
select
|
2017-12-14 23:36:24 +08:00
|
|
|
x + 4 as cartodb_id,
|
2017-12-04 19:40:53 +08:00
|
|
|
st_setsrid(st_makepoint(x*10, x*10), 4326) as the_geom,
|
|
|
|
st_transform(st_setsrid(st_makepoint(x*10, x*10), 4326), 3857) as the_geom_webmercator,
|
|
|
|
x as value
|
|
|
|
from generate_series(-3, 3) x
|
|
|
|
`;
|
|
|
|
|
2018-07-11 16:33:58 +08:00
|
|
|
const POINTS_SQL_0 = `
|
|
|
|
select
|
|
|
|
x + 4 as cartodb_id,
|
|
|
|
st_setsrid(st_makepoint(x*10+1, x*10+1), 4326) as the_geom,
|
|
|
|
st_transform(st_setsrid(st_makepoint(x*10+1, x*10+1), 4326), 3857) as the_geom_webmercator,
|
|
|
|
x as value
|
|
|
|
from generate_series(-3, 3) x
|
|
|
|
`;
|
|
|
|
|
2017-12-14 21:14:55 +08:00
|
|
|
const POINTS_SQL_TIMESTAMP_1 = `
|
|
|
|
select
|
2017-12-14 23:36:24 +08:00
|
|
|
row_number() over() AS cartodb_id,
|
2017-12-14 21:14:55 +08:00
|
|
|
st_setsrid(st_makepoint(x*10, x*10), 4326) as the_geom,
|
|
|
|
st_transform(st_setsrid(st_makepoint(x*10, x*10), 4326), 3857) as the_geom_webmercator,
|
|
|
|
x as value,
|
|
|
|
date
|
|
|
|
from
|
|
|
|
generate_series(-3, 3) x,
|
|
|
|
generate_series(
|
|
|
|
'2007-02-15 01:00:00'::timestamp, '2007-02-18 01:00:00'::timestamp, '1 day'::interval
|
|
|
|
) date
|
|
|
|
`;
|
|
|
|
|
2017-12-04 19:40:53 +08:00
|
|
|
const POINTS_SQL_2 = `
|
|
|
|
select
|
2017-12-14 23:36:24 +08:00
|
|
|
x + 4 as cartodb_id,
|
2017-12-04 19:40:53 +08:00
|
|
|
st_setsrid(st_makepoint(x*10, x*10*(-1)), 4326) as the_geom,
|
|
|
|
st_transform(st_setsrid(st_makepoint(x*10, x*10*(-1)), 4326), 3857) as the_geom_webmercator,
|
2017-12-05 02:48:06 +08:00
|
|
|
x as value,
|
|
|
|
x*x as sqrt_value
|
2017-12-04 19:40:53 +08:00
|
|
|
from generate_series(-3, 3) x
|
|
|
|
`;
|
|
|
|
|
2019-03-06 05:17:04 +08:00
|
|
|
const POINTS_OVER_THRESHOLD = 'SELECT * FROM test_table_200k';
|
|
|
|
|
2017-12-12 00:32:06 +08:00
|
|
|
const POLYGONS_SQL_1 = `
|
2017-12-06 03:21:20 +08:00
|
|
|
select
|
2017-12-14 23:36:24 +08:00
|
|
|
x + 4 as cartodb_id,
|
2019-07-03 21:14:01 +08:00
|
|
|
st_buffer(st_setsrid(st_makepoint(x*10, x*10), 4326), 10) as the_geom,
|
2017-12-12 00:32:06 +08:00
|
|
|
st_transform(
|
2019-07-03 21:14:01 +08:00
|
|
|
st_buffer(st_setsrid(st_makepoint(x*10, x*10), 4326), 10),
|
2017-12-12 00:32:06 +08:00
|
|
|
3857
|
|
|
|
) as the_geom_webmercator,
|
|
|
|
x as value
|
2017-12-06 03:21:20 +08:00
|
|
|
from generate_series(-3, 3) x
|
|
|
|
`;
|
|
|
|
|
2017-12-13 23:34:36 +08:00
|
|
|
const SQL_WRAP = `
|
|
|
|
WITH hgrid AS (
|
|
|
|
SELECT
|
|
|
|
CDB_RectangleGrid (
|
2019-10-22 01:07:24 +08:00
|
|
|
ST_Expand(!bbox!, ${webmercator.getResolution({ z: 1 })} * 12),
|
|
|
|
${webmercator.getResolution({ z: 1 })} * 12,
|
|
|
|
${webmercator.getResolution({ z: 1 })} * 12
|
2017-12-13 23:34:36 +08:00
|
|
|
) as cell
|
|
|
|
)
|
|
|
|
SELECT
|
|
|
|
hgrid.cell as the_geom_webmercator,
|
|
|
|
count(1) as agg_value,
|
2019-10-22 01:07:24 +08:00
|
|
|
count(1) /power( 12 * ${webmercator.getResolution({ z: 1 })}, 2 ) as agg_value_density,
|
2017-12-13 23:34:36 +08:00
|
|
|
row_number() over () as cartodb_id
|
|
|
|
FROM hgrid, (<%= sql %>) i
|
|
|
|
WHERE ST_Intersects(i.the_geom_webmercator, hgrid.cell) GROUP BY hgrid.cell
|
|
|
|
`;
|
2017-12-12 00:32:06 +08:00
|
|
|
|
2017-12-14 02:46:35 +08:00
|
|
|
const TURBO_CARTOCSS_SQL_WRAP = `
|
|
|
|
#layer {
|
|
|
|
polygon-fill: ramp([agg_value], (#245668, #04817E, #39AB7E, #8BD16D, #EDEF5D), quantiles);
|
|
|
|
}
|
|
|
|
#layer::outline {
|
|
|
|
line-width: 1;
|
|
|
|
line-color: #FFFFFF;
|
|
|
|
line-opacity: 1;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2018-01-29 22:44:24 +08:00
|
|
|
const POINTS_SQL_ONLY_WEBMERCATOR = `
|
|
|
|
select
|
|
|
|
x + 4 as cartodb_id,
|
|
|
|
st_transform(st_setsrid(st_makepoint(x*10, x*10), 4326), 3857) as the_geom_webmercator,
|
|
|
|
x as value
|
|
|
|
from generate_series(-3, 3) x
|
|
|
|
`;
|
|
|
|
|
2018-05-13 19:05:39 +08:00
|
|
|
const POINTS_SQL_PAIRS = `
|
|
|
|
-- Generate pairs of near points
|
|
|
|
select
|
2018-07-11 22:47:10 +08:00
|
|
|
x + 1 as cartodb_id,
|
2018-07-11 22:56:37 +08:00
|
|
|
st_setsrid(
|
|
|
|
st_makepoint(
|
|
|
|
Floor((x-6)/2)*10 + 9E-3*(x % 2 + 1),
|
|
|
|
Floor((x-6)/2)*10 + 9E-3*(x % 2 + 1)
|
|
|
|
),
|
|
|
|
4326
|
|
|
|
) as the_geom,
|
2018-05-13 19:05:39 +08:00
|
|
|
st_transform(
|
2018-07-11 22:56:37 +08:00
|
|
|
st_setsrid(
|
|
|
|
st_makepoint(
|
|
|
|
Floor((x-6)/2)*10 + 9E-3*(x % 2 + 1),
|
|
|
|
Floor((x-6)/2)*10 + 9E-3*(x % 2 + 1)
|
|
|
|
),
|
|
|
|
4326
|
|
|
|
),
|
|
|
|
3857
|
|
|
|
) as the_geom_webmercator,
|
2018-05-13 19:05:39 +08:00
|
|
|
x as value
|
2018-07-11 22:47:10 +08:00
|
|
|
from generate_series(0, 13) x
|
2018-05-13 19:05:39 +08:00
|
|
|
`;
|
|
|
|
|
2018-07-16 04:15:57 +08:00
|
|
|
// Some points at corners and centers of aggregation grids (zoom=1, resolution=1)
|
|
|
|
// @ = point location
|
|
|
|
// --+---+---+---+---+---+---+--
|
|
|
|
// | | | | | | |
|
|
|
|
// --+---+---@---@---@---+---+--
|
|
|
|
// | | | @ | @ | | |
|
|
|
|
// --+---+---@---@---@---+---+--- Y = 0
|
|
|
|
// | | | @ | @ | | |
|
|
|
|
// --+---+---@---@---@---+---+--
|
|
|
|
// | | | | | | |
|
|
|
|
// --+---+---+---+---+---+---+--
|
|
|
|
// |
|
|
|
|
// X = 0
|
|
|
|
// Point identifiers (cartodb_id)
|
|
|
|
// --+---+---+---+---+---+---+--
|
|
|
|
// | | | | | | |
|
|
|
|
// --+---+---7---8---9---+---+--
|
|
|
|
// | | |12 |13 | | |
|
|
|
|
// --+---+---4---5---6---+---+---
|
|
|
|
// | | |10 |11 | | |
|
|
|
|
// --+---+---1---2---3---+---+--
|
|
|
|
// | | | | | | |
|
|
|
|
// --+---+---+---+---+---+---+--
|
|
|
|
// Point count per aggregation cell and Z=1 tiles
|
|
|
|
//
|
|
|
|
// Tile 0,0 -+---+---+---+- Tile 1,0
|
|
|
|
// | | | 1 | 1 | 1 | |
|
|
|
|
// --+---+---@---@---@---+---+--
|
|
|
|
// | | | 2 | 2 | 1 | |
|
|
|
|
// --+---+---@---@---@---+---+---
|
|
|
|
// | | | 2 | 2 | 1 | |
|
|
|
|
// --+---+---@---@---@---+---+--
|
|
|
|
// | | | | | | |
|
|
|
|
// Tile 0, 1 -+---+---+---+- Tile 1,1
|
|
|
|
//
|
2019-07-03 22:13:54 +08:00
|
|
|
const POINTS_SQL_GRID = (z, resolution) => `
|
2018-07-16 04:15:57 +08:00
|
|
|
WITH params AS (
|
2019-10-22 01:07:24 +08:00
|
|
|
SELECT ${webmercator.getResolution({ z: z })}*${resolution} AS l -- cell size for Z, resolution
|
2018-07-16 04:15:57 +08:00
|
|
|
)
|
|
|
|
SELECT
|
|
|
|
row_number() OVER () AS cartodb_id,
|
|
|
|
ST_SetSRID(ST_MakePoint(x*l, y*l), 3857) AS the_geom_webmercator,
|
|
|
|
ST_Transform(ST_SetSRID(ST_MakePoint(x*l, y*l), 3857), 4326) AS the_geom
|
|
|
|
FROM params, generate_series(-1,1) x, generate_series(-1,1) y
|
2018-07-17 18:42:33 +08:00
|
|
|
UNION ALL
|
2018-07-16 04:15:57 +08:00
|
|
|
SELECT
|
|
|
|
row_number() OVER () + 9 AS cartodb_id,
|
|
|
|
ST_SetSRID(ST_MakePoint(x*l-l/2, y*l-l/2), 3857) AS the_geom_webmercator,
|
|
|
|
ST_Transform(ST_SetSRID(ST_MakePoint(x*l-l/2, y*l-l/2), 3857), 4326) AS the_geom
|
|
|
|
FROM params, generate_series(0,1) x, generate_series(0,1) y
|
|
|
|
`;
|
2018-07-16 04:17:00 +08:00
|
|
|
|
|
|
|
// Points positioned inside one cell of Z=20, X=1000000, X=1000000 (the SW corner)
|
|
|
|
// The center of the cell is x = 18181005.874444414, y = -18181043.94366749
|
|
|
|
const POINTS_SQL_CELL = `
|
|
|
|
SELECT
|
|
|
|
1 AS cartodb_id,
|
2019-07-15 21:30:56 +08:00
|
|
|
ST_SetSRID(ST_MakePoint(18181005.82, -18181043.9), 3857) AS the_geom_webmercator,
|
|
|
|
ST_Transform(ST_SetSRID(ST_MakePoint(18181005.82, -18181043.9), 3857), 4326) AS the_geom
|
2018-07-17 18:42:33 +08:00
|
|
|
UNION ALL SELECT
|
2018-07-16 04:17:00 +08:00
|
|
|
2 AS cartodb_id,
|
|
|
|
ST_SetSRID(ST_MakePoint(18181005.9, -18181044.0), 3857) AS the_geom_webmercator,
|
|
|
|
ST_Transform(ST_SetSRID(ST_MakePoint(18181005.9, -18181044.0), 3857), 4326) AS the_geom
|
2018-07-17 18:42:33 +08:00
|
|
|
UNION ALL SELECT
|
2018-07-16 04:17:00 +08:00
|
|
|
3 AS cartodb_id,
|
|
|
|
ST_SetSRID(ST_MakePoint(18181005.87, -18181043.94), 3857) AS the_geom_webmercator,
|
|
|
|
ST_Transform(ST_SetSRID(ST_MakePoint(18181005.87, -18181043.94), 3857), 4326) AS the_geom
|
2018-07-17 18:42:33 +08:00
|
|
|
UNION ALL SELECT
|
2018-07-16 04:17:00 +08:00
|
|
|
4 AS cartodb_id,
|
2019-07-15 21:30:56 +08:00
|
|
|
ST_SetSRID(ST_MakePoint(18181005.82, -18181043.9), 3857) AS the_geom_webmercator,
|
|
|
|
ST_Transform(ST_SetSRID(ST_MakePoint(18181005.82, -18181043.9), 3857), 4326) AS the_geom
|
2018-07-16 04:17:00 +08:00
|
|
|
`;
|
|
|
|
|
|
|
|
// Points positioned inside one cell of Z=20, X=1000000, X=1000000 (inner cell not on border)
|
|
|
|
// The center of the cell is x = 18181006.023735486, y = -18181043.794376418
|
|
|
|
const POINTS_SQL_CELL_INNER = `
|
|
|
|
SELECT
|
|
|
|
1 AS cartodb_id,
|
|
|
|
ST_SetSRID(ST_MakePoint(18181005.95, -18181043.8), 3857) AS the_geom_webmercator,
|
|
|
|
ST_Transform(ST_SetSRID(ST_MakePoint(18181005.95, -18181043.8), 3857), 4326) AS the_geom
|
2018-07-17 18:42:33 +08:00
|
|
|
UNION ALL SELECT
|
2018-07-16 04:17:00 +08:00
|
|
|
2 AS cartodb_id,
|
2019-07-15 21:30:56 +08:00
|
|
|
ST_SetSRID(ST_MakePoint(18181006.09, -18181043.74), 3857) AS the_geom_webmercator,
|
|
|
|
ST_Transform(ST_SetSRID(ST_MakePoint(18181006.09, -18181043.74), 3857), 4326) AS the_geom
|
2018-07-17 18:42:33 +08:00
|
|
|
UNION ALL SELECT
|
2018-07-16 04:17:00 +08:00
|
|
|
3 AS cartodb_id,
|
|
|
|
ST_SetSRID(ST_MakePoint(18181006.02, -18181043.79), 3857) AS the_geom_webmercator,
|
|
|
|
ST_Transform(ST_SetSRID(ST_MakePoint(18181006.02, -18181043.79), 3857), 4326) AS the_geom
|
2018-07-17 18:42:33 +08:00
|
|
|
UNION ALL SELECT
|
2018-07-16 04:17:00 +08:00
|
|
|
4 AS cartodb_id,
|
|
|
|
ST_SetSRID(ST_MakePoint(18181006.01, -18181043.75), 3857) AS the_geom_webmercator,
|
|
|
|
ST_Transform(ST_SetSRID(ST_MakePoint(18181006.01, -18181043.75), 3857), 4326) AS the_geom
|
|
|
|
`;
|
|
|
|
|
2017-12-04 19:40:53 +08:00
|
|
|
function createVectorMapConfig (layers = [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_2,
|
|
|
|
aggregation: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]) {
|
|
|
|
return {
|
|
|
|
version: '1.6.0',
|
|
|
|
layers: layers
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
suites.forEach((suite) => {
|
|
|
|
const { desc, usePostGIS } = suite;
|
|
|
|
|
2017-12-06 00:44:52 +08:00
|
|
|
describe(desc, function () {
|
2017-12-04 19:40:53 +08:00
|
|
|
const originalUsePostGIS = serverOptions.renderer.mvt.usePostGIS;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = usePostGIS;
|
2018-05-13 19:05:39 +08:00
|
|
|
this.layerStatsConfig = global.environment.enabledFeatures.layerStats;
|
2017-12-04 19:40:53 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
after(function () {
|
2017-12-04 19:40:53 +08:00
|
|
|
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
2018-05-13 19:05:39 +08:00
|
|
|
global.environment.enabledFeatures.layerStats = this.layerStatsConfig;
|
2017-12-04 19:40:53 +08:00
|
|
|
});
|
|
|
|
|
2017-12-05 02:48:06 +08:00
|
|
|
it('should return a layergroup indicating the mapconfig was aggregated', function (done) {
|
2017-12-12 00:32:06 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_2,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
2017-12-05 02:48:06 +08:00
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
2017-12-04 19:40:53 +08:00
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2017-12-04 19:40:53 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
2017-12-05 23:52:15 +08:00
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
2017-12-06 03:21:20 +08:00
|
|
|
body.metadata.layers.forEach(layer => assert.ok(!layer.meta.aggregation.png));
|
2017-12-04 19:40:53 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-12-05 02:48:06 +08:00
|
|
|
|
2017-12-14 23:35:09 +08:00
|
|
|
it('should return a NOT aggregated layergroup', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
cartocss: '#layer { marker-width: [value]; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2017-12-14 23:35:09 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
body.metadata.layers.forEach(layer => assert.strictEqual(layer.meta.aggregation, undefined));
|
2017-12-14 23:35:09 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-05 02:48:06 +08:00
|
|
|
it('should return a layergroup with aggregation and cartocss compatible', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
columns: {
|
|
|
|
total: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
2017-12-12 00:32:06 +08:00
|
|
|
},
|
|
|
|
threshold: 1
|
2017-12-05 02:48:06 +08:00
|
|
|
},
|
2017-12-12 18:19:05 +08:00
|
|
|
cartocss: '#layer { marker-width: [total]; }',
|
2017-12-05 02:48:06 +08:00
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
2017-12-05 23:52:15 +08:00
|
|
|
this.testClient.getLayergroup((err, body) => {
|
2017-12-05 02:48:06 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2017-12-05 23:52:15 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
2017-12-06 03:21:20 +08:00
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.png));
|
2017-12-05 23:52:15 +08:00
|
|
|
|
2017-12-05 02:48:06 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-12 19:15:13 +08:00
|
|
|
it('should fail when aggregation and cartocss are not compatible', function (done) {
|
|
|
|
const response = {
|
|
|
|
status: 400,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
columns: {
|
|
|
|
total: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
threshold: 1
|
|
|
|
},
|
|
|
|
cartocss: '#layer { marker-width: [value]; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup({ response }, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2017-12-14 02:46:35 +08:00
|
|
|
assert.ok(body.errors[0].match(/column "value" does not exist/));
|
2017-12-12 19:15:13 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-05 23:52:15 +08:00
|
|
|
it('should fail if cartocss uses "value" column and it\'s not defined in the aggregation',
|
2019-10-22 01:07:24 +08:00
|
|
|
function (done) {
|
|
|
|
const response = {
|
|
|
|
status: 400,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
2017-12-05 02:48:06 +08:00
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
};
|
2017-12-22 18:31:33 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_2,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
placement: 'centroid'
|
|
|
|
},
|
|
|
|
cartocss: '#layer { marker-width: [value]; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
2017-12-22 18:31:33 +08:00
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
]);
|
2017-12-22 18:31:33 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup({ response }, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2017-12-22 18:31:33 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ok(body.errors[0].match(/column "value" does not exist/));
|
2017-12-22 18:31:33 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
done();
|
|
|
|
});
|
2017-12-22 18:31:33 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should provide all columns in the default aggregation ',
|
2018-04-04 22:58:11 +08:00
|
|
|
function (done) {
|
|
|
|
const response = {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_2,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#layer { marker-width: [value]; }',
|
2018-04-04 22:58:11 +08:00
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup({ response }, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2018-04-04 22:58:11 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.png));
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
['centroid', 'point-sample', 'point-grid'].forEach(placement => {
|
|
|
|
it('should provide all the requested columns in non-default aggregation: ' + placement,
|
|
|
|
function (done) {
|
|
|
|
const response = {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_2,
|
|
|
|
aggregation: {
|
|
|
|
placement: placement,
|
|
|
|
columns: {
|
|
|
|
first_column: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
dimensions: {
|
|
|
|
second_column: 'sqrt_value'
|
|
|
|
},
|
|
|
|
threshold: 1
|
2018-04-04 22:58:11 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#layer { marker-width: [first_column]; line-width: [second_column]; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2018-04-04 22:58:11 +08:00
|
|
|
}
|
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
]);
|
2018-04-04 22:58:11 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup({ response }, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-04-04 22:58:11 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
2018-04-04 22:58:11 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.png));
|
|
|
|
done();
|
2018-04-04 22:58:11 +08:00
|
|
|
});
|
2019-10-22 01:07:24 +08:00
|
|
|
});
|
2018-04-04 22:58:11 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should provide only the requested columns in non-default aggregation: ' + placement,
|
|
|
|
function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_2,
|
|
|
|
aggregation: {
|
|
|
|
placement: placement,
|
|
|
|
columns: {
|
|
|
|
first_column: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
dimensions: {
|
|
|
|
second_column: 'sqrt_value'
|
|
|
|
},
|
|
|
|
threshold: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
this.testClient.getTile(0, 0, 0, { format: 'mvt' }, function (err, res, mvt) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const geojsonTile = JSON.parse(mvt.toGeoJSONSync(0));
|
|
|
|
let columns = new Set();
|
|
|
|
geojsonTile.features.forEach(f => {
|
|
|
|
Object.keys(f.properties).forEach(p => columns.add(p));
|
|
|
|
});
|
|
|
|
columns = Array.from(columns);
|
|
|
|
const expected_columns = [
|
|
|
|
'_cdb_feature_count', 'cartodb_id', 'first_column', 'second_column'
|
|
|
|
];
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(columns.sort(), expected_columns.sort());
|
2019-10-22 01:07:24 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2018-04-04 22:58:11 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-05 19:59:32 +08:00
|
|
|
it('should skip aggregation to create a layergroup with aggregation defined already', function (done) {
|
|
|
|
const mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
columns: {
|
|
|
|
total: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
2017-12-13 02:23:21 +08:00
|
|
|
},
|
|
|
|
threshold: 1
|
2017-12-05 19:59:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(mapConfig);
|
|
|
|
const options = { aggregation: false };
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2017-12-05 19:59:32 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
body.metadata.layers.forEach(layer => assert.strictEqual(layer.meta.aggregation, undefined));
|
2017-12-13 02:23:21 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-03 19:40:00 +08:00
|
|
|
it('skip default aggregation by setting `aggregation: false` for just one layer', function (done) {
|
|
|
|
const mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2019-03-06 05:17:04 +08:00
|
|
|
// Note that we need the table to have more than AggregationMapConfig.THRESHOLD rows
|
|
|
|
// otherwise it won't get aggregated in any case
|
|
|
|
sql: POINTS_OVER_THRESHOLD,
|
2018-01-03 19:40:00 +08:00
|
|
|
aggregation: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(mapConfig);
|
|
|
|
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2018-01-03 19:40:00 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(body.metadata.layers[0].meta.aggregation.mvt, true);
|
|
|
|
assert.strictEqual(body.metadata.layers[1].meta.aggregation.mvt, false);
|
2018-01-03 19:40:00 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-06 22:28:38 +08:00
|
|
|
it('use default aggregation by setting `aggregation: true`', function (done) {
|
|
|
|
const mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_OVER_THRESHOLD,
|
|
|
|
cartocss: '#layer { marker-width: 7; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
aggregation: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(mapConfig);
|
|
|
|
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2019-03-06 22:28:38 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(body.metadata.layers[0].meta.aggregation.mvt, true);
|
|
|
|
assert.strictEqual(body.metadata.layers[0].meta.aggregation.png, true);
|
2019-03-06 22:28:38 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('but do not aggregate below threshold by setting `aggregation: true`', function (done) {
|
|
|
|
const mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_2,
|
|
|
|
cartocss: '#layer { marker-width: 7; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
aggregation: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(mapConfig);
|
|
|
|
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2019-03-06 22:28:38 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(body.metadata.layers[0].meta.aggregation.mvt, false);
|
|
|
|
assert.strictEqual(body.metadata.layers[0].meta.aggregation.png, false);
|
2019-03-06 22:28:38 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-13 02:23:21 +08:00
|
|
|
it('when the aggregation param is not valid should respond with error', function (done) {
|
|
|
|
const mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(mapConfig);
|
|
|
|
const options = {
|
|
|
|
response: {
|
|
|
|
status: 400
|
|
|
|
},
|
|
|
|
aggregation: 'wadus'
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, {
|
2017-12-13 02:23:21 +08:00
|
|
|
errors: [
|
|
|
|
"Invalid value for 'aggregation' query param: wadus." +
|
|
|
|
" Valid ones are 'true' or 'false'"
|
|
|
|
],
|
2019-10-22 01:07:24 +08:00
|
|
|
errors_with_context: [{
|
2017-12-13 02:23:21 +08:00
|
|
|
type: 'unknown',
|
|
|
|
message: "Invalid value for 'aggregation' query param: wadus." +
|
|
|
|
" Valid ones are 'true' or 'false'"
|
|
|
|
}]
|
|
|
|
});
|
2017-12-05 19:59:32 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-12-06 03:21:20 +08:00
|
|
|
|
2017-12-12 00:32:06 +08:00
|
|
|
it('when the layer\'s row count is lower than threshold should skip aggregation', function (done) {
|
|
|
|
const mapConfig = createVectorMapConfig([
|
2017-12-06 03:21:20 +08:00
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2017-12-12 00:32:06 +08:00
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
columns: {
|
|
|
|
total: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
threshold: 1001
|
|
|
|
}
|
2017-12-06 03:21:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2017-12-12 00:32:06 +08:00
|
|
|
this.testClient = new TestClient(mapConfig);
|
|
|
|
const options = {};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
2017-12-06 03:21:20 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2017-12-06 03:21:20 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
body.metadata.layers.forEach(layer => {
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(layer.meta.aggregation, { png: false, mvt: false });
|
2017-12-12 00:32:06 +08:00
|
|
|
});
|
2017-12-06 03:21:20 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-13 02:23:21 +08:00
|
|
|
it('when the layer\'s geometry type is not point should respond with error', function (done) {
|
2017-12-12 00:32:06 +08:00
|
|
|
const mapConfig = createVectorMapConfig([
|
2017-12-06 03:21:20 +08:00
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2017-12-12 00:32:06 +08:00
|
|
|
sql: POLYGONS_SQL_1,
|
2018-01-03 19:00:25 +08:00
|
|
|
cartocss: '#layer { marker-width: [value]; }',
|
|
|
|
cartocss_version: '2.3.0',
|
2017-12-12 00:32:06 +08:00
|
|
|
aggregation: {
|
|
|
|
threshold: 1
|
|
|
|
}
|
2017-12-06 03:21:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2017-12-12 00:32:06 +08:00
|
|
|
this.testClient = new TestClient(mapConfig);
|
|
|
|
const options = {
|
|
|
|
response: {
|
|
|
|
status: 400
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
2017-12-06 03:21:20 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, {
|
2017-12-12 00:32:06 +08:00
|
|
|
errors: [
|
2017-12-12 19:39:12 +08:00
|
|
|
'Unsupported geometry type: ST_Polygon.' +
|
|
|
|
' Aggregation is available only for geometry type: ST_Point'
|
2017-12-12 00:32:06 +08:00
|
|
|
],
|
2019-10-22 01:07:24 +08:00
|
|
|
errors_with_context: [{
|
2017-12-19 02:35:12 +08:00
|
|
|
type: 'layer',
|
2017-12-12 19:39:12 +08:00
|
|
|
message: 'Unsupported geometry type: ST_Polygon.' +
|
2017-12-19 02:35:12 +08:00
|
|
|
' Aggregation is available only for geometry type: ST_Point',
|
|
|
|
layer: {
|
|
|
|
id: 'layer0',
|
|
|
|
index: 0,
|
|
|
|
type: 'mapnik'
|
|
|
|
}
|
2017-12-12 00:32:06 +08:00
|
|
|
}]
|
|
|
|
});
|
2017-12-06 03:21:20 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-12-13 23:34:36 +08:00
|
|
|
|
|
|
|
it('when sql_wrap is provided should return a layergroup', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql_wrap: SQL_WRAP,
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1
|
2017-12-14 02:46:35 +08:00
|
|
|
},
|
|
|
|
cartocss: TURBO_CARTOCSS_SQL_WRAP,
|
|
|
|
cartocss_version: '3.0.12'
|
2017-12-13 23:34:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2017-12-13 23:34:36 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
2017-12-14 02:46:35 +08:00
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.png));
|
2017-12-13 23:34:36 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-12-14 00:01:43 +08:00
|
|
|
|
|
|
|
it('when sql_wrap is provided should return a tile', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql_wrap: SQL_WRAP,
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1
|
|
|
|
},
|
2017-12-14 02:46:35 +08:00
|
|
|
cartocss: TURBO_CARTOCSS_SQL_WRAP,
|
|
|
|
cartocss_version: '3.0.12'
|
2017-12-14 00:01:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
this.testClient.getTile(0, 0, 0, {}, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-12-14 21:14:55 +08:00
|
|
|
|
2017-12-20 21:41:29 +08:00
|
|
|
it('when dimensions is provided should return a tile returning the column used as dimensions',
|
2019-10-22 01:07:24 +08:00
|
|
|
function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
|
|
|
value: 'value'
|
|
|
|
}
|
2017-12-20 21:35:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
]);
|
2017-12-20 21:35:47 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2017-12-20 21:35:47 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
const tileJSON = tile.toJSON();
|
2017-12-20 21:35:47 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
tileJSON[0].features.forEach(feature => assert.strictEqual(typeof feature.properties.value, 'number'));
|
2017-12-20 21:35:47 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
done();
|
|
|
|
});
|
2017-12-20 21:35:47 +08:00
|
|
|
});
|
|
|
|
|
2018-10-07 06:29:12 +08:00
|
|
|
it('time dimensions', function (done) {
|
2018-09-21 03:12:54 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_TIMESTAMP_1,
|
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
|
|
|
dow: {
|
|
|
|
column: 'date',
|
2018-10-07 06:29:12 +08:00
|
|
|
group: {
|
|
|
|
units: 'dayOfWeek'
|
|
|
|
}
|
2018-09-21 03:12:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
tileJSON[0].features.forEach(feature => assert.strictEqual(typeof feature.properties.dow, 'number'));
|
2018-09-21 03:12:54 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-08 04:46:02 +08:00
|
|
|
it('aggregation dimensions only used if present', function (done) {
|
2018-10-09 01:16:32 +08:00
|
|
|
const nPoints = 50;
|
2018-10-08 04:46:02 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2018-10-09 01:16:32 +08:00
|
|
|
sql: pointsWithTimeSQL(nPoints, '2000-01-01T00:00:00+00', '2019-12-31T23:59:59+00', 0),
|
2018-10-08 04:46:02 +08:00
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
threshold: 1
|
2018-10-08 04:46:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tileJSON = tile.toJSON();
|
2018-10-09 01:16:32 +08:00
|
|
|
// Everything's aggregated into a single feature because the only
|
|
|
|
// dimension is space and all points are in the same place.
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(tileJSON[0].features.map(f => f.properties._cdb_feature_count), [nPoints]);
|
2018-10-08 04:46:02 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-09 01:16:32 +08:00
|
|
|
it('aggregation dimension year used', function (done) {
|
|
|
|
const nPoints = 50;
|
2018-10-08 04:46:02 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2018-10-09 01:16:32 +08:00
|
|
|
sql: pointsWithTimeSQL(nPoints, '2000-01-01T00:00:00+00', '2019-12-31T23:59:59+00', 0),
|
2018-10-08 04:46:02 +08:00
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
2018-10-09 01:16:32 +08:00
|
|
|
year: {
|
2018-10-08 04:46:02 +08:00
|
|
|
column: 'date',
|
|
|
|
group: {
|
2018-10-09 01:16:32 +08:00
|
|
|
units: 'year'
|
2018-10-08 04:46:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
2018-10-08 04:46:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tileJSON = tile.toJSON();
|
2018-10-09 01:16:32 +08:00
|
|
|
// Now all features have same location, but the year is an additional dimension
|
|
|
|
// with 20 different values, so we'll have an aggregated feature for each.
|
2019-10-22 01:07:24 +08:00
|
|
|
const expectedYears = Array.from({ length: 20 }, (_, k) => 2000 + k); // 2000 to 2019
|
2018-10-09 01:16:32 +08:00
|
|
|
const resultYears = tileJSON[0].features.map(f => f.properties.year).sort((a, b) => a - b);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(resultYears, expectedYears);
|
2018-10-08 04:46:02 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('aggregation dimension month with count', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: pointsWithTimeSQL(50, '2018-01-01T00:00:00+00', '2018-12-31T23:59:59+00', 0),
|
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
|
|
|
month: {
|
|
|
|
column: 'date',
|
|
|
|
group: {
|
|
|
|
units: 'month',
|
|
|
|
count: 5,
|
|
|
|
starting: '2018-01'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
2018-10-08 04:46:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tileJSON = tile.toJSON();
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tileJSON[0].features.length, 3);
|
2018-10-08 04:46:02 +08:00
|
|
|
const resultQuimesters = tileJSON[0].features.map(f => f.properties.month).sort((a, b) => a - b);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(resultQuimesters, [1, 2, 3]);
|
2018-10-08 04:46:02 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('aggregation dimension month with starting', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: pointsWithTimeSQL(50, '2018-01-01T00:00:00+00', '2018-12-31T23:59:59+00', 0),
|
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
|
|
|
month: {
|
|
|
|
column: 'date',
|
|
|
|
group: {
|
|
|
|
units: 'month',
|
|
|
|
starting: '2017-01'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
const resultMonths = tileJSON[0].features.map(f => f.properties.month).sort((a, b) => a - b);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(resultMonths, [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]);
|
2018-10-08 04:46:02 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('aggregation dimension month by default UTC', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: pointsWithTimeSQL(50, '2018-01-01T00:00:00+00', '2018-01-31T23:59:59+00', 0),
|
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
|
|
|
dow: {
|
|
|
|
column: 'date',
|
|
|
|
group: {
|
|
|
|
units: 'month',
|
|
|
|
timezone: '+00'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
// In UTC all times are in the same month 2018-01
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tileJSON[0].features.length, 1);
|
2018-10-08 04:46:02 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('aggregation dimension month with timezone', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: pointsWithTimeSQL(50, '2018-01-01T00:00:00+00', '2018-01-31T23:59:59+00', 0),
|
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
|
|
|
dow: {
|
|
|
|
column: 'date',
|
|
|
|
group: {
|
|
|
|
units: 'month',
|
|
|
|
timezone: '+7200'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
// In UTC+2 some times are in a different month
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tileJSON[0].features.length, 2);
|
2018-10-08 04:46:02 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-10-07 06:29:12 +08:00
|
|
|
|
|
|
|
it('time dimensions stats', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_TIMESTAMP_1,
|
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
|
|
|
dow: {
|
|
|
|
column: 'date',
|
|
|
|
group: {
|
|
|
|
units: 'dayOfWeek'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
metadata: {
|
|
|
|
dimensions: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
2018-09-21 03:12:54 +08:00
|
|
|
|
2018-10-07 06:29:12 +08:00
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getLayergroup(function (err, layergroup) {
|
2018-10-07 06:29:12 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
const expectedDimensions = {
|
|
|
|
dow:
|
2019-10-22 01:07:24 +08:00
|
|
|
{
|
|
|
|
params:
|
|
|
|
{
|
|
|
|
time: 'to_timestamp("date")',
|
|
|
|
timezone: 'utc',
|
|
|
|
units: 'dayOfWeek',
|
|
|
|
count: 1
|
|
|
|
},
|
|
|
|
min: 4,
|
|
|
|
max: 7,
|
|
|
|
type: 'number'
|
|
|
|
}
|
2018-10-07 06:29:12 +08:00
|
|
|
};
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(layergroup.metadata.layers[0].meta.stats.dimensions, expectedDimensions);
|
2018-10-07 17:35:28 +08:00
|
|
|
done();
|
2018-10-07 06:29:12 +08:00
|
|
|
});
|
|
|
|
});
|
2018-09-21 03:12:54 +08:00
|
|
|
|
2018-10-08 04:46:02 +08:00
|
|
|
it('no time dimensions stats by default', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_TIMESTAMP_1,
|
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
|
|
|
dow: {
|
|
|
|
column: 'date',
|
|
|
|
group: {
|
|
|
|
units: 'dayOfWeek'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getLayergroup(function (err, layergroup) {
|
2018-10-08 04:46:02 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
assert(!layergroup.metadata.layers[0].meta.stats.dimensions);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('aggregation dimension month iso format', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: pointsWithTimeSQL(50, '2018-01-01T00:00:00+00', '2018-12-31T23:59:59+00', 0),
|
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
|
|
|
month: {
|
|
|
|
column: 'date',
|
|
|
|
group: {
|
2019-10-22 01:07:24 +08:00
|
|
|
units: 'month'
|
2018-10-08 04:46:02 +08:00
|
|
|
},
|
|
|
|
format: 'iso'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
const resultMonths = tileJSON[0].features.map(f => f.properties.month).sort();
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(resultMonths, [
|
2019-10-22 01:07:24 +08:00
|
|
|
'2018-01', '2018-02', '2018-03', '2018-04', '2018-05', '2018-06',
|
2018-10-08 04:46:02 +08:00
|
|
|
'2018-07', '2018-08', '2018-09', '2018-10', '2018-11', '2018-12'
|
|
|
|
]);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('aggregation dimension month iso format with timezone', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: pointsWithTimeSQL(50, '2018-01-01T00:00:00+00', '2018-12-31T23:59:59+00', 0),
|
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
|
|
|
month: {
|
|
|
|
column: 'date',
|
|
|
|
group: {
|
|
|
|
units: 'month',
|
|
|
|
timezone: '+7200'
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
format: 'iso'
|
2018-10-08 04:46:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
const resultMonths = tileJSON[0].features.map(f => f.properties.month).sort();
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(resultMonths, [
|
2018-10-08 04:46:02 +08:00
|
|
|
'2018-01', '2018-02', '2018-03', '2018-04', '2018-05', '2018-06',
|
|
|
|
'2018-07', '2018-08', '2018-09', '2018-10', '2018-11', '2018-12',
|
|
|
|
'2019-01'
|
|
|
|
]);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-31 19:39:06 +08:00
|
|
|
it('aggregation dimension hour iso format with timezone', function (done) {
|
2018-10-31 19:00:40 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2018-10-31 19:02:23 +08:00
|
|
|
// take four points per hour over two days
|
2018-10-31 19:00:40 +08:00
|
|
|
sql: pointsWithTimeSQL(96, '2018-01-01T00:00:00+02', '2018-01-01T23:59:59+02', 0),
|
|
|
|
dates_as_numbers: true,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
|
|
|
hour: {
|
|
|
|
column: 'date',
|
|
|
|
group: {
|
|
|
|
units: 'hour',
|
|
|
|
timezone: '+7200'
|
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
format: 'iso'
|
2018-10-31 19:00:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
const resultHours = tileJSON[0].features.map(f => f.properties.hour).sort();
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(resultHours, [
|
2019-10-22 01:07:24 +08:00
|
|
|
'2018-01-01T00',
|
|
|
|
'2018-01-01T01',
|
|
|
|
'2018-01-01T02',
|
|
|
|
'2018-01-01T03',
|
|
|
|
'2018-01-01T04',
|
|
|
|
'2018-01-01T05',
|
|
|
|
'2018-01-01T06',
|
|
|
|
'2018-01-01T07',
|
|
|
|
'2018-01-01T08',
|
|
|
|
'2018-01-01T09',
|
|
|
|
'2018-01-01T10',
|
|
|
|
'2018-01-01T11',
|
|
|
|
'2018-01-01T12',
|
|
|
|
'2018-01-01T13',
|
|
|
|
'2018-01-01T14',
|
|
|
|
'2018-01-01T15',
|
|
|
|
'2018-01-01T16',
|
|
|
|
'2018-01-01T17',
|
|
|
|
'2018-01-01T18',
|
|
|
|
'2018-01-01T19',
|
|
|
|
'2018-01-01T20',
|
|
|
|
'2018-01-01T21',
|
|
|
|
'2018-01-01T22',
|
|
|
|
'2018-01-01T23'
|
2018-10-31 19:00:40 +08:00
|
|
|
]);
|
2019-10-22 01:41:03 +08:00
|
|
|
tileJSON[0].features.forEach(f => assert.strictEqual(f.properties._cdb_feature_count, 4));
|
2018-10-31 19:00:40 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-22 18:31:33 +08:00
|
|
|
['centroid', 'point-sample', 'point-grid'].forEach(placement => {
|
2019-10-22 01:07:24 +08:00
|
|
|
it(`dimensions should work for ${placement} placement`, function (done) {
|
2017-12-22 18:31:33 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
placement: placement,
|
2017-12-22 18:31:33 +08:00
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
2019-10-22 01:07:24 +08:00
|
|
|
value: 'value'
|
2017-12-22 18:31:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(
|
2019-10-22 01:41:03 +08:00
|
|
|
feature => assert.strictEqual(typeof feature.properties.value, 'number')
|
2017-12-22 18:31:33 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-04 22:29:40 +08:00
|
|
|
['centroid', 'point-sample', 'point-grid'].forEach(placement => {
|
2019-10-22 01:07:24 +08:00
|
|
|
it(`dimensions with alias should work for ${placement} placement`, function (done) {
|
2018-04-04 22:29:40 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
placement: placement,
|
2018-04-04 22:29:40 +08:00
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
2019-10-22 01:07:24 +08:00
|
|
|
value2: 'value'
|
2018-04-04 22:29:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(
|
2019-10-22 01:41:03 +08:00
|
|
|
feature => assert.strictEqual(typeof feature.properties.value2, 'number')
|
2018-04-04 22:29:40 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('dimensions should trigger non-default aggregation', function (done) {
|
2017-12-22 18:31:33 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_2,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
dimensions: {
|
2019-10-22 01:07:24 +08:00
|
|
|
value: 'value'
|
2017-12-22 18:31:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(
|
2019-10-22 01:41:03 +08:00
|
|
|
feature => assert.strictEqual(typeof feature.properties.value, 'number')
|
2017-12-22 18:31:33 +08:00
|
|
|
);
|
|
|
|
tileJSON[0].features.forEach(
|
2019-10-22 01:41:03 +08:00
|
|
|
feature => assert.strictEqual(typeof feature.properties.sqrt_value, 'undefined')
|
2017-12-22 18:31:33 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('aggregation columns should trigger non-default aggregation', function (done) {
|
2017-12-22 18:31:33 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_2,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(
|
2019-10-22 01:41:03 +08:00
|
|
|
feature => assert.strictEqual(typeof feature.properties.value, 'number')
|
2017-12-22 18:31:33 +08:00
|
|
|
);
|
|
|
|
tileJSON[0].features.forEach(
|
2019-10-22 01:41:03 +08:00
|
|
|
feature => assert.strictEqual(typeof feature.properties.sqrt_value, 'undefined')
|
2017-12-22 18:31:33 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-12-22 22:45:34 +08:00
|
|
|
|
|
|
|
['centroid', 'point-sample', 'point-grid'].forEach(placement => {
|
2019-10-22 01:07:24 +08:00
|
|
|
it(`aggregations with base column names should work for ${placement} placement`, function (done) {
|
2017-12-22 22:45:34 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
placement: placement,
|
2017-12-22 22:45:34 +08:00
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(
|
2019-10-22 01:41:03 +08:00
|
|
|
feature => assert.strictEqual(typeof feature.properties.value, 'number')
|
2017-12-22 22:45:34 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-14 21:14:55 +08:00
|
|
|
it('should work when the sql has single quotes', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: `
|
|
|
|
SELECT
|
2017-12-22 18:31:33 +08:00
|
|
|
cartodb_id,
|
2017-12-14 21:14:55 +08:00
|
|
|
the_geom_webmercator,
|
|
|
|
the_geom,
|
|
|
|
value,
|
|
|
|
DATE_PART('day', date::timestamp - '1912-12-31 01:00:00'::timestamp )::numeric AS day
|
|
|
|
FROM (${POINTS_SQL_TIMESTAMP_1}) _query
|
|
|
|
`,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2017-12-14 21:14:55 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(!layer.meta.aggregation.png));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-12-15 18:14:17 +08:00
|
|
|
|
|
|
|
it('aggregates with point-grid placement', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
placement: 'point-grid',
|
|
|
|
columns: {
|
|
|
|
total: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
},
|
|
|
|
v_avg: {
|
|
|
|
aggregate_function: 'avg',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
threshold: 1
|
|
|
|
},
|
|
|
|
cartocss: '#layer { marker-width: [total]; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2017-12-15 18:14:17 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.png));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('aggregates with point-sample placement', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
placement: 'point-sample',
|
|
|
|
columns: {
|
|
|
|
total: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
},
|
|
|
|
v_avg: {
|
|
|
|
aggregate_function: 'avg',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
threshold: 1
|
|
|
|
},
|
|
|
|
cartocss: '#layer { marker-width: [total]; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2017-12-15 18:14:17 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.png));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('aggregates with centroid placement', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
placement: 'centroid',
|
|
|
|
columns: {
|
|
|
|
total: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
},
|
|
|
|
v_avg: {
|
|
|
|
aggregate_function: 'avg',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
threshold: 1
|
|
|
|
},
|
|
|
|
cartocss: '#layer { marker-width: [total]; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2017-12-15 18:14:17 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.png));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-12-18 20:42:27 +08:00
|
|
|
|
2017-12-22 18:31:33 +08:00
|
|
|
it('aggregates with full-sample placement by default', function (done) {
|
2017-12-19 23:17:13 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2018-07-16 20:59:26 +08:00
|
|
|
threshold: 1
|
2017-12-19 23:17:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
this.testClient.getTile(0, 0, 0, { format: 'mvt' }, function (err, res, mvt) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const geojsonTile = JSON.parse(mvt.toGeoJSONSync(0));
|
|
|
|
|
|
|
|
assert.ok(Array.isArray(geojsonTile.features));
|
|
|
|
assert.ok(geojsonTile.features.length > 0);
|
|
|
|
|
|
|
|
const feature = geojsonTile.features[0];
|
|
|
|
|
|
|
|
assert.ok(feature.properties.hasOwnProperty('value'), 'Missing value property');
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-18 20:42:27 +08:00
|
|
|
it('should fail with bad resolution', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
id: 'wadus',
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
resolution: 'wadus'
|
2017-12-18 20:42:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
response: {
|
|
|
|
status: 400
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, {
|
2019-10-22 01:07:24 +08:00
|
|
|
errors: ['Invalid resolution, should be a number greather than 0'],
|
|
|
|
errors_with_context: [{
|
2017-12-18 20:42:27 +08:00
|
|
|
type: 'layer',
|
|
|
|
message: 'Invalid resolution, should be a number greather than 0',
|
|
|
|
layer: {
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'wadus',
|
|
|
|
index: 0,
|
|
|
|
type: 'mapnik'
|
2017-12-18 20:42:27 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail with bad placement', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
placement: 'wadus'
|
2017-12-18 20:42:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
response: {
|
|
|
|
status: 400
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, {
|
2019-10-22 01:07:24 +08:00
|
|
|
errors: ['Invalid placement. Valid values: centroid, point-grid, point-sample'],
|
|
|
|
errors_with_context: [{
|
2017-12-18 20:42:27 +08:00
|
|
|
type: 'layer',
|
2017-12-22 18:31:33 +08:00
|
|
|
message: 'Invalid placement. Valid values: centroid, point-grid, point-sample',
|
2017-12-18 20:42:27 +08:00
|
|
|
layer: {
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'layer0',
|
2017-12-18 20:42:27 +08:00
|
|
|
index: 0,
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'mapnik'
|
2017-12-18 20:42:27 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail with bad threshold', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
threshold: 'wadus'
|
2017-12-18 20:42:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
response: {
|
|
|
|
status: 400
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, {
|
2019-10-22 01:07:24 +08:00
|
|
|
errors: ['Invalid threshold, should be a number greather than 0'],
|
|
|
|
errors_with_context: [{
|
2017-12-18 20:42:27 +08:00
|
|
|
type: 'layer',
|
|
|
|
message: 'Invalid threshold, should be a number greather than 0',
|
|
|
|
layer: {
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'layer0',
|
|
|
|
index: 0,
|
|
|
|
type: 'mapnik'
|
2017-12-18 20:42:27 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-12-19 03:42:26 +08:00
|
|
|
|
|
|
|
it('should fail with bad column name', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
columns: {
|
2017-12-19 03:42:26 +08:00
|
|
|
'': {
|
|
|
|
aggregate_function: 'count',
|
2019-10-22 01:07:24 +08:00
|
|
|
aggregated_column: 'value'
|
2017-12-19 03:42:26 +08:00
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
2017-12-19 03:42:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
response: {
|
|
|
|
status: 400
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, {
|
2019-10-22 01:07:24 +08:00
|
|
|
errors: ['Invalid column name, should be a non empty string'],
|
|
|
|
errors_with_context: [{
|
2017-12-19 03:42:26 +08:00
|
|
|
type: 'layer',
|
|
|
|
message: 'Invalid column name, should be a non empty string',
|
|
|
|
layer: {
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'layer0',
|
|
|
|
index: 0,
|
|
|
|
type: 'mapnik'
|
2017-12-19 03:42:26 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail with bad aggregated function', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
columns: {
|
|
|
|
wadus_function: {
|
2017-12-19 03:42:26 +08:00
|
|
|
aggregate_function: 'wadus',
|
2019-10-22 01:07:24 +08:00
|
|
|
aggregated_column: 'value'
|
2017-12-19 03:42:26 +08:00
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
2017-12-19 03:42:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
response: {
|
|
|
|
status: 400
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, {
|
2019-10-22 01:07:24 +08:00
|
|
|
errors: ['Unsupported aggregation function wadus, ' +
|
|
|
|
'valid ones: count, avg, sum, min, max, mode'],
|
|
|
|
errors_with_context: [{
|
2017-12-19 03:42:26 +08:00
|
|
|
type: 'layer',
|
|
|
|
message: 'Unsupported aggregation function wadus, ' +
|
|
|
|
'valid ones: count, avg, sum, min, max, mode',
|
|
|
|
layer: {
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'layer0',
|
|
|
|
index: 0,
|
|
|
|
type: 'mapnik'
|
2017-12-19 03:42:26 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail with bad aggregated columns', function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
columns: {
|
|
|
|
total_wadus: {
|
2017-12-19 03:42:26 +08:00
|
|
|
aggregate_function: 'sum',
|
2019-10-22 01:07:24 +08:00
|
|
|
aggregated_column: ''
|
2017-12-19 03:42:26 +08:00
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
2017-12-19 03:42:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
response: {
|
|
|
|
status: 400
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, {
|
2019-10-22 01:07:24 +08:00
|
|
|
errors: ['Invalid aggregated column, should be a non empty string'],
|
|
|
|
errors_with_context: [{
|
2017-12-19 03:42:26 +08:00
|
|
|
type: 'layer',
|
|
|
|
message: 'Invalid aggregated column, should be a non empty string',
|
|
|
|
layer: {
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'layer0',
|
|
|
|
index: 0,
|
|
|
|
type: 'mapnik'
|
2017-12-19 03:42:26 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-01-03 19:00:25 +08:00
|
|
|
it('should skip aggregation w/o failing when is Vector Only MapConfig and layer has polygons',
|
2019-10-22 01:07:24 +08:00
|
|
|
function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POLYGONS_SQL_1
|
|
|
|
}
|
2018-01-03 18:14:20 +08:00
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
]);
|
2018-01-03 18:14:20 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
2018-01-03 18:14:20 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-01-03 18:14:20 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
2018-01-03 18:14:20 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
body.metadata.layers.forEach(layer => assert.ok(!layer.meta.aggregation.mvt));
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(!layer.meta.aggregation.png));
|
2018-01-03 18:14:20 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
const tileJSON = tile.toJSON();
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tileJSON[0].features.length, 7);
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
done();
|
|
|
|
});
|
2018-01-03 19:00:25 +08:00
|
|
|
});
|
2018-01-03 18:14:20 +08:00
|
|
|
});
|
|
|
|
|
2018-01-03 19:00:25 +08:00
|
|
|
it('should skip aggregation for polygons (w/o failing) and aggregate when the layer has points',
|
2019-10-22 01:07:24 +08:00
|
|
|
function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POLYGONS_SQL_1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1
|
|
|
|
}
|
2018-01-03 19:00:25 +08:00
|
|
|
}
|
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
]);
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(body.metadata.layers[0].meta.aggregation.mvt, false);
|
|
|
|
assert.strictEqual(body.metadata.layers[1].meta.aggregation.mvt, true);
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
const tileJSON = tile.toJSON();
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tileJSON[0].features.length, 7);
|
2018-01-03 19:00:25 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
done();
|
|
|
|
});
|
2018-01-03 19:00:25 +08:00
|
|
|
});
|
|
|
|
});
|
2018-01-29 19:40:59 +08:00
|
|
|
|
2018-09-12 17:25:21 +08:00
|
|
|
['centroid', 'point-sample', 'point-grid', 'default'].forEach(placement => {
|
2019-10-22 01:07:24 +08:00
|
|
|
it(`cartodb_id should be present in ${placement} aggregation`, function (done) {
|
2018-01-29 19:40:59 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2018-09-13 14:54:59 +08:00
|
|
|
threshold: 1,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-01-29 19:40:59 +08:00
|
|
|
},
|
|
|
|
cartocss: '#layer { marker-width: 1; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
interactivity: ['cartodb_id']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2018-01-29 19:40:59 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.png));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-01-29 22:44:24 +08:00
|
|
|
|
2018-09-12 17:25:21 +08:00
|
|
|
it(`should only require the_geom_webmercator for ${placement} aggregation`, function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_ONLY_WEBMERCATOR,
|
|
|
|
aggregation: {
|
2018-09-13 14:54:59 +08:00
|
|
|
threshold: 1,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-09-12 17:25:21 +08:00
|
|
|
}
|
2018-01-29 22:44:24 +08:00
|
|
|
}
|
|
|
|
}
|
2018-09-12 17:25:21 +08:00
|
|
|
]);
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
2018-01-29 22:44:24 +08:00
|
|
|
|
2018-09-12 17:25:21 +08:00
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-01-29 22:44:24 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2018-09-12 17:25:21 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
2018-01-29 22:44:24 +08:00
|
|
|
|
2018-09-12 17:25:21 +08:00
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(!layer.meta.aggregation.png));
|
2018-01-29 22:44:24 +08:00
|
|
|
|
2018-09-12 17:25:21 +08:00
|
|
|
done();
|
|
|
|
});
|
2018-01-29 22:44:24 +08:00
|
|
|
});
|
2018-02-01 01:56:24 +08:00
|
|
|
|
2018-09-12 17:25:21 +08:00
|
|
|
it(`${placement} aggregation should work with attributes`, function (done) {
|
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
cartocss: '#layer { marker-width: 7; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1
|
|
|
|
},
|
|
|
|
attributes: {
|
|
|
|
id: 'cartodb_id',
|
|
|
|
columns: [
|
|
|
|
'value'
|
|
|
|
]
|
|
|
|
}
|
2018-02-01 01:56:24 +08:00
|
|
|
}
|
|
|
|
}
|
2018-09-12 17:25:21 +08:00
|
|
|
]);
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
2018-02-01 01:56:24 +08:00
|
|
|
|
2018-09-12 17:25:21 +08:00
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-02-01 01:56:24 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2018-09-12 17:25:21 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
2018-02-01 01:56:24 +08:00
|
|
|
|
2018-09-12 17:25:21 +08:00
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.png));
|
2018-02-01 01:56:24 +08:00
|
|
|
|
2018-09-12 17:25:21 +08:00
|
|
|
done();
|
|
|
|
});
|
2018-02-01 01:56:24 +08:00
|
|
|
});
|
|
|
|
});
|
2018-03-22 00:01:32 +08:00
|
|
|
|
|
|
|
['centroid', 'point-sample', 'point-grid'].forEach(placement => {
|
2019-10-22 01:07:24 +08:00
|
|
|
it(`filters should work for ${placement} placement`, function (done) {
|
2018-03-22 00:01:32 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
placement: placement,
|
2018-03-22 00:01:32 +08:00
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
2019-07-08 22:27:31 +08:00
|
|
|
aggregate_function: 'mode',
|
2018-03-22 00:01:32 +08:00
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
value: {
|
|
|
|
greater_than_or_equal_to: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(row => {
|
|
|
|
assert.ok(row.properties.value >= 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
['centroid', 'point-sample', 'point-grid'].forEach(placement => {
|
2019-10-22 01:07:24 +08:00
|
|
|
it(`multiple ORed filters should work for ${placement} placement`, function (done) {
|
2018-03-22 00:01:32 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
placement: placement,
|
2018-03-22 00:01:32 +08:00
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
2019-07-08 22:27:31 +08:00
|
|
|
aggregate_function: 'mode',
|
2018-03-22 00:01:32 +08:00
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
value: [
|
|
|
|
{ greater_than: 0 },
|
|
|
|
{ less_than: -2 }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(row => {
|
|
|
|
assert.ok(row.properties.value > 0 || row.properties.value < -2);
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
['centroid', 'point-sample', 'point-grid'].forEach(placement => {
|
2019-10-22 01:07:24 +08:00
|
|
|
it(`multiple ANDed filters should work for ${placement} placement`, function (done) {
|
2018-03-22 00:01:32 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_2,
|
|
|
|
aggregation: {
|
2019-10-22 01:07:24 +08:00
|
|
|
placement: placement,
|
2018-03-22 00:01:32 +08:00
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
},
|
|
|
|
value2: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'sqrt_value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
value: { greater_than: 0 },
|
|
|
|
value2: { less_than: 9 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(row => {
|
|
|
|
assert.ok(row.properties.value > 0 && row.properties.value2 < 9);
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('supports IN filters', function (done) {
|
2018-03-22 00:01:32 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
value: { in: [1, 3] }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(row => {
|
|
|
|
assert.ok(row.properties.value === 1 || row.properties.value === 3);
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('supports NOT IN filters', function (done) {
|
2018-03-22 00:01:32 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
value: { not_in: [1, 3] }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(row => {
|
|
|
|
assert.ok(row.properties.value !== 1 && row.properties.value !== 3);
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('supports EQUAL filters', function (done) {
|
2018-03-22 00:01:32 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
2019-10-22 01:07:24 +08:00
|
|
|
value: [{ equal: 1 }, { equal: 3 }]
|
2018-03-22 00:01:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(row => {
|
|
|
|
assert.ok(row.properties.value === 1 || row.properties.value === 3);
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('supports NOT EQUAL filters', function (done) {
|
2018-03-22 00:01:32 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
value: { not_equal: 1 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(row => {
|
|
|
|
assert.ok(row.properties.value !== 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('supports BETWEEN filters', function (done) {
|
2018-03-22 00:01:32 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
value: {
|
|
|
|
greater_than_or_equal_to: -1,
|
|
|
|
less_than_or_equal_to: 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(row => {
|
|
|
|
assert.ok(row.properties.value >= -1 || row.properties.value <= 2);
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('supports RANGE filters', function (done) {
|
2018-03-22 00:01:32 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
value: {
|
|
|
|
greater_than: -1,
|
|
|
|
less_than_or_equal_to: 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
const options = {
|
|
|
|
format: 'mvt'
|
|
|
|
};
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const tileJSON = tile.toJSON();
|
|
|
|
|
|
|
|
tileJSON[0].features.forEach(row => {
|
|
|
|
assert.ok(row.properties.value > -1 || row.properties.value <= 2);
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('invalid filters cause errors', function (done) {
|
2018-03-22 00:01:32 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
value: {
|
|
|
|
not_a_valid_parameter: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
response: {
|
|
|
|
status: 400
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, {
|
2019-10-22 01:07:24 +08:00
|
|
|
errors: ['Invalid filter parameter name: not_a_valid_parameter'],
|
|
|
|
errors_with_context: [{
|
2018-03-22 00:01:32 +08:00
|
|
|
type: 'layer',
|
|
|
|
message: 'Invalid filter parameter name: not_a_valid_parameter',
|
|
|
|
layer: {
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'layer0',
|
2018-03-22 00:01:32 +08:00
|
|
|
index: 0,
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'mapnik'
|
2018-03-22 00:01:32 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('filters on invalid columns cause errors', function (done) {
|
2018-03-22 00:01:32 +08:00
|
|
|
this.mapConfig = createVectorMapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
|
|
|
columns: {
|
|
|
|
value_sum: {
|
|
|
|
aggregate_function: 'sum',
|
|
|
|
aggregated_column: 'value'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
filters: {
|
|
|
|
value: {
|
|
|
|
not_a_valid_parameter: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
response: {
|
|
|
|
status: 400
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getLayergroup(options, (err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, {
|
2019-10-22 01:07:24 +08:00
|
|
|
errors: ['Invalid filtered column: value'],
|
|
|
|
errors_with_context: [{
|
2018-03-22 00:01:32 +08:00
|
|
|
type: 'layer',
|
|
|
|
message: 'Invalid filtered column: value',
|
|
|
|
layer: {
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'layer0',
|
2018-03-22 00:01:32 +08:00
|
|
|
index: 0,
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'mapnik'
|
2018-03-22 00:01:32 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-05 22:01:29 +08:00
|
|
|
['default', 'centroid', 'point-sample', 'point-grid'].forEach(placement => {
|
2018-07-11 17:29:22 +08:00
|
|
|
it(`for ${placement} and no points between tiles has unique ids`, function (done) {
|
|
|
|
this.mapConfig = {
|
|
|
|
version: '1.6.0',
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize: { mvt: 0 },
|
2018-07-11 17:29:22 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_0,
|
|
|
|
aggregation: {
|
2018-07-16 20:27:39 +08:00
|
|
|
threshold: 1,
|
2018-09-13 14:54:59 +08:00
|
|
|
resolution: 1,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-04-05 22:01:29 +08:00
|
|
|
}
|
|
|
|
}
|
2018-07-11 17:29:22 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(1, 0, 1, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-11 17:29:22 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
2018-07-11 16:33:58 +08:00
|
|
|
}
|
|
|
|
|
2018-07-11 17:29:22 +08:00
|
|
|
const tile1 = JSON.parse(mvt.toGeoJSONSync(0));
|
2018-07-11 16:33:58 +08:00
|
|
|
|
2018-07-11 17:29:22 +08:00
|
|
|
assert.ok(Array.isArray(tile1.features));
|
|
|
|
assert.ok(tile1.features.length > 0);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(1, 1, 0, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-11 16:33:58 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
2018-04-05 22:01:29 +08:00
|
|
|
}
|
|
|
|
|
2018-07-11 17:29:22 +08:00
|
|
|
const tile2 = JSON.parse(mvt.toGeoJSONSync(0));
|
2018-07-11 16:33:58 +08:00
|
|
|
|
2018-07-11 17:29:22 +08:00
|
|
|
assert.ok(Array.isArray(tile2.features));
|
|
|
|
assert.ok(tile2.features.length > 0);
|
2018-07-11 16:33:58 +08:00
|
|
|
|
2018-07-11 17:29:22 +08:00
|
|
|
const tile1Ids = tile1.features.map(f => f.properties.cartodb_id);
|
|
|
|
const tile2Ids = tile2.features.map(f => f.properties.cartodb_id);
|
|
|
|
const repeatedIds = tile1Ids.filter(id => tile2Ids.includes(id));
|
2018-07-11 16:33:58 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(repeatedIds.length, 0);
|
2018-07-11 16:33:58 +08:00
|
|
|
|
2018-07-11 17:29:22 +08:00
|
|
|
done();
|
2018-07-11 16:33:58 +08:00
|
|
|
});
|
|
|
|
});
|
2018-07-11 17:29:22 +08:00
|
|
|
});
|
|
|
|
it(`for ${placement} has unique ids save between tiles`, function (done) {
|
|
|
|
this.mapConfig = {
|
|
|
|
version: '1.6.0',
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize: { mvt: 0 },
|
2018-07-11 17:29:22 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1,
|
|
|
|
resolution: 1,
|
|
|
|
aggregation: {
|
2018-09-13 14:54:59 +08:00
|
|
|
threshold: 1,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-07-11 16:33:58 +08:00
|
|
|
}
|
|
|
|
}
|
2018-07-11 17:29:22 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(1, 0, 1, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-11 17:29:22 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
2018-07-11 16:33:58 +08:00
|
|
|
}
|
2018-04-05 22:01:29 +08:00
|
|
|
|
2018-07-11 17:29:22 +08:00
|
|
|
const tile1 = JSON.parse(mvt.toGeoJSONSync(0));
|
|
|
|
|
|
|
|
assert.ok(Array.isArray(tile1.features));
|
|
|
|
assert.ok(tile1.features.length > 0);
|
2018-04-05 22:01:29 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(1, 1, 0, { format: 'mvt' }, (err, res, mvt) => {
|
2018-04-05 22:01:29 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2018-07-11 17:29:22 +08:00
|
|
|
const tile2 = JSON.parse(mvt.toGeoJSONSync(0));
|
|
|
|
|
|
|
|
assert.ok(Array.isArray(tile2.features));
|
|
|
|
assert.ok(tile2.features.length > 0);
|
|
|
|
|
|
|
|
const tile1Ids = tile1.features.map(f => f.properties.cartodb_id);
|
|
|
|
const tile2Ids = tile2.features.map(f => f.properties.cartodb_id);
|
|
|
|
const repeatedIds = tile1Ids.filter(id => tile2Ids.includes(id));
|
|
|
|
|
|
|
|
// It is not guaranteed that features appear in a single tile:
|
|
|
|
// features on the border of tiles can appear in multiple tiles
|
|
|
|
if (repeatedIds.length > 0) {
|
|
|
|
repeatedIds.forEach(id => {
|
|
|
|
const tile1Features = tile1.features.filter(f => f.properties.cartodb_id === id);
|
|
|
|
const tile2Features = tile2.features.filter(f => f.properties.cartodb_id === id);
|
|
|
|
// repetitions cannot occur inside a tile
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tile1Features.length, 1);
|
|
|
|
assert.strictEqual(tile2Features.length, 1);
|
2018-07-11 17:29:22 +08:00
|
|
|
const feature1 = tile1Features[0];
|
|
|
|
const feature2 = tile2Features[0];
|
|
|
|
// features should be identical (geometry and properties)
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(feature1.properties, feature2.properties);
|
|
|
|
assert.deepStrictEqual(feature1.geometry, feature2.geometry);
|
2018-07-11 17:29:22 +08:00
|
|
|
// and geometry should be on the border;
|
|
|
|
// for the dataset and zoom 1, only point with cartodb_id=4 (0,0)
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(feature1.properties.cartodb_id, 4);
|
|
|
|
assert.strictEqual(feature2.properties.cartodb_id, 4);
|
2018-07-11 17:29:22 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
done();
|
2018-07-11 16:33:58 +08:00
|
|
|
});
|
2018-04-05 22:01:29 +08:00
|
|
|
});
|
2018-07-11 17:29:22 +08:00
|
|
|
});
|
2018-07-16 04:15:57 +08:00
|
|
|
|
2018-07-16 18:02:37 +08:00
|
|
|
it(`for ${placement} each aggr. cell is in a single tile`, function (done) {
|
2018-09-13 01:26:09 +08:00
|
|
|
const z = 1;
|
|
|
|
const resolution = 1;
|
2019-07-03 22:13:54 +08:00
|
|
|
const query = POINTS_SQL_GRID(z, resolution);
|
2018-07-16 04:15:57 +08:00
|
|
|
this.mapConfig = {
|
|
|
|
version: '1.6.0',
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize: { mvt: 0 },
|
2018-07-16 04:15:57 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
|
|
|
|
options: {
|
2018-09-13 01:26:09 +08:00
|
|
|
sql: query,
|
2018-07-16 04:15:57 +08:00
|
|
|
aggregation: {
|
2018-07-16 20:27:39 +08:00
|
|
|
threshold: 1,
|
2018-09-13 14:54:59 +08:00
|
|
|
resolution: resolution,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-07-16 04:15:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
2018-09-13 01:26:09 +08:00
|
|
|
const c = Math.pow(2, z - 1) - 1; // center tile coordinates
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c + 0, c + 0, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-16 04:15:57 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile00 = JSON.parse(mvt.toGeoJSONSync(0));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c + 0, c + 1, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-16 04:15:57 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile01 = JSON.parse(mvt.toGeoJSONSync(0));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c + 1, c + 0, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-16 04:15:57 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile10 = JSON.parse(mvt.toGeoJSONSync(0));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c + 1, c + 1, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-16 04:15:57 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile11 = JSON.parse(mvt.toGeoJSONSync(0));
|
|
|
|
|
2019-07-03 22:13:54 +08:00
|
|
|
// There needs to be 13 points
|
2019-10-22 01:07:24 +08:00
|
|
|
const count_features = (tile) =>
|
2019-07-03 22:13:54 +08:00
|
|
|
tile.features.map(f => f.properties)
|
2019-10-22 01:07:24 +08:00
|
|
|
.map(f => f._cdb_feature_count)
|
|
|
|
.reduce((a, b) => a + b, 0);
|
2019-07-03 22:13:54 +08:00
|
|
|
|
|
|
|
const tile00Count = count_features(tile00);
|
|
|
|
const tile10Count = count_features(tile10);
|
|
|
|
const tile01Count = count_features(tile01);
|
|
|
|
const tile11Count = count_features(tile11);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(13, tile00Count + tile10Count + tile01Count + tile11Count);
|
2018-07-16 04:15:57 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-07-16 04:17:00 +08:00
|
|
|
|
2018-07-16 20:27:39 +08:00
|
|
|
it(`for ${placement} no partially aggregated cells`, function (done) {
|
|
|
|
// Use level 1 with resolution 2 tiles and buffersize 1 (half the cell size)
|
|
|
|
// Only the cells completely inside the buffer are aggregated
|
2018-09-13 01:26:09 +08:00
|
|
|
const z = 1;
|
|
|
|
const resolution = 2;
|
|
|
|
// space the test points by half the resolution:
|
2019-07-03 22:13:54 +08:00
|
|
|
const query = POINTS_SQL_GRID(z, resolution / 2);
|
2018-09-13 01:26:09 +08:00
|
|
|
|
2018-07-16 20:27:39 +08:00
|
|
|
this.mapConfig = {
|
|
|
|
version: '1.6.0',
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize: { mvt: 1 },
|
2018-07-16 20:27:39 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
|
|
|
|
options: {
|
2018-09-13 01:26:09 +08:00
|
|
|
sql: query,
|
2018-07-16 20:27:39 +08:00
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
2018-09-13 14:54:59 +08:00
|
|
|
resolution: resolution,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-07-16 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
2018-09-13 01:26:09 +08:00
|
|
|
const c = Math.pow(2, z - 1) - 1; // center tile coordinates
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c, c, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-16 20:27:39 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile00 = JSON.parse(mvt.toGeoJSONSync(0));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c, c + 1, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-16 20:27:39 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile01 = JSON.parse(mvt.toGeoJSONSync(0));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c + 1, c, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-16 20:27:39 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile10 = JSON.parse(mvt.toGeoJSONSync(0));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c + 1, c + 1, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-16 20:27:39 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile11 = JSON.parse(mvt.toGeoJSONSync(0));
|
|
|
|
|
|
|
|
const tile00Expected = [
|
|
|
|
{ cartodb_id: 4, _cdb_feature_count: 3 }
|
|
|
|
];
|
|
|
|
const tile10Expected = [
|
|
|
|
{ cartodb_id: 5, _cdb_feature_count: 5 }
|
|
|
|
];
|
|
|
|
const tile01Expected = [
|
|
|
|
{ cartodb_id: 1, _cdb_feature_count: 2 }
|
|
|
|
];
|
|
|
|
const tile11Expected = [
|
|
|
|
{ cartodb_id: 2, _cdb_feature_count: 3 }
|
|
|
|
];
|
|
|
|
const tile00Actual = tile00.features.map(f => f.properties);
|
|
|
|
const tile10Actual = tile10.features.map(f => f.properties);
|
|
|
|
const tile01Actual = tile01.features.map(f => f.properties);
|
|
|
|
const tile11Actual = tile11.features.map(f => f.properties);
|
|
|
|
const orderById = (a, b) => a.cartodb_id - b.cartodb_id;
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(tile00Actual.sort(orderById), tile00Expected);
|
|
|
|
assert.deepStrictEqual(tile10Actual.sort(orderById), tile10Expected);
|
|
|
|
assert.deepStrictEqual(tile01Actual.sort(orderById), tile01Expected);
|
|
|
|
assert.deepStrictEqual(tile11Actual.sort(orderById), tile11Expected);
|
2018-09-13 01:26:09 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`for ${placement} includes complete cells in buffer`, function (done) {
|
|
|
|
// use buffersize coincident with resolution, the buffer should include neighbour cells
|
|
|
|
const z = 2;
|
|
|
|
const resolution = 1;
|
2019-07-03 22:13:54 +08:00
|
|
|
const query = POINTS_SQL_GRID(z, resolution);
|
2018-09-13 01:26:09 +08:00
|
|
|
|
|
|
|
this.mapConfig = {
|
|
|
|
version: '1.6.0',
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize: { mvt: 1 },
|
2018-09-13 01:26:09 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
|
|
|
|
options: {
|
|
|
|
sql: query,
|
|
|
|
aggregation: {
|
|
|
|
threshold: 1,
|
2018-09-13 14:54:59 +08:00
|
|
|
resolution: resolution,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-09-13 01:26:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
|
|
|
const c = Math.pow(2, z - 1) - 1; // center tile coordinates
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c, c, { format: 'mvt' }, (err, res, mvt) => {
|
2018-09-13 01:26:09 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile00 = JSON.parse(mvt.toGeoJSONSync(0));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c, c + 1, { format: 'mvt' }, (err, res, mvt) => {
|
2018-09-13 01:26:09 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile01 = JSON.parse(mvt.toGeoJSONSync(0));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c + 1, c, { format: 'mvt' }, (err, res, mvt) => {
|
2018-09-13 01:26:09 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile10 = JSON.parse(mvt.toGeoJSONSync(0));
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(z, c + 1, c + 1, { format: 'mvt' }, (err, res, mvt) => {
|
2018-09-13 01:26:09 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile11 = JSON.parse(mvt.toGeoJSONSync(0));
|
|
|
|
|
2019-07-15 21:30:56 +08:00
|
|
|
// We check that if an id/cell is present in multiple tiles,
|
|
|
|
// it always contains the same amount of features
|
2018-09-13 01:26:09 +08:00
|
|
|
const tile00Actual = tile00.features.map(f => f.properties);
|
|
|
|
const tile10Actual = tile10.features.map(f => f.properties);
|
|
|
|
const tile01Actual = tile01.features.map(f => f.properties);
|
|
|
|
const tile11Actual = tile11.features.map(f => f.properties);
|
2019-07-09 20:02:34 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
const allFeatures = [...tile00Actual, ...tile10Actual,
|
|
|
|
...tile01Actual, ...tile11Actual];
|
2019-07-15 21:30:56 +08:00
|
|
|
for (let i = 0; i < allFeatures.length; i++) {
|
|
|
|
for (let j = i + 1; j < allFeatures.length; j++) {
|
|
|
|
const c1 = allFeatures[i];
|
|
|
|
const c2 = allFeatures[j];
|
|
|
|
if (c1.cartodb_id === c2.cartodb_id) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(c1._cdb_feature_count, c2._cdb_feature_count);
|
2019-07-15 21:30:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-16 20:27:39 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-16 18:44:30 +08:00
|
|
|
it(`for ${placement} points aggregated into corner cluster`, function (done) {
|
2018-07-16 04:17:00 +08:00
|
|
|
// this test will fail due to !bbox! lack of accuracy if strict cell filtering is in place
|
|
|
|
this.mapConfig = {
|
|
|
|
version: '1.6.0',
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize: { mvt: 0 },
|
2018-07-16 04:17:00 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_CELL,
|
|
|
|
aggregation: {
|
2018-07-16 20:27:39 +08:00
|
|
|
threshold: 1,
|
2018-09-13 14:54:59 +08:00
|
|
|
resolution: 1,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-07-16 04:17:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(20, 1000000, 1000000, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-16 04:17:00 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile = JSON.parse(mvt.toGeoJSONSync(0));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tile.features.length, 1);
|
|
|
|
assert.strictEqual(tile.features[0].properties._cdb_feature_count, 4);
|
2018-07-16 04:17:00 +08:00
|
|
|
if (placement === 'point-grid') {
|
|
|
|
// check geometry x = 18181005.874444414, y = -18181043.94366749
|
2019-10-22 01:07:24 +08:00
|
|
|
const expectedPoint = [163.322754576802, -83.3823797469878];
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(tile.features[0].geometry.coordinates, expectedPoint);
|
2018-07-16 04:17:00 +08:00
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-07-16 18:02:37 +08:00
|
|
|
it(`for ${placement} points aggregated into correct cluster`, function (done) {
|
2018-07-16 04:17:00 +08:00
|
|
|
this.mapConfig = {
|
|
|
|
version: '1.6.0',
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize: { mvt: 0 },
|
2018-07-16 04:17:00 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_CELL_INNER,
|
|
|
|
aggregation: {
|
2018-07-16 20:27:39 +08:00
|
|
|
threshold: 1,
|
2018-09-13 14:54:59 +08:00
|
|
|
resolution: 1,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-07-16 04:17:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getTile(20, 1000000, 1000000, { format: 'mvt' }, (err, res, mvt) => {
|
2018-07-16 04:17:00 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
const tile = JSON.parse(mvt.toGeoJSONSync(0));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tile.features.length, 1);
|
|
|
|
assert.strictEqual(tile.features[0].properties._cdb_feature_count, 4);
|
2018-07-16 04:17:00 +08:00
|
|
|
if (placement === 'point-grid') {
|
|
|
|
// check geometry x = 18181006.023735486, y = -18181043.794376418
|
2019-10-22 01:07:24 +08:00
|
|
|
const expectedPoint = [163.322755917907, -83.3823795924354];
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(tile.features[0].geometry.coordinates, expectedPoint);
|
2018-07-16 04:17:00 +08:00
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-04-05 22:01:29 +08:00
|
|
|
});
|
|
|
|
|
2018-05-13 19:05:39 +08:00
|
|
|
['default', 'centroid', 'point-sample', 'point-grid'].forEach(placement => {
|
|
|
|
it(`default pre-aggregation stats are available with ${placement} aggregation`, function (done) {
|
|
|
|
global.environment.enabledFeatures.layerStats = true;
|
|
|
|
this.mapConfig = {
|
|
|
|
version: '1.6.0',
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize: { mvt: 0 },
|
2018-05-13 19:05:39 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_PAIRS,
|
|
|
|
aggregation: {
|
2018-07-16 20:27:39 +08:00
|
|
|
threshold: 1,
|
2018-09-13 14:54:59 +08:00
|
|
|
resolution: 1,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-05-13 19:05:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2018-05-13 19:05:39 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
assert.ok(body.metadata.layers[0].meta.aggregation.mvt);
|
|
|
|
assert.ok(body.metadata.layers[0].meta.stats.estimatedFeatureCount > 0);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`on demand post-aggregation stats are available with ${placement} aggregation`, function (done) {
|
|
|
|
global.environment.enabledFeatures.layerStats = true;
|
|
|
|
this.mapConfig = {
|
|
|
|
version: '1.6.0',
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize: { mvt: 0 },
|
2018-05-13 19:05:39 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_PAIRS,
|
|
|
|
aggregation: {
|
2018-07-16 20:27:39 +08:00
|
|
|
threshold: 1,
|
2018-09-13 14:54:59 +08:00
|
|
|
resolution: 1,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-05-13 19:05:39 +08:00
|
|
|
},
|
|
|
|
metadata: {
|
|
|
|
aggrFeatureCount: 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2018-05-13 19:05:39 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
assert.ok(body.metadata.layers[0].meta.aggregation.mvt);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(body.metadata.layers[0].meta.stats.aggrFeatureCount, 13);
|
2018-05-13 19:05:39 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`post-aggregation count adapts to zoom level with ${placement} aggregation`, function (done) {
|
|
|
|
global.environment.enabledFeatures.layerStats = true;
|
|
|
|
this.mapConfig = {
|
|
|
|
version: '1.6.0',
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize: { mvt: 0 },
|
2018-05-13 19:05:39 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_PAIRS,
|
|
|
|
aggregation: {
|
2018-07-16 20:27:39 +08:00
|
|
|
threshold: 1,
|
2018-09-13 14:54:59 +08:00
|
|
|
resolution: 1,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-05-13 19:05:39 +08:00
|
|
|
},
|
|
|
|
metadata: {
|
|
|
|
aggrFeatureCount: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2018-05-13 19:05:39 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
assert.ok(body.metadata.layers[0].meta.aggregation.mvt);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(body.metadata.layers[0].meta.stats.aggrFeatureCount, 7);
|
2018-05-13 19:05:39 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`on-demand pre-aggregation stats are available with ${placement} aggregation`, function (done) {
|
|
|
|
global.environment.enabledFeatures.layerStats = true;
|
|
|
|
this.mapConfig = {
|
|
|
|
version: '1.6.0',
|
2019-10-22 01:07:24 +08:00
|
|
|
buffersize: { mvt: 0 },
|
2018-05-13 19:05:39 +08:00
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_PAIRS,
|
|
|
|
aggregation: {
|
2018-07-16 20:27:39 +08:00
|
|
|
threshold: 1,
|
2018-09-13 14:54:59 +08:00
|
|
|
resolution: 1,
|
|
|
|
placement: placement !== 'default' ? placement : undefined
|
2018-05-13 19:05:39 +08:00
|
|
|
},
|
|
|
|
metadata: {
|
|
|
|
featureCount: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
this.testClient.getLayergroup((err, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(typeof body.metadata, 'object');
|
2018-05-13 19:05:39 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
assert.ok(body.metadata.layers[0].meta.aggregation.mvt);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(body.metadata.layers[0].meta.stats.featureCount, 14);
|
2018-05-13 19:05:39 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-12-04 19:40:53 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|