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) { ...@@ -75,8 +75,16 @@ module.exports = function(app, pool) {
srid: row.srid, srid: row.srid,
bboxsrid: row.bboxsrid?row.bboxsrid.match(/BOX\((.*)\)/)[1].split(',').map(coord=>coord.split(' ').map(c=>parseFloat(c))):null 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 { } else {
throw(new Error('bbox query did not return 1 row')); throw(new Error('bbox query returned more than 1 row'));
} }
} catch(err) { } catch(err) {
console.log(err); console.log(err);
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
function initMap() function initMap()
{ {
map = new mapboxgl.Map({ const mapDefinition = {
container: 'map', container: 'map',
"style": { "style": {
"version": 8, "version": 8,
...@@ -98,7 +98,13 @@ ...@@ -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) { 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)};}); 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); document.getElementById('info').innerHTML = JSON.stringify(features.map(feature=>feature.properties), null, 2);
......
...@@ -67,7 +67,7 @@ ...@@ -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>' + 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> layerInfo.map(item=>`<tr>
<td>${item.f_table_schema}</td> <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.f_geometry_column}</td>
<td>${item.srid}</td> <td>${item.srid}</td>
<td>${item.type}</td> <td>${item.type}</td>
......
...@@ -6,12 +6,21 @@ ...@@ -6,12 +6,21 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Info</title> <title>Info</title>
<script> <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() { function init() {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const fullTableName = urlParams.get('table'); const fullTableName = urlParams.get('table');
const geomType = urlParams.get('geomtype'); 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; document.querySelector('#tablename').innerHTML = fullTableName;
const parts = fullTableName.split('.'); const parts = fullTableName.split('.');
const tableName = (parts.length > 1) ? parts[1] : parts[0]; const tableName = (parts.length > 1) ? parts[1] : parts[0];
...@@ -35,11 +44,12 @@ ...@@ -35,11 +44,12 @@
const bbox = document.querySelector('#bbox'); const bbox = document.querySelector('#bbox');
if (response.ok) { if (response.ok) {
response.json().then(json=> { response.json().then(json=> {
addBboxllToLinks(json.bboxll);
bbox.innerHTML = `number of rows: ${json.allrows}<br> bbox.innerHTML = `number of rows: ${json.allrows}<br>
number of geometries: ${json.geomrows}<br> number of geometries: ${json.geomrows}<br>
srid: EPSG:${json.srid}<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 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}): ll: ${json.bboxsrid[0][0]},${json.bboxsrid[0][1]}, tr: ${json.bboxsrid[1][0]},${json.bboxsrid[1][1]}<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 { } 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