@opengis/gis 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +1 -1
- package/dist/index.js +79 -79
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
- package/server/routes/map/index.mjs +9 -9
- package/server/routes/map/maps/get.map.js +54 -50
package/package.json
CHANGED
|
@@ -29,18 +29,18 @@ const schemaInfo = {
|
|
|
29
29
|
type: 'string',
|
|
30
30
|
},
|
|
31
31
|
z: {
|
|
32
|
-
type: 'number'
|
|
32
|
+
type: 'number',
|
|
33
33
|
},
|
|
34
34
|
y: {
|
|
35
|
-
type: 'number'
|
|
35
|
+
type: 'number',
|
|
36
36
|
},
|
|
37
37
|
x: {
|
|
38
38
|
type: 'string',
|
|
39
|
-
pattern: '^\\d+\\.(pbf|vmt)$'
|
|
39
|
+
pattern: '^\\d+\\.(pbf|vmt)$',
|
|
40
40
|
},
|
|
41
41
|
id: {
|
|
42
|
-
type: 'string'
|
|
43
|
-
}
|
|
42
|
+
type: 'string',
|
|
43
|
+
},
|
|
44
44
|
},
|
|
45
45
|
},
|
|
46
46
|
};
|
|
@@ -70,12 +70,12 @@ export default async function route(app) {
|
|
|
70
70
|
app.get('/layer-rtile/:id/:z/:y/:x', publicParams, rtile);
|
|
71
71
|
app.get('/layer-vtile/:id/:z/:y/:x', publicParams, vtile);
|
|
72
72
|
|
|
73
|
-
if (!app.hasRoute({ method: 'GET', url: '/api/vtile/:layer/:lang/:z/:y/:x'
|
|
74
|
-
console.log(
|
|
73
|
+
if (!app.hasRoute({ method: 'GET', url: '/api/vtile/:layer/:lang/:z/:y/:x' })) {
|
|
74
|
+
console.log('\x1b[34m%s\x1b[0m', 'add vtile from gis');
|
|
75
75
|
app.get('/vtile/:layer/:lang/:z/:y/:x', publicParams, vtile1);
|
|
76
76
|
}
|
|
77
|
-
if (!app.hasRoute({ method: 'GET', url: '/api/gis-layer-list'
|
|
78
|
-
console.log(
|
|
77
|
+
if (!app.hasRoute({ method: 'GET', url: '/api/gis-layer-list' })) {
|
|
78
|
+
console.log('\x1b[34m%s\x1b[0m', 'add gis-layer-list from gis');
|
|
79
79
|
app.get('/gis-layer-list', publicParams, layerList);
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -1,70 +1,74 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import yaml from 'js-yaml';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
getMeta, getTemplate, pgClients, getTemplates, getTemplateSync,
|
|
5
|
+
} from '@opengis/fastify-table/utils.js';
|
|
4
6
|
|
|
5
7
|
const table = 'gis.maps';
|
|
6
8
|
|
|
7
9
|
const columnType = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
text: 'text',
|
|
11
|
+
date: 'date',
|
|
12
|
+
bool: 'yes/no',
|
|
13
|
+
numeric: 'number',
|
|
14
|
+
integer: 'number',
|
|
15
|
+
'timestamp without time zone': 'date',
|
|
16
|
+
'timestamp with time zone': 'date',
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
export default async function getMap({ params = {}, pg = pgClients.client }, reply) {
|
|
18
|
-
|
|
20
|
+
const { columns = [] } = await getMeta({ pg, table }) || {};
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
const fields = columns.map(({ name, dataTypeID, title }) => ({ name, type: columnType[pg.pgType?.[dataTypeID] || 'text'], label: title || name }));
|
|
23
|
+
const mapList = getTemplates('map').map(el => el[0]);
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const rows = pg.pk?.['gis.maps'] ? await pg.query(
|
|
26
|
+
`SELECT map_id as id, * FROM gis.maps where ${params.id ? 'map_id=$1' : '1=1'}`,
|
|
27
|
+
[params.id].filter(Boolean),
|
|
28
|
+
).then(el => el.rows || []) : [];
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
if (params.id && !mapList?.includes(params.id) && !rows[0]) {
|
|
31
|
+
return { status: 404, message: 'map not found' };
|
|
32
|
+
}
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (params.id) {
|
|
39
|
-
const map = rows[0] || {};
|
|
40
|
-
const loadTemplate = await getTemplate('map', params.id) || await getTemplate('map', map.map_key);
|
|
34
|
+
const totals = pg.queryCache ? await pg.queryCache('select json_object_agg(oid::regclass, reltuples) from pg_class')
|
|
35
|
+
.then(el => el.rows?.[0]?.json_object_agg || {}) : {};
|
|
36
|
+
const maps = pg.pk?.['gis.maps'] ? await pg.query(
|
|
37
|
+
'SELECT map_id as slug, name FROM gis.maps',
|
|
38
|
+
).then(el => el.rows || []) : [];
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
if (params.id) {
|
|
41
|
+
const map = rows[0] || {};
|
|
42
|
+
const loadTemplate = await getTemplate('map', params.id) || await getTemplate('map', map.map_key);
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
const layers = await Promise.all(obj.layers.map(async (layer) => {
|
|
46
|
-
const layerData = await getTemplate('layer', layer);
|
|
47
|
-
const serviceData = layerData || await pg.query('select service_id as id, *, st_asgeojson(bbox)::json as bbox, st_asgeojson(center)::json as center from gis.services where service_id=$1', [layer]).then(el => el.rows?.[0]);
|
|
48
|
-
Object.assign(serviceData, { count: totals[serviceData.source_path || ''] || 0 });
|
|
49
|
-
serviceData.style = typeof serviceData.style ==='object'?serviceData.style: yaml.load(serviceData.style);
|
|
50
|
-
return { ...serviceData, id: layer, visible: true };
|
|
51
|
-
}));
|
|
52
|
-
return { maps,...rows[0], ...obj, layers };
|
|
53
|
-
}
|
|
44
|
+
const obj = loadTemplate;
|
|
54
45
|
|
|
55
|
-
|
|
46
|
+
if (Array.isArray(obj?.layers) && typeof obj?.layers?.[0] === 'string') {
|
|
47
|
+
const layers = await Promise.all(obj.layers.map(async (layer) => {
|
|
48
|
+
const layerData = await getTemplate('layer', layer);
|
|
49
|
+
const serviceData = layerData || await pg.query('select service_id as id, *, st_asgeojson(bbox)::json as bbox, st_asgeojson(center)::json as center from gis.services where service_id=$1', [layer]).then(el => el.rows?.[0]);
|
|
50
|
+
Object.assign(serviceData, { count: totals[serviceData.source_path || ''] || 0 });
|
|
51
|
+
serviceData.style = typeof serviceData.style === 'object' ? serviceData.style : yaml.load(serviceData.style);
|
|
52
|
+
return { ...serviceData, id: layer, visible: true };
|
|
53
|
+
}));
|
|
54
|
+
return {
|
|
55
|
+
maps, ...rows[0], ...obj, layers,
|
|
56
|
+
};
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
59
|
+
return reply.status(200).send({ maps, ...rows[0], ...loadTemplate });
|
|
60
|
+
}
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
if (params.id && !rows.length) {
|
|
63
|
+
return reply.status(404).send('map not found');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (params.id) {
|
|
67
|
+
return reply.status(200).send({ ...rows[0], fields });
|
|
68
|
+
}
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
70
|
+
return reply.status(200).send({
|
|
71
|
+
rows,
|
|
72
|
+
fields,
|
|
73
|
+
});
|
|
74
|
+
}
|