2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2018-01-03 23:54:45 +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-01-03 23:54:45 +08:00
|
|
|
|
2018-10-17 17:12:58 +08:00
|
|
|
const originalUsePostGIS = serverOptions.renderer.mvt.usePostGIS;
|
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
describe('tilejson via mapnik renderer', () => tileJsonSuite(false));
|
|
|
|
describe('tilejson via postgis renderer', () => tileJsonSuite(true));
|
2018-10-17 17:12:58 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function tileJsonSuite (usePostGIS) {
|
|
|
|
before(function () {
|
2018-10-17 17:12:58 +08:00
|
|
|
serverOptions.renderer.mvt.usePostGIS = usePostGIS;
|
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
|
|
|
|
});
|
2018-01-03 23:54:45 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function tilejsonValidation (tilejson, shouldHaveGrid = false) {
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tilejson.tilejson, '2.2.0');
|
2018-01-03 23:54:45 +08:00
|
|
|
|
2018-01-04 04:53:03 +08:00
|
|
|
assert.ok(Array.isArray(tilejson.tiles), JSON.stringify(tilejson));
|
2018-01-03 23:54:45 +08:00
|
|
|
assert.ok(tilejson.tiles.length > 0);
|
|
|
|
|
|
|
|
if (shouldHaveGrid) {
|
|
|
|
assert.ok(Array.isArray(tilejson.grids));
|
|
|
|
assert.ok(tilejson.grids.length > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const sql = 'SELECT * FROM populated_places_simple_reduced';
|
|
|
|
const cartocss = TestClient.CARTOCSS.POINTS;
|
2019-11-06 23:44:17 +08:00
|
|
|
const cartocssVersion = '3.0.12';
|
2018-01-03 23:54:45 +08:00
|
|
|
|
|
|
|
const RASTER_LAYER = {
|
|
|
|
options: {
|
2019-11-06 23:44:17 +08:00
|
|
|
sql, cartocss, cartocss_version: cartocssVersion
|
2018-01-03 23:54:45 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
const RASTER_INTERACTIVITY_LAYER = {
|
|
|
|
options: {
|
2019-10-22 01:07:24 +08:00
|
|
|
sql,
|
|
|
|
cartocss,
|
2019-11-06 23:44:17 +08:00
|
|
|
cartocss_version: cartocssVersion,
|
2018-01-03 23:54:45 +08:00
|
|
|
interactivity: ['cartodb_id']
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const VECTOR_LAYER = {
|
|
|
|
options: {
|
|
|
|
sql
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const PLAIN_LAYER = {
|
|
|
|
type: 'plain',
|
|
|
|
options: {
|
|
|
|
color: '#000000'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function mapConfig (layers) {
|
2018-01-03 23:54:45 +08:00
|
|
|
return {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: Array.isArray(layers) ? layers : [layers]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('per layer', function () {
|
|
|
|
it('should expose raster + vector tilejson for raster layers', function (done) {
|
2018-01-03 23:54:45 +08:00
|
|
|
var testClient = new TestClient(mapConfig(RASTER_LAYER));
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup(function (err, layergroupResult) {
|
2018-01-03 23:54:45 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
const metadata = layergroupResult.metadata;
|
|
|
|
assert.ok(metadata);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(metadata.layers.length, 1);
|
2018-01-03 23:54:45 +08:00
|
|
|
|
|
|
|
const layer = metadata.layers[0];
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(Object.keys(layer.tilejson), ['vector', 'raster']);
|
2018-01-03 23:54:45 +08:00
|
|
|
|
|
|
|
Object.keys(layer.tilejson).forEach(k => {
|
|
|
|
tilejsonValidation(layer.tilejson[k]);
|
|
|
|
});
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose just the vector tilejson vector only layers', function (done) {
|
2018-01-03 23:54:45 +08:00
|
|
|
var testClient = new TestClient(mapConfig(VECTOR_LAYER));
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup(function (err, layergroupResult) {
|
2018-01-03 23:54:45 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
const metadata = layergroupResult.metadata;
|
|
|
|
assert.ok(metadata);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(metadata.layers.length, 1);
|
2018-01-03 23:54:45 +08:00
|
|
|
|
|
|
|
const layer = metadata.layers[0];
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(Object.keys(layer.tilejson), ['vector']);
|
2018-01-03 23:54:45 +08:00
|
|
|
|
|
|
|
Object.keys(layer.tilejson).forEach(k => {
|
|
|
|
tilejsonValidation(layer.tilejson[k]);
|
|
|
|
});
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose just the raster tilejson plain layers', function (done) {
|
2018-01-03 23:54:45 +08:00
|
|
|
var testClient = new TestClient(mapConfig(PLAIN_LAYER));
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup(function (err, layergroupResult) {
|
2018-01-03 23:54:45 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
const metadata = layergroupResult.metadata;
|
|
|
|
assert.ok(metadata);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(metadata.layers.length, 1);
|
2018-01-03 23:54:45 +08:00
|
|
|
|
|
|
|
const layer = metadata.layers[0];
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(Object.keys(layer.tilejson), ['raster']);
|
2018-01-03 23:54:45 +08:00
|
|
|
|
|
|
|
Object.keys(layer.tilejson).forEach(k => {
|
|
|
|
tilejsonValidation(layer.tilejson[k]);
|
|
|
|
});
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose grids for the raster layer with interactivity', function (done) {
|
2018-01-03 23:54:45 +08:00
|
|
|
var testClient = new TestClient(mapConfig(RASTER_INTERACTIVITY_LAYER));
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup(function (err, layergroupResult) {
|
2018-01-03 23:54:45 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
const metadata = layergroupResult.metadata;
|
|
|
|
assert.ok(metadata);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(metadata.layers.length, 1);
|
2018-01-03 23:54:45 +08:00
|
|
|
|
|
|
|
const layer = metadata.layers[0];
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(Object.keys(layer.tilejson), ['vector', 'raster']);
|
2018-01-03 23:54:45 +08:00
|
|
|
|
|
|
|
tilejsonValidation(layer.tilejson.vector);
|
|
|
|
tilejsonValidation(layer.tilejson.raster, true);
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should work with several layers', function (done) {
|
2018-01-03 23:54:45 +08:00
|
|
|
var testClient = new TestClient(mapConfig([RASTER_LAYER, RASTER_INTERACTIVITY_LAYER]));
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup(function (err, layergroupResult) {
|
2018-01-03 23:54:45 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
const metadata = layergroupResult.metadata;
|
|
|
|
assert.ok(metadata);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(metadata.layers.length, 2);
|
2018-01-03 23:54:45 +08:00
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(Object.keys(metadata.layers[0].tilejson), ['vector', 'raster']);
|
2018-01-03 23:54:45 +08:00
|
|
|
tilejsonValidation(metadata.layers[0].tilejson.vector);
|
|
|
|
tilejsonValidation(metadata.layers[0].tilejson.raster);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(Object.keys(metadata.layers[1].tilejson), ['vector', 'raster']);
|
2018-01-03 23:54:45 +08:00
|
|
|
tilejsonValidation(metadata.layers[1].tilejson.vector);
|
|
|
|
tilejsonValidation(metadata.layers[1].tilejson.raster, true);
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('root tilejson', function () {
|
|
|
|
it('should expose just the `vector` tilejson and URL when for vector only mapnik layers', function (done) {
|
2018-01-03 23:54:45 +08:00
|
|
|
var testClient = new TestClient(mapConfig(VECTOR_LAYER));
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup(function (err, layergroupResult) {
|
2018-01-03 23:54:45 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
const metadata = layergroupResult.metadata;
|
|
|
|
assert.ok(metadata);
|
|
|
|
|
|
|
|
const tilejson = metadata.tilejson;
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(Object.keys(tilejson), ['vector']);
|
2018-01-03 23:54:45 +08:00
|
|
|
|
|
|
|
Object.keys(tilejson).forEach(k => {
|
|
|
|
tilejsonValidation(tilejson[k]);
|
|
|
|
});
|
|
|
|
|
2018-01-04 04:53:03 +08:00
|
|
|
const url = metadata.url;
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(Object.keys(url), ['vector']);
|
2018-01-04 04:53:03 +08:00
|
|
|
|
2018-01-04 06:18:59 +08:00
|
|
|
assert.ok(url.vector.urlTemplate);
|
|
|
|
assert.ok(url.vector.subdomains);
|
2018-01-04 04:53:03 +08:00
|
|
|
|
2018-01-03 23:54:45 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should expose just the `vector` and `raster` tilejson and urls for mapnik layers', function (done) {
|
2018-01-03 23:54:45 +08:00
|
|
|
var testClient = new TestClient(mapConfig(RASTER_LAYER));
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup(function (err, layergroupResult) {
|
2018-01-03 23:54:45 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
const metadata = layergroupResult.metadata;
|
|
|
|
assert.ok(metadata);
|
|
|
|
|
|
|
|
const tilejson = metadata.tilejson;
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(Object.keys(tilejson), ['vector', 'raster']);
|
2018-01-03 23:54:45 +08:00
|
|
|
|
|
|
|
Object.keys(tilejson).forEach(k => {
|
|
|
|
tilejsonValidation(tilejson[k]);
|
|
|
|
});
|
|
|
|
|
2018-01-04 04:53:03 +08:00
|
|
|
const url = metadata.url;
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(Object.keys(url), ['vector', 'raster']);
|
2018-01-04 04:53:03 +08:00
|
|
|
|
2018-01-04 06:18:59 +08:00
|
|
|
assert.ok(url.vector.urlTemplate);
|
|
|
|
assert.ok(url.vector.subdomains);
|
2018-01-04 04:53:03 +08:00
|
|
|
|
2018-01-04 06:18:59 +08:00
|
|
|
assert.ok(url.raster.urlTemplate);
|
|
|
|
assert.ok(url.raster.subdomains);
|
2018-01-04 04:53:03 +08:00
|
|
|
|
2018-01-03 23:54:45 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-17 17:12:58 +08:00
|
|
|
}
|