Commit 120af7fb authored by Anne Blankert's avatar Anne Blankert

handle zero result, zoom map to bbox if available

parent d53a469f
......@@ -75,8 +75,16 @@ module.exports = function(app, pool) {
srid: row.srid,
bboxsrid: row.bboxsrid?row.bboxsrid.match(/BOX\((.*)\)/)[1].split(',').map(coord=>coord.split(' ').map(c=>parseFloat(c))):null
})
} else if (result.rows.length === 0) {
res.json({
allrows: 0,
geomrows: 0,
bboxll: null,
srid: 0,
bboxsrid: null
})
} else {
throw(new Error('bbox query did not return 1 row'));
throw(new Error('bbox query returned more than 1 row'));
}
} catch(err) {
console.log(err);
......
......@@ -73,7 +73,7 @@
function initMap()
{
map = new mapboxgl.Map({
const mapDefinition = {
container: 'map',
"style": {
"version": 8,
......@@ -98,7 +98,13 @@
}
]
}
});
}
const urlParams = new URLSearchParams(window.location.search);
const bboxll = urlParams.get('bboxll');
if (bboxll) {
mapDefinition.bounds = JSON.parse(bboxll);
}
map = new mapboxgl.Map(mapDefinition);
map.on('mousemove', function (e) {
var features = map.queryRenderedFeatures(e.point).map(function(feature){ return {layer: {id: feature.layer.id, type: feature.layer.type}, properties:(feature.properties)};});
document.getElementById('info').innerHTML = JSON.stringify(features.map(feature=>feature.properties), null, 2);
......
......@@ -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><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>${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>${item.f_geometry_column}</td>
<td>${item.srid}</td>
<td>${item.type}</td>
......
......@@ -7,11 +7,20 @@
<title>Info</title>
<script>
function addBboxllToLinks(bboxll)
{
if (bboxll) {
document.querySelectorAll('#columns > li > a')
.forEach(a=>(a.setAttribute('href', a.getAttribute('href') + '&bboxll='+JSON.stringify(bboxll))))
}
}
function init() {
const urlParams = new URLSearchParams(window.location.search);
const fullTableName = urlParams.get('table');
const geomType = urlParams.get('geomtype');
const geomcolumn = urlParams.get('geom_column')
const geomcolumn = urlParams.get('geom_column');
let bboxll = null;
document.querySelector('#tablename').innerHTML = fullTableName;
const parts = fullTableName.split('.');
const tableName = (parts.length > 1) ? parts[1] : parts[0];
......@@ -35,11 +44,12 @@
const bbox = document.querySelector('#bbox');
if (response.ok) {
response.json().then(json=> {
addBboxllToLinks(json.bboxll);
bbox.innerHTML = `number of rows: ${json.allrows}<br>
number of geometries: ${json.geomrows}<br>
srid: EPSG:${json.srid}<br>
bbox lon/lat: sw: ${json.bboxll[0][0]},${json.bboxll[0][1]}, ne: ${json.bboxll[1][0]},${json.bboxll[1][1]}<br>
bbox (EPSG:${json.srid}): ll: ${json.bboxsrid[0][0]},${json.bboxsrid[0][1]}, tr: ${json.bboxsrid[1][0]},${json.bboxsrid[1][1]}<br>
bbox lon/lat: ${json.bboxll?`sw: ${json.bboxll[0][0]},${json.bboxll[0][1]}, ne: ${json.bboxll[1][0]},${json.bboxll[1][1]}`: 'not defined'}<br>
bbox (EPSG:${json.srid}): ${json.srid?`ll: ${json.bboxsrid[0][0]},${json.bboxsrid[0][1]}, tr: ${json.bboxsrid[1][0]},${json.bboxsrid[1][1]}`: 'not defined'}<br>
`
})
} else {
......
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