2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-03-02 19:43:14 +08:00
|
|
|
require('../../support/test_helper');
|
|
|
|
|
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var TestClient = require('../../support/test-client');
|
|
|
|
var dot = require('dot');
|
2016-05-05 18:17:33 +08:00
|
|
|
var debug = require('debug')('windshaft:cartodb:test');
|
2016-03-02 19:43:14 +08:00
|
|
|
|
2017-09-22 23:41:58 +08:00
|
|
|
describe('analysis-layers use cases', function () {
|
2016-03-02 19:43:14 +08:00
|
|
|
|
|
|
|
|
2017-09-22 23:41:58 +08:00
|
|
|
var multitypeStyleTemplate = dot.template(
|
|
|
|
`#points['mapnik::geometry_type'=1] {
|
|
|
|
marker-fill-opacity: {{=it._opacity}};
|
|
|
|
marker-line-color: #FFF;
|
|
|
|
marker-line-width: 0.5;
|
|
|
|
marker-line-opacity: {{=it._opacity}};
|
|
|
|
marker-placement: point;
|
|
|
|
marker-type: ellipse;
|
|
|
|
marker-width: 8;
|
|
|
|
marker-fill: {{=it._color}};
|
|
|
|
marker-allow-overlap: true;
|
|
|
|
}
|
|
|
|
#lines['mapnik::geometry_type'=2] {
|
|
|
|
line-color: {{=it._color}};
|
|
|
|
line-width: 2;
|
|
|
|
line-opacity: {{=it._opacity}};
|
|
|
|
}
|
|
|
|
#polygons['mapnik::geometry_type'=3] {
|
|
|
|
polygon-fill: {{=it._color}};
|
|
|
|
polygon-opacity: {{=it._opacity}};
|
|
|
|
line-color: #FFF;
|
|
|
|
line-width: 0.5;
|
|
|
|
line-opacity: {{=it._opacity}};
|
|
|
|
}`
|
|
|
|
);
|
2016-03-02 19:43:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
function cartocss(color, opacity) {
|
|
|
|
return multitypeStyleTemplate({
|
|
|
|
_color: color || '#F11810',
|
|
|
|
_opacity: Number.isFinite(opacity) ? opacity : 1
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-03 18:47:52 +08:00
|
|
|
function mapConfig(layers, dataviews, analysis) {
|
2016-03-02 19:43:14 +08:00
|
|
|
return {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: layers,
|
2016-03-03 18:47:52 +08:00
|
|
|
dataviews: dataviews || {},
|
2017-09-22 23:41:58 +08:00
|
|
|
analyses: analysis || []
|
2016-03-02 19:43:14 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var DEFAULT_MULTITYPE_STYLE = cartocss();
|
|
|
|
|
|
|
|
var TILE_ANALYSIS_TABLES = { z: 14, x: 8023, y: 6177 };
|
|
|
|
|
2017-09-22 23:41:58 +08:00
|
|
|
var pointInPolygonDef = {
|
|
|
|
id: 'a1',
|
|
|
|
type: 'point-in-polygon',
|
|
|
|
params: {
|
|
|
|
points_source: {
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from analysis_rent_listings'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
polygons_source: {
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from analysis_banks'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
radius: 250
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var bufferDef = {
|
|
|
|
id: 'b1',
|
|
|
|
type: 'buffer',
|
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from analysis_banks'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
radius: 250
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-02 19:43:14 +08:00
|
|
|
var useCases = [
|
|
|
|
{
|
|
|
|
desc: '1 mapnik layer',
|
|
|
|
mapConfig: {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2017-09-22 23:41:58 +08:00
|
|
|
sql: 'select * from analysis_rent_listings',
|
2016-03-02 19:43:14 +08:00
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
desc: '2 mapnik layers',
|
|
|
|
mapConfig: mapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2017-09-22 23:41:58 +08:00
|
|
|
sql: 'select * from analysis_banks',
|
2016-03-02 19:43:14 +08:00
|
|
|
cartocss: cartocss('#2167AB'),
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2017-09-22 23:41:58 +08:00
|
|
|
sql: 'select * from analysis_rent_listings',
|
2016-03-02 19:43:14 +08:00
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
desc: 'rent listings + buffer over atm-machines',
|
|
|
|
mapConfig: mapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2017-09-22 23:41:58 +08:00
|
|
|
sql: 'select * from analysis_rent_listings',
|
2016-03-02 19:43:14 +08:00
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-09-22 23:41:58 +08:00
|
|
|
type: 'cartodb',
|
2016-03-02 19:43:14 +08:00
|
|
|
options: {
|
2017-09-22 23:41:58 +08:00
|
|
|
source: {
|
|
|
|
id: 'b1'
|
|
|
|
},
|
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
2016-03-02 19:43:14 +08:00
|
|
|
}
|
|
|
|
}
|
2017-09-22 23:41:58 +08:00
|
|
|
],
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
bufferDef
|
|
|
|
]
|
|
|
|
)
|
2016-03-02 19:43:14 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
desc: 'rent listings + point-in-polygon from buffer atm-machines and rent listings',
|
|
|
|
mapConfig: mapConfig([
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2017-09-22 23:41:58 +08:00
|
|
|
sql: 'select * from analysis_rent_listings',
|
2016-03-02 19:43:14 +08:00
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
2017-09-22 23:41:58 +08:00
|
|
|
source: {
|
|
|
|
id: 'a1'
|
|
|
|
},
|
2016-03-02 19:43:14 +08:00
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
2017-09-22 23:41:58 +08:00
|
|
|
],
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
pointInPolygonDef
|
|
|
|
]
|
|
|
|
)
|
2016-03-02 19:43:14 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2017-09-22 23:41:58 +08:00
|
|
|
desc: 'point-in-polygon from buffer atm-machines and rent listings + rent listings',
|
|
|
|
mapConfig: mapConfig(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'a1'
|
|
|
|
},
|
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from analysis_rent_listings',
|
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
2016-03-02 19:43:14 +08:00
|
|
|
}
|
2017-09-22 23:41:58 +08:00
|
|
|
],
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
pointInPolygonDef
|
|
|
|
]
|
|
|
|
)
|
2016-03-02 19:43:14 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
desc: 'buffer + point-in-polygon from buffer atm-machines and rent listings + rent listings',
|
2017-09-22 23:41:58 +08:00
|
|
|
mapConfig: mapConfig(
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from analysis_rent_listings',
|
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'a1'
|
2016-03-02 19:43:14 +08:00
|
|
|
},
|
2017-09-22 23:41:58 +08:00
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'b1'
|
|
|
|
},
|
|
|
|
cartocss: DEFAULT_MULTITYPE_STYLE,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
2016-03-02 19:43:14 +08:00
|
|
|
}
|
2017-09-22 23:41:58 +08:00
|
|
|
],
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
bufferDef,
|
|
|
|
pointInPolygonDef
|
|
|
|
]
|
|
|
|
)
|
2016-03-02 19:43:14 +08:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2017-09-22 23:41:58 +08:00
|
|
|
useCases.forEach(function (useCase) {
|
2016-03-02 19:43:14 +08:00
|
|
|
if (!!useCase.skip) {
|
2017-09-22 23:41:58 +08:00
|
|
|
return debug(JSON.stringify(useCase.mapConfig, null, 4));
|
2016-03-02 19:43:14 +08:00
|
|
|
}
|
2017-09-22 23:41:58 +08:00
|
|
|
it(`should implement use case: '${useCase.desc}'`, function (done) {
|
2016-03-02 19:43:14 +08:00
|
|
|
|
|
|
|
var testClient = new TestClient(useCase.mapConfig, 1234);
|
|
|
|
|
|
|
|
var tile = useCase.tile || TILE_ANALYSIS_TABLES;
|
|
|
|
|
2017-09-22 23:41:58 +08:00
|
|
|
testClient.getTile(tile.z, tile.x, tile.y, function (err, res, image) {
|
2016-03-02 19:43:14 +08:00
|
|
|
assert.ok(!err, err);
|
|
|
|
|
2017-09-22 23:41:58 +08:00
|
|
|
//image.save('/tmp/tests/' + imageIdx + '---' + useCase.desc.replace(/\s/g, '-') + '.png');
|
2016-03-02 19:43:14 +08:00
|
|
|
|
|
|
|
assert.equal(image.width(), 256);
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|