2018-03-27 00:44:31 +08:00
|
|
|
require('../support/test_helper');
|
|
|
|
|
|
|
|
const assert = require('../support/assert');
|
|
|
|
const TestClient = require('../support/test-client');
|
|
|
|
const serverOptions = require('../../lib/cartodb/server_options');
|
|
|
|
|
|
|
|
const suites = [{
|
2018-04-11 22:08:18 +08:00
|
|
|
desc: 'mapnik',
|
2018-03-27 00:44:31 +08:00
|
|
|
usePostGIS: false
|
|
|
|
}];
|
|
|
|
|
|
|
|
if (process.env.POSTGIS_VERSION === '2.4') {
|
|
|
|
suites.push({
|
2018-04-11 22:08:18 +08:00
|
|
|
desc: 'postgis',
|
2018-03-27 00:44:31 +08:00
|
|
|
usePostGIS: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function (){
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(typeof body.metadata, 'object');
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function (){
|
|
|
|
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
|
|
|
|
from countries_null_values
|
|
|
|
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) {
|
|
|
|
return reject(new Error(`Missing country='Sudan'`));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04-12 17:27:31 +08:00
|
|
|
|
2018-03-27 00:44:31 +08:00
|
|
|
});
|