2019-02-27 02:19:44 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const layergroupToken = require('../middlewares/layergroup-token');
|
|
|
|
const cleanUpQueryParams = require('../middlewares/clean-up-query-params');
|
|
|
|
const credentials = require('../middlewares/credentials');
|
|
|
|
const dbConnSetup = require('../middlewares/db-conn-setup');
|
|
|
|
const authorize = require('../middlewares/authorize');
|
|
|
|
const rateLimit = require('../middlewares/rate-limit');
|
|
|
|
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
|
|
|
|
const createMapStoreMapConfigProvider = require('../middlewares/map-store-map-config-provider');
|
|
|
|
const cacheControlHeader = require('../middlewares/cache-control-header');
|
|
|
|
const cacheChannelHeader = require('../middlewares/cache-channel-header');
|
|
|
|
const surrogateKeyHeader = require('../middlewares/surrogate-key-header');
|
|
|
|
const lastModifiedHeader = require('../middlewares/last-modified-header');
|
|
|
|
|
|
|
|
module.exports = class AggregatedFeaturesLayergroupController {
|
|
|
|
constructor (
|
|
|
|
clusterBackend,
|
|
|
|
pgConnection,
|
|
|
|
mapStore,
|
|
|
|
userLimitsBackend,
|
|
|
|
layergroupAffectedTablesCache,
|
|
|
|
authBackend,
|
|
|
|
surrogateKeysCache
|
|
|
|
) {
|
|
|
|
this.clusterBackend = clusterBackend;
|
|
|
|
this.pgConnection = pgConnection;
|
|
|
|
this.mapStore = mapStore;
|
|
|
|
this.userLimitsBackend = userLimitsBackend;
|
|
|
|
this.layergroupAffectedTablesCache = layergroupAffectedTablesCache;
|
|
|
|
this.authBackend = authBackend;
|
|
|
|
this.surrogateKeysCache = surrogateKeysCache;
|
|
|
|
}
|
|
|
|
|
2019-10-04 18:22:23 +08:00
|
|
|
route (mapRouter) {
|
2019-02-27 19:42:54 +08:00
|
|
|
mapRouter.get('/:token/:layer/:z/cluster/:clusterId', this.middlewares());
|
2019-02-27 02:19:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
middlewares () {
|
|
|
|
return [
|
|
|
|
layergroupToken(),
|
|
|
|
credentials(),
|
|
|
|
authorize(this.authBackend),
|
|
|
|
dbConnSetup(this.pgConnection),
|
2019-03-02 00:49:26 +08:00
|
|
|
// TODO: create its rate limit
|
2019-02-27 02:19:44 +08:00
|
|
|
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ATTRIBUTES),
|
2019-10-22 01:07:24 +08:00
|
|
|
cleanUpQueryParams(['aggregation']),
|
2019-02-27 02:19:44 +08:00
|
|
|
createMapStoreMapConfigProvider(
|
|
|
|
this.mapStore,
|
|
|
|
this.userLimitsBackend,
|
|
|
|
this.pgConnection,
|
|
|
|
this.layergroupAffectedTablesCache
|
|
|
|
),
|
|
|
|
getClusteredFeatures(this.clusterBackend),
|
|
|
|
cacheControlHeader(),
|
|
|
|
cacheChannelHeader(),
|
|
|
|
surrogateKeyHeader({ surrogateKeysCache: this.surrogateKeysCache }),
|
|
|
|
lastModifiedHeader()
|
|
|
|
];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function getClusteredFeatures (clusterBackend) {
|
|
|
|
return function getFeatureAttributesMiddleware (req, res, next) {
|
|
|
|
req.profiler.start('windshaft.maplayer_cluster_features');
|
|
|
|
|
|
|
|
const { mapConfigProvider } = res.locals;
|
2019-02-28 01:54:21 +08:00
|
|
|
const { user, token } = res.locals;
|
2019-02-27 02:19:44 +08:00
|
|
|
const { dbuser, dbname, dbpassword, dbhost, dbport } = res.locals;
|
2019-02-27 19:42:54 +08:00
|
|
|
const { layer, z: zoom, clusterId } = req.params;
|
2019-03-01 18:21:18 +08:00
|
|
|
const { aggregation } = req.query;
|
2019-02-27 02:19:44 +08:00
|
|
|
|
|
|
|
const params = {
|
2019-10-22 01:07:24 +08:00
|
|
|
user,
|
|
|
|
token,
|
|
|
|
dbuser,
|
|
|
|
dbname,
|
|
|
|
dbpassword,
|
|
|
|
dbhost,
|
|
|
|
dbport,
|
|
|
|
layer,
|
|
|
|
zoom,
|
|
|
|
clusterId,
|
2019-03-01 18:21:18 +08:00
|
|
|
aggregation
|
2019-02-27 02:19:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
clusterBackend.getClusterFeatures(mapConfigProvider, params, (err, features, stats = {}) => {
|
|
|
|
req.profiler.add(stats);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
err.label = 'GET CLUSTERED FEATURES';
|
|
|
|
return next(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
res.statusCode = 200;
|
2019-03-02 00:34:32 +08:00
|
|
|
const { rows, fields } = features;
|
|
|
|
res.body = { rows, fields };
|
2019-02-27 02:19:44 +08:00
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|