Project 'adan.salazar/GeoSentinel' was moved to 'mario.chirinos/GeoSentinel'. Please update any links and bookmarks that may still have the old path.
Commit 3b5cf385 authored by Anne Blankert's avatar Anne Blankert

cache bbox,translate to english,support views

parent 0a9d9246
// based on https://raw.githubusercontent.com/tobinbradley/dirt-simple-postgis-http-api/master/routes/bbox.js
const sqlTableName = require('./utils/sqltablename.js');
const DirCache = require('./utils/dircache.js')
const cache = new DirCache('./cache');
const sql = (params, query) => {
......@@ -18,6 +20,30 @@ select allrows, geomrows, bboxll,srid,bboxsrid from bboxll,srid,bboxsrid
`
}
let cacheMiddleware = async(req, res, next) => {
const cacheDir = `${req.params.table}/bbox`
const key = ((req.query.geom_column?req.query.geom_column:'geom')
+ (req.query.columns?'_'+req.query.columns:'')
+ (req.query.filter?'_'+req.query.filter:''))
.replace(/[\W]+/g, '_');
const bbox = await cache.getCachedFile(cacheDir, key);
if (bbox) {
console.log(`bbox cache hit for ${cacheDir}?${key}`);
res.header('Content-Type', 'application/json').send(bbox);
return;
} else {
res.sendResponse = res.send;
res.send = (body) => {
if (res.statusCode >= 200 && res.statusCode < 300) {
cache.setCachedFile(cacheDir, key, body);
}
res.sendResponse(body);
}
next();
}
}
module.exports = function(app, pool) {
/**
* @swagger
......@@ -38,11 +64,6 @@ module.exports = function(app, pool) {
* description: name of geometry column (default 'geom')
* in: query
* required: false
* - name: strid
* description: 'The SRID for the returned centroid. The default is <em>4326</em> WGS84 Lat/Lng.'
* in: query
* required: false
* type: integer
* - name: filter
* type: string
* description: 'Optional filter parameters for a SQL WHERE statement.'
......@@ -50,13 +71,47 @@ module.exports = function(app, pool) {
* required: false
* responses:
* 200:
* description: vector tile
* 204:
* description: no data (empty tile)
* description: boundingboxes and row counters
* content:
* application/json
* schema:
* type: object
* properties:
* allrows:
* type: integer
* description: number of rows in table
* geomrows:
* type: integer
* description: number of non-null geometries in table
* bboxll:
* description: boundingbox of geometries defined in latitude and longitude
* type: array
* minItems: 2
* maxItems: 2
* items:
* type: array
* minItems: 2
* maxItems: 2
* items:
* type: number
* srid:
* type: integer
* description: id of spatial reference system (EPSG code) used by geometries
* bboxsrid:
* description: boundingbox of geometries defined using geometry srid
* type: array
* minItems: 2
* maxItems: 2
* items:
* type: array
* minItems: 2
* maxItems: 2
* items:
* type: number
* 422:
* description: invalid datasource or columnname
*/
app.get('/api/bbox/:table', async (req, res)=>{
app.get('/api/bbox/:table', cacheMiddleware, async (req, res)=>{
if (!req.query.geom_column) {
req.query.geom_column = 'geom'; //default
}
......
......@@ -252,10 +252,10 @@
if (response.ok) {
response.json().then(json=> {
const div = document.querySelector('#attrinfo');
div.innerHTML = `<b>aantal</b>:${json[0].count}<br>
<b>verschillend</b>:${json[0].distinct}<br>
<b>min</b>:${json[0].min}<br>
<b>max</b>:${json[0].max}<br>`;
div.innerHTML = `<b>count</b>:${json[0].count}<br>
<b>nr of unique values</b>:${json[0].distinct}<br>
<b>minimum</b>:${json[0].min}<br>
<b>maximum</b>:${json[0].max}<br>`;
})
}
})
......@@ -358,7 +358,7 @@ linearTicks.min: ${linearTicks.min}, linearTicks.max: ${linearTicks.max}, linear
data: {
labels: histLabels,
datasets: [{
label: `aantal ${tableName}`,
label: `count of ${tableName}`,
data: values,
backgroundColor: "blue",
borderColor: "white",
......@@ -426,7 +426,7 @@ linearTicks.min: ${linearTicks.min}, linearTicks.max: ${linearTicks.max}, linear
</script>
</head>
<body onload="init()">
<h1>Attribuut-informatie</h1>
<h1>Attribuut-information</h1>
<h2 id="tablename"></h2>
<h2 id="columnname"></h2>
<div id="attrinfo"></div>
......
......@@ -67,7 +67,7 @@
table.innerHTML = '<tr><th>schema</th><th>name</th><th>geom_column</th><th>srid</th><th>geom_type</th><th>dim</th><th>count</th></tr>' +
layerInfo.map(item=>`<tr>
<td>${item.f_table_schema}</td>
<td>${Number(item.estimated_rows)?`<a href="tableinfo.html?table=${item.f_table_schema}.${item.f_table_name}&geom_column=${item.f_geometry_column}&srid=${item.srid}&geomtype=${item.type}&dimensions=${item.coord_dimension}&estimated_rows=${item.estimated_rows}">${item.f_table_name}</a>`:`${item.f_table_name}`}</td>
<td><a href="tableinfo.html?table=${item.f_table_schema}.${item.f_table_name}&geom_column=${item.f_geometry_column}&srid=${item.srid}&geomtype=${item.type}&dimensions=${item.coord_dimension}&estimated_rows=${item.estimated_rows}">${item.f_table_name}</a></td>
<td>${item.f_geometry_column}</td>
<td>${item.srid}</td>
<td>${item.type}</td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment