2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../support/test-helper');
|
2017-11-30 01:17:51 +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-11-30 01:17:51 +08:00
|
|
|
|
|
|
|
const POINTS_SQL_1 = `
|
|
|
|
select
|
|
|
|
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
|
|
|
|
`;
|
|
|
|
|
|
|
|
const POINTS_SQL_2 = `
|
|
|
|
select
|
|
|
|
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,
|
|
|
|
x as value
|
|
|
|
from generate_series(-3, 3) x
|
|
|
|
`;
|
|
|
|
|
|
|
|
function createVectorLayergroup () {
|
|
|
|
return {
|
|
|
|
version: '1.6.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_1
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: POINTS_SQL_2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const INCOMPATIBLE_LAYERS_ERROR = {
|
2019-10-22 01:07:24 +08:00
|
|
|
errors: [
|
|
|
|
'The `mapnik` or `cartodb` layers must be consistent:' +
|
|
|
|
' `cartocss` option is either present or voided in all layers. Mixing is not allowed.'
|
2017-11-30 01:17:51 +08:00
|
|
|
],
|
2019-10-22 01:07:24 +08:00
|
|
|
errors_with_context: [
|
2017-11-30 01:17:51 +08:00
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'mapconfig',
|
|
|
|
message: 'The `mapnik` or `cartodb` layers must be consistent:' +
|
|
|
|
' `cartocss` option is either present or voided in all layers. Mixing is not allowed.'
|
2017-11-30 01:17:51 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
const INVALID_FORMAT_ERROR = {
|
2019-10-22 01:07:24 +08:00
|
|
|
errors: [
|
2017-12-01 20:52:28 +08:00
|
|
|
"Unsupported format: 'cartocss' option is missing for png"
|
2017-11-30 01:17:51 +08:00
|
|
|
],
|
2019-10-22 01:07:24 +08:00
|
|
|
errors_with_context: [
|
2017-11-30 01:17:51 +08:00
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'tile',
|
|
|
|
message: "Unsupported format: 'cartocss' option is missing for png"
|
2017-11-30 01:17:51 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-02-22 15:31:22 +08:00
|
|
|
const suites = [
|
|
|
|
{
|
|
|
|
desc: 'mvt (mapnik)',
|
|
|
|
usePostGIS: false
|
|
|
|
},
|
|
|
|
{
|
2017-11-30 01:17:51 +08:00
|
|
|
desc: 'mvt (postgis)',
|
|
|
|
usePostGIS: true
|
2019-02-22 15:31:22 +08:00
|
|
|
}
|
|
|
|
];
|
2017-11-30 01:17:51 +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 () {
|
2017-11-30 01:17:51 +08:00
|
|
|
serverOptions.renderer.mvt.usePostGIS = originalUsePostGIS;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('vector-layergroup', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.mapConfig = createVectorLayergroup();
|
|
|
|
this.testClient = new TestClient(this.mapConfig);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get vector tiles from layergroup with layers w/o cartocss', function (done) {
|
|
|
|
this.testClient.getTile(0, 0, 0, { format: 'mvt' }, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tile.tileSize, 4096);
|
|
|
|
assert.strictEqual(tile.z, 0);
|
|
|
|
assert.strictEqual(tile.x, 0);
|
|
|
|
assert.strictEqual(tile.y, 0);
|
2017-11-30 01:17:51 +08:00
|
|
|
|
|
|
|
const layer0 = JSON.parse(tile.toGeoJSONSync(0));
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layer0.name, 'layer0');
|
|
|
|
assert.strictEqual(layer0.features[0].type, 'Feature');
|
|
|
|
assert.strictEqual(layer0.features[0].geometry.type, 'Point');
|
2017-11-30 01:17:51 +08:00
|
|
|
|
|
|
|
const layer1 = JSON.parse(tile.toGeoJSONSync(1));
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layer1.name, 'layer1');
|
|
|
|
assert.strictEqual(layer1.features[0].type, 'Feature');
|
|
|
|
assert.strictEqual(layer1.features[0].geometry.type, 'Point');
|
2017-11-30 01:17:51 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get vector tiles from specific layer (layer0)', function (done) {
|
|
|
|
this.testClient.getTile(0, 0, 0, { format: 'mvt', layers: 0 }, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tile.tileSize, 4096);
|
|
|
|
assert.strictEqual(tile.z, 0);
|
|
|
|
assert.strictEqual(tile.x, 0);
|
|
|
|
assert.strictEqual(tile.y, 0);
|
2017-11-30 01:17:51 +08:00
|
|
|
|
|
|
|
const layer = JSON.parse(tile.toGeoJSONSync(0));
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layer.name, 'layer0');
|
|
|
|
assert.strictEqual(layer.features[0].type, 'Feature');
|
|
|
|
assert.strictEqual(layer.features[0].geometry.type, 'Point');
|
2017-11-30 01:17:51 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should get vector tiles from specific layer (layer1)', function (done) {
|
|
|
|
this.testClient.getTile(0, 0, 0, { format: 'mvt', layers: 1 }, (err, res, tile) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(tile.tileSize, 4096);
|
|
|
|
assert.strictEqual(tile.z, 0);
|
|
|
|
assert.strictEqual(tile.x, 0);
|
|
|
|
assert.strictEqual(tile.y, 0);
|
2017-11-30 01:17:51 +08:00
|
|
|
|
|
|
|
const layer = JSON.parse(tile.toGeoJSONSync(0));
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layer.name, 'layer1');
|
|
|
|
assert.strictEqual(layer.features[0].type, 'Feature');
|
|
|
|
assert.strictEqual(layer.features[0].geometry.type, 'Point');
|
2017-11-30 01:17:51 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when the format requested is not mvt', function (done) {
|
|
|
|
const options = {
|
|
|
|
format: 'png',
|
|
|
|
response: {
|
|
|
|
status: 400,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.testClient.getTile(0, 0, 0, options, (err, res, body) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, INVALID_FORMAT_ERROR);
|
2017-11-30 01:17:51 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail when the map-config mix layers with and without cartocss', function (done) {
|
|
|
|
const response = {
|
|
|
|
status: 400,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
const cartocss = '#layer0 { marker-fill: red; marker-width: 10; }';
|
2017-11-30 01:28:42 +08:00
|
|
|
const cartocssVersion = '2.3.0';
|
|
|
|
|
|
|
|
this.testClient.mapConfig.layers[0].options.cartocss = cartocss;
|
|
|
|
this.testClient.mapConfig.layers[0].options.cartocss_version = cartocssVersion;
|
|
|
|
|
2017-12-05 19:09:31 +08:00
|
|
|
this.testClient.getLayergroup({ response }, (err, body) => {
|
2017-11-30 01:17:51 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(body, INCOMPATIBLE_LAYERS_ERROR);
|
2017-11-30 01:17:51 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|