2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2018-03-27 00:44:31 +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');
|
2018-03-27 00:44:31 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
const suites = [
|
|
|
|
{
|
|
|
|
desc: 'mapnik',
|
|
|
|
usePostGIS: false
|
|
|
|
},
|
|
|
|
{
|
2018-04-11 22:08:18 +08:00
|
|
|
desc: 'postgis',
|
2018-03-27 00:44:31 +08:00
|
|
|
usePostGIS: true
|
2019-02-22 15:31:22 +08:00
|
|
|
}
|
|
|
|
];
|
2018-03-27 00:44:31 +08:00
|
|
|
|
2018-04-11 22:08:18 +08:00
|
|
|
describe('mvt regressions', function () {
|
2018-03-27 00:44:31 +08:00
|
|
|
suites.forEach((suite) => {
|
|
|
|
const { desc, usePostGIS } = suite;
|
|
|
|
|
|
|
|
describe(desc, function () {
|
|
|
|
const originalUsePostGIS = serverOptions.renderer.mvt.usePostGIS;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = usePostGIS;
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
after(function () {
|
2018-03-27 00:44:31 +08:00
|
|
|
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
|
2018-04-11 22:08:18 +08:00
|
|
|
it('should not error on missing column from aggregation', function (done) {
|
2018-03-27 00:44:31 +08:00
|
|
|
const mapConfig = {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from populated_places_simple_reduced',
|
|
|
|
aggregation: {
|
|
|
|
placement: 'point-sample',
|
|
|
|
columns: {
|
|
|
|
pop_max_avg: {
|
|
|
|
aggregate_function: 'avg',
|
|
|
|
aggregated_column: 'pop_max'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
threshold: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
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-03-27 00:44:31 +08:00
|
|
|
assert.ok(Array.isArray(body.metadata.layers));
|
|
|
|
|
|
|
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-04-11 18:03:06 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-11 18:13:24 +08:00
|
|
|
describe('MVT Mapnik', function () {
|
2018-04-11 18:03:06 +08:00
|
|
|
const originalUsePostGIS = serverOptions.renderer.mvt.usePostGIS;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = false;
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
after(function () {
|
2018-04-11 18:03:06 +08:00
|
|
|
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('invalid properties', function (done) {
|
2018-04-17 17:05:37 +08:00
|
|
|
const query = `
|
|
|
|
select ldc, cartodb_id, _2016_6_partcntry, the_geom_webmercator, country
|
2018-10-24 00:39:02 +08:00
|
|
|
from countries_null_values
|
2018-04-17 17:05:37 +08:00
|
|
|
where country = 'Kenya' OR country = 'Sudan' LIMIT 3
|
|
|
|
`;
|
|
|
|
|
2018-04-11 18:03:06 +08:00
|
|
|
const mapConfig = {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2018-04-17 17:05:37 +08:00
|
|
|
sql: query
|
2018-04-11 18:03:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
const handler = (resolve, reject) => {
|
|
|
|
return (err, res, MVT) => {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
const geojsonTile = JSON.parse(MVT.toGeoJSONSync(0));
|
|
|
|
const sudanFeature = geojsonTile.features.filter(_ => {
|
|
|
|
return _.properties.country === 'Sudan';
|
|
|
|
})[0];
|
|
|
|
if (!sudanFeature) {
|
2019-10-22 01:07:24 +08:00
|
|
|
return reject(new Error('Missing country=\'Sudan\''));
|
2018-04-11 18:03:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
resolve(sudanFeature);
|
|
|
|
} catch (err) {
|
|
|
|
resolve(err);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(mapConfig);
|
|
|
|
const tile487 = new Promise((resolve, reject) => {
|
|
|
|
this.testClient.getTile(4, 8, 7, { format: 'mvt', layer: 0 }, handler(resolve, reject));
|
|
|
|
});
|
|
|
|
const tile497 = new Promise((resolve, reject) => {
|
|
|
|
this.testClient.getTile(4, 9, 7, { format: 'mvt', layer: 0 }, handler(resolve, reject));
|
2018-03-27 00:44:31 +08:00
|
|
|
});
|
2018-04-11 18:03:06 +08:00
|
|
|
Promise.all([tile487, tile497])
|
|
|
|
.then(features => {
|
|
|
|
const [tile487SudanFeature, tile497SudanFeature] = features;
|
2018-04-11 19:40:55 +08:00
|
|
|
assert.strictEqual(tile487SudanFeature.properties._2016_6_partcntry, 0);
|
|
|
|
assert.strictEqual(tile497SudanFeature.properties._2016_6_partcntry, 0);
|
2018-04-11 18:03:06 +08:00
|
|
|
return done();
|
|
|
|
})
|
|
|
|
.catch(err => done(err));
|
2018-03-27 00:44:31 +08:00
|
|
|
});
|
2018-04-12 16:46:21 +08:00
|
|
|
|
|
|
|
it('should not convert boolean to numeric', function (done) {
|
|
|
|
const geomWebmercator = 'st_transform(st_setsrid(st_makepoint(10, 10), 4326), 3857) as the_geom_webmercator';
|
|
|
|
const sql = `SELECT ${geomWebmercator}, FALSE as status, 0 as data`;
|
|
|
|
|
|
|
|
const mapConfig = {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: { sql }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient = new TestClient(mapConfig);
|
|
|
|
this.testClient.getTile(0, 0, 0, { format: 'mvt', layer: 0 }, (err, res, MVT) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const geojsonTile = JSON.parse(MVT.toGeoJSONSync(0));
|
|
|
|
assert.strictEqual(geojsonTile.features[0].properties.status, false);
|
2018-04-12 17:27:31 +08:00
|
|
|
assert.strictEqual(geojsonTile.features[0].properties.data, 0);
|
2018-04-12 16:46:21 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-03-27 00:44:31 +08:00
|
|
|
});
|