2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2017-07-18 01:43:59 +08:00
|
|
|
|
2017-10-05 20:38:43 +08:00
|
|
|
var assert = require('../support/assert');
|
|
|
|
var TestClient = require('../support/test-client');
|
2019-10-07 16:10:51 +08:00
|
|
|
var serverOptions = require('../../lib/server-options');
|
2017-07-18 01:43:59 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function createMapConfig (sql = TestClient.SQL.ONE_POINT) {
|
2017-07-18 01:43:59 +08:00
|
|
|
return {
|
|
|
|
version: '1.6.0',
|
|
|
|
layers: [{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
2017-07-18 01:43:59 +08:00
|
|
|
options: {
|
|
|
|
sql: sql,
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
interactivity: 'cartodb_id'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-10-06 22:07:24 +08:00
|
|
|
describe('mvt (mapnik)', mvt(false));
|
2019-02-22 15:31:22 +08:00
|
|
|
describe('mvt (postgis)', mvt(true));
|
2017-10-06 22:07:24 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function mvt (usePostGIS) {
|
2019-02-22 15:31:22 +08:00
|
|
|
return function () {
|
|
|
|
const originalUsePostGIS = serverOptions.renderer.mvt.usePostGIS;
|
|
|
|
before(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = usePostGIS;
|
|
|
|
});
|
2019-10-22 01:07:24 +08:00
|
|
|
after(function () {
|
2019-02-22 15:31:22 +08:00
|
|
|
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('named map tile', function () {
|
|
|
|
it('should get default named vector tile', function (done) {
|
|
|
|
const apikeyToken = 1234;
|
|
|
|
const templateName = `mvt-template-${usePostGIS ? 'postgis' : 'mapnik'}`;
|
|
|
|
const template = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: templateName,
|
|
|
|
placeholders: {
|
|
|
|
buffersize: {
|
|
|
|
type: 'number',
|
|
|
|
default: 0
|
2018-03-03 01:22:53 +08:00
|
|
|
}
|
2019-02-22 15:31:22 +08:00
|
|
|
},
|
|
|
|
layergroup: {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from populated_places_simple_reduced limit 10',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss_version: '2.3.0'
|
2019-02-22 15:31:22 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
2018-03-03 01:22:53 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
const testClient = new TestClient(template, apikeyToken);
|
|
|
|
testClient.keysToDelete['map_tpl|localhost'] = 0;
|
2018-03-03 01:22:53 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
testClient.getNamedTile(templateName, 0, 0, 0, 'mvt', {}, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2018-03-03 01:22:53 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
const tileJSON = tile.toJSON();
|
2018-03-03 01:22:53 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tileJSON[0].features.length, 10);
|
2018-03-03 01:22:53 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2018-03-03 01:22:53 +08:00
|
|
|
});
|
|
|
|
});
|
2019-02-22 15:31:22 +08:00
|
|
|
|
|
|
|
describe('analysis-layers-dataviews-mvt', function () {
|
2019-10-22 01:07:24 +08:00
|
|
|
function createMapConfig (layers, dataviews, analysis) {
|
2019-02-22 15:31:22 +08:00
|
|
|
return {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: layers,
|
|
|
|
dataviews: dataviews || {},
|
|
|
|
analyses: analysis || []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var CARTOCSS = [
|
2019-10-22 01:07:24 +08:00
|
|
|
'#points {',
|
|
|
|
' marker-fill-opacity: 1.0;',
|
|
|
|
' marker-line-color: #FFF;',
|
|
|
|
' marker-line-width: 0.5;',
|
|
|
|
' marker-line-opacity: 1.0;',
|
|
|
|
' marker-placement: point;',
|
|
|
|
' marker-type: ellipse;',
|
|
|
|
' marker-width: 8;',
|
|
|
|
' marker-fill: red;',
|
|
|
|
' marker-allow-overlap: true;',
|
|
|
|
'}'
|
2019-02-22 15:31:22 +08:00
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
var mapConfig = createMapConfig(
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: '2570e105-7b37-40d2-bdf4-1af889598745'
|
2019-02-22 15:31:22 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: CARTOCSS,
|
|
|
|
cartocss_version: '2.3.0'
|
2019-02-22 15:31:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2017-10-05 20:38:43 +08:00
|
|
|
{
|
2019-02-22 15:31:22 +08:00
|
|
|
pop_max_histogram: {
|
|
|
|
source: {
|
|
|
|
id: '2570e105-7b37-40d2-bdf4-1af889598745'
|
2017-10-05 20:38:43 +08:00
|
|
|
},
|
2019-02-22 15:31:22 +08:00
|
|
|
type: 'histogram',
|
|
|
|
options: {
|
|
|
|
column: 'pop_max'
|
|
|
|
}
|
2017-10-05 20:38:43 +08:00
|
|
|
}
|
2019-02-22 15:31:22 +08:00
|
|
|
},
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: '2570e105-7b37-40d2-bdf4-1af889598745',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from populated_places_simple_reduced'
|
2019-02-22 15:31:22 +08:00
|
|
|
}
|
2017-10-05 20:38:43 +08:00
|
|
|
}
|
2019-02-22 15:31:22 +08:00
|
|
|
]
|
|
|
|
);
|
2017-10-05 20:38:43 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
it('should get pop_max column from dataview', function (done) {
|
|
|
|
var testClient = new TestClient(mapConfig);
|
2017-10-05 20:38:43 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
testClient.getTile(0, 0, 0, { format: 'mvt', layers: 0 }, function (err, res, MVT) {
|
|
|
|
var geojsonTile = JSON.parse(MVT.toGeoJSONSync(0));
|
|
|
|
assert.ok(!err, err);
|
2017-10-05 20:38:43 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
assert.ok(Array.isArray(geojsonTile.features));
|
|
|
|
assert.ok(geojsonTile.features.length > 0);
|
|
|
|
var feature = geojsonTile.features[0];
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(feature.properties, 'pop_max'), 'Missing pop_max property');
|
2017-10-05 20:38:43 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2017-10-05 20:38:43 +08:00
|
|
|
});
|
2019-02-22 15:31:22 +08:00
|
|
|
});
|
2017-10-05 20:38:43 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
const testCases = [
|
|
|
|
{
|
|
|
|
desc: 'should get empty mvt with code 204 (no content)',
|
|
|
|
coords: { z: 0, x: 0, y: 0 },
|
|
|
|
format: 'mvt',
|
|
|
|
response: {
|
|
|
|
status: 204,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': undefined
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mapConfig: createMapConfig(TestClient.SQL.EMPTY)
|
2017-07-31 23:58:33 +08:00
|
|
|
},
|
2019-02-22 15:31:22 +08:00
|
|
|
{
|
|
|
|
desc: 'should get mvt tile with code 200 (ok)',
|
|
|
|
coords: { z: 0, x: 0, y: 0 },
|
|
|
|
format: 'mvt',
|
|
|
|
response: {
|
|
|
|
status: 200,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-protobuf'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mapConfig: createMapConfig()
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
testCases.forEach(function (test) {
|
|
|
|
it(test.desc, done => {
|
|
|
|
var testClient = new TestClient(test.mapConfig);
|
|
|
|
const { z, x, y } = test.coords;
|
|
|
|
const { format, response } = test;
|
|
|
|
|
|
|
|
testClient.getTile(z, x, y, { format, response }, err => {
|
|
|
|
assert.ifError(err);
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2017-07-18 01:43:59 +08:00
|
|
|
});
|
|
|
|
});
|
2019-02-22 15:31:22 +08:00
|
|
|
|
|
|
|
describe('overviews', function () {
|
2019-10-22 01:07:24 +08:00
|
|
|
function createMapConfig (layers, dataviews, analysis) {
|
2019-02-22 15:31:22 +08:00
|
|
|
return {
|
|
|
|
version: '1.8.0',
|
|
|
|
layers: layers,
|
|
|
|
dataviews: dataviews || {},
|
|
|
|
analyses: analysis || []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
it('should use overviews to fetch mvt data', function (done) {
|
|
|
|
const mapConfig = createMapConfig(
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'SELECT * FROM test_table_overviews',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
2019-02-22 15:31:22 +08:00
|
|
|
}
|
2018-10-11 23:59:49 +08:00
|
|
|
}
|
2019-02-22 15:31:22 +08:00
|
|
|
]
|
|
|
|
);
|
2018-10-11 23:59:49 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
const testClient = new TestClient(mapConfig);
|
2019-10-22 01:07:24 +08:00
|
|
|
const [z, x, y] = [0, 0, 0];
|
2019-02-22 15:31:22 +08:00
|
|
|
const options = { format: 'mvt' };
|
2018-10-11 23:59:49 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
testClient.getTile(z, x, y, options, function (err, res, mvt) {
|
|
|
|
assert.ifError(err);
|
2018-10-15 14:25:44 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
const geojsonTile = JSON.parse(mvt.toGeoJSONSync(0));
|
2018-10-11 23:59:49 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
assert.ok(Array.isArray(geojsonTile.features));
|
|
|
|
assert.ok(geojsonTile.features.length > 0);
|
2018-10-15 14:25:44 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
const feature = geojsonTile.features[0];
|
2018-10-11 23:59:49 +08:00
|
|
|
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(feature.properties, '_feature_count'), 'Missing _feature_count property');
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(feature.properties.cartodb_id, 1);
|
|
|
|
assert.strictEqual(feature.properties.name, 'Hawai');
|
|
|
|
assert.strictEqual(feature.properties._feature_count, 5); // original table has _feature_count = 1
|
|
|
|
assert.strictEqual(feature.properties.value, 3); // original table has value = 1.0
|
2018-10-11 23:59:49 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2018-10-11 23:59:49 +08:00
|
|
|
});
|
2018-10-15 14:23:39 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
it('first layer should use overviews, second layer shouldn\'t', function (done) {
|
|
|
|
const mapConfig = createMapConfig(
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'SELECT * FROM test_table_overviews',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
2019-02-22 15:31:22 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'SELECT * FROM test_table',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
2019-02-22 15:31:22 +08:00
|
|
|
}
|
2018-10-15 14:23:39 +08:00
|
|
|
}
|
2019-02-22 15:31:22 +08:00
|
|
|
]
|
|
|
|
);
|
2018-10-15 14:23:39 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
const testClient = new TestClient(mapConfig);
|
2019-10-22 01:07:24 +08:00
|
|
|
const [z, x, y] = [0, 0, 0];
|
2019-02-22 15:31:22 +08:00
|
|
|
const options = { format: 'mvt' };
|
2018-10-15 14:23:39 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
testClient.getTile(z, x, y, options, function (err, res, mvt) {
|
|
|
|
assert.ifError(err);
|
2018-10-15 14:23:39 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
const tileWithOverviews = JSON.parse(mvt.toGeoJSONSync(0));
|
|
|
|
const tileWithoutOverviews = JSON.parse(mvt.toGeoJSONSync(1));
|
2018-10-15 14:23:39 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
assert.ok(Array.isArray(tileWithOverviews.features));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tileWithOverviews.features.length, 1);
|
|
|
|
assert.strictEqual(tileWithOverviews.features[0].properties._feature_count, 5);
|
2018-10-15 14:23:39 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
assert.ok(Array.isArray(tileWithoutOverviews.features));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tileWithoutOverviews.features.length, 5);
|
|
|
|
assert.strictEqual(tileWithoutOverviews.features[0].properties._feature_count, undefined);
|
2018-10-15 14:23:39 +08:00
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2018-10-15 14:23:39 +08:00
|
|
|
});
|
|
|
|
});
|
2019-02-22 15:31:22 +08:00
|
|
|
};
|
2017-11-29 20:12:09 +08:00
|
|
|
}
|