@opengis/gis 0.1.82 → 0.2.1

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.
Files changed (50) hide show
  1. package/dist/index.css +1 -1
  2. package/dist/index.js +6794 -6952
  3. package/dist/index.umd.cjs +50 -56
  4. package/module/cls.json +2 -1
  5. package/module/gis/form/gis.maps.form.json +2 -2
  6. package/module/gis/form/gis.registers.form.json +8 -199
  7. package/module/gis/form/gis.services.form.json +11 -200
  8. package/module/gis/table/gis.group_list.table.json +36 -0
  9. package/module/gis/table/gis.maps.table.json +5 -7
  10. package/module/gis/table/gis.ogc_service.table.json +14 -3
  11. package/module/gis/table/gis.registers.table.json +2 -3
  12. package/module/gis/table/gis.services.table.json +19 -6
  13. package/module/test/cls/doc_status.json +31 -31
  14. package/module/test/cls/ts.temp_status.json +18 -0
  15. package/module/test/cls/ts.temp_structure.ts_class.json +50 -0
  16. package/module/test/cls/ts.temp_type.json +10 -0
  17. package/module/test/layer/bp.json +60 -0
  18. package/module/test/map/address4.json +2 -42
  19. package/module/test/map/bp_myo.json +41 -0
  20. package/module/test/map/main.json +44 -0
  21. package/module/test/map/mbd.json +24 -176
  22. package/module/test/map/ts.json +20 -129
  23. package/module/test/select/address_id.json +3 -0
  24. package/module/test/select/address_id.sql +8 -0
  25. package/module/test/select/core.user_uid.sql +1 -1
  26. package/module/test/table/data_bp_myo.bp.table.json +123 -0
  27. package/package.json +61 -61
  28. package/server/migrations/ogc.sql +107 -0
  29. package/server/migrations/widgets.sql +21 -0
  30. package/server/routes/gis/index.mjs +18 -2
  31. package/server/routes/gis/ogc/map.info.point.js +120 -0
  32. package/server/routes/gis/registers/funcs/classifiers.js +6 -3
  33. package/server/routes/gis/registers/funcs/handleRegistryRequest.js +15 -22
  34. package/server/routes/gis/registers/gis.registry.js +3 -2
  35. package/server/routes/gis/services/add.service.js +5 -5
  36. package/server/routes/gis/services/get.services.col.js +19 -11
  37. package/server/routes/gis/services/get.services.js +29 -14
  38. package/server/routes/gis/services/legend.auto.js +78 -0
  39. package/server/routes/map/controllers/layerList.js +14 -2
  40. package/server/routes/map/controllers/mapFeatures.js +11 -2
  41. package/server/routes/map/controllers/mapFormat.js +14 -18
  42. package/server/routes/map/controllers/vtile.js +1 -1
  43. package/server/routes/map/index.mjs +36 -17
  44. package/server/routes/map/maps/add.map.js +42 -0
  45. package/server/routes/map/maps/del.map.js +19 -0
  46. package/server/routes/map/maps/get.map.js +67 -0
  47. package/server/routes/map/vtile1.js +42 -6
  48. package/server/routes/map/widgets/add.widget.js +39 -0
  49. package/server/routes/map/widgets/del.widget.js +23 -0
  50. package/server/routes/map/widgets/get.widget.js +41 -0
@@ -13,10 +13,18 @@ import mapFormat from './controllers/mapFormat.js';
13
13
  import maps from './controllers/maps.js';
14
14
  import markerIconApi from './controllers/marker_icon.js';
15
15
 
16
+ import getMap from './maps/get.map.js';
17
+ import addMap from './maps/add.map.js';
18
+ import delMap from './maps/del.map.js';
19
+
20
+ import getWidget from './widgets/get.widget.js';
21
+ import addWidget from './widgets/add.widget.js';
22
+ import delWidget from './widgets/del.widget.js';
23
+
16
24
  const schemaInfo = {
17
25
  type: 'object',
18
26
  properties: {
19
- params: {
27
+ publicParams: {
20
28
  slug: {
21
29
  type: 'string',
22
30
  },
@@ -37,31 +45,42 @@ const schemaInfo = {
37
45
  },
38
46
  };
39
47
 
40
- const policy = ['public'];
48
+ const publicParams = { config: { policy: 'L0' }, schema: schemaInfo }; // * L0 === public
49
+ const privilegedParams = { config: { policy: 'L1', role: 'admin' }, schema: schemaInfo }; // ? just auth or admin
41
50
 
42
51
  export default async function route(app) {
43
- app.get('/maps', { config: { policy }, schema: schemaInfo }, maps);
44
- app.get('/map/:slug', { config: { policy }, schema: schemaInfo }, map);
45
- app.get('/map-tiles/:slug/:z/:y/:x', { config: { policy }, schema: schemaInfo }, mapTiles);
46
- app.get('/map-features/:slug/:id', { config: { policy }, schema: schemaInfo }, mapFeatures);
47
- app.get('/map-features-point/:slug', { config: { policy }, schema: schemaInfo }, mapFeatures);
52
+ app.get('/gis-map/:id?', publicParams, getMap);
53
+ app.post('/gis-map/:id?', privilegedParams, addMap);
54
+ app.put('/gis-map/:id', privilegedParams, addMap);
55
+ app.delete('/gis-map/:id', privilegedParams, delMap);
56
+
57
+ app.get('/gis-widget/:map/:id?', publicParams, getWidget);
58
+ app.post('/gis-widget/:map/:id?', privilegedParams, addWidget);
59
+ app.put('/gis-widget/:map/:id', privilegedParams, addWidget);
60
+ app.delete('/gis-widget/:map/:id', privilegedParams, delWidget);
61
+
62
+ app.get('/maps', publicParams, maps);
63
+ app.get('/map/:slug', publicParams, map);
64
+ app.get('/map-tiles/:slug/:z/:y/:x', publicParams, mapTiles);
65
+ app.get('/map-features/:slug/:id', publicParams, mapFeatures);
66
+ app.get('/map-features-point/:slug', publicParams, mapFeatures);
48
67
 
49
- app.get('/map-catalog', { config: { policy }, schema: schemaInfo }, mapCatalog);
50
- app.get('/map-catalog/:service/:attr', { config: { policy }, schema: schemaInfo }, mapCatalogAttribute);
51
- app.get('/layer-rtile/:id/:z/:y/:x', { config: { policy }, schema: {} }, rtile);
52
- app.get('/layer-vtile/:id/:z/:y/:x', { config: { policy }, schema: schemaInfo }, vtile);
68
+ app.get('/map-catalog', publicParams, mapCatalog);
69
+ app.get('/map-catalog/:service/:attr', publicParams, mapCatalogAttribute);
70
+ app.get('/layer-rtile/:id/:z/:y/:x', publicParams, rtile);
71
+ app.get('/layer-vtile/:id/:z/:y/:x', publicParams, vtile);
53
72
 
54
73
  if (!app.hasRoute({ method: 'GET', url: '/api/vtile/:layer/:lang/:z/:y/:x', })) {
55
74
  console.log("\x1b[34m%s\x1b[0m", 'add vtile from gis');
56
- app.get('/vtile/:layer/:lang/:z/:y/:x', { config: { policy }, schema: schemaInfo }, vtile1);
75
+ app.get('/vtile/:layer/:lang/:z/:y/:x', publicParams, vtile1);
57
76
  }
58
77
  if (!app.hasRoute({ method: 'GET', url: '/api/gis-layer-list', })) {
59
78
  console.log("\x1b[34m%s\x1b[0m", 'add gis-layer-list from gis');
60
- app.get('/gis-layer-list', { config: { policy }, }, layerList);
79
+ app.get('/gis-layer-list', publicParams, layerList);
61
80
  }
62
81
 
63
- app.get('/gis-icon/*', { config: { policy }, schema: {} }, markerIconApi);
64
- app.get('/icon/*', { config: { policy }, schema: {} }, markerIconApi);
65
- app.get('/marker-icon/*', { config: { policy }, schema: {} }, markerIconApi);
66
- app.get('/map-format', { config: { policy }, schema: {} }, mapFormat);
82
+ app.get('/gis-icon/*', publicParams, markerIconApi);
83
+ app.get('/icon/*', publicParams, markerIconApi);
84
+ app.get('/marker-icon/*', publicParams, markerIconApi);
85
+ app.get('/map-format', publicParams, mapFormat);
67
86
  }
@@ -0,0 +1,42 @@
1
+ import { dataInsert, dataUpdate, pgClients } from "@opengis/fastify-table/utils.js";
2
+ export default async function addMap({
3
+ method, params = {}, body, pg = pgClients.client, user = {},
4
+ }, reply) {
5
+ const { uid } = user;
6
+
7
+ if (!uid) {
8
+ return reply.status(401).send('unauthorized');
9
+ }
10
+
11
+ if (method === 'POST') {
12
+ if (!body?.name) {
13
+ return reply.status(400).send('not enough body params: name');
14
+ }
15
+
16
+ if (!body?.map_key) {
17
+ return reply.status(400).send('not enough body params: map_key');
18
+ }
19
+
20
+ const { rows = [] } = await dataInsert({
21
+ pg,
22
+ id: params.id,
23
+ table: 'gis.maps',
24
+ data: body,
25
+ uid,
26
+ });
27
+ return reply.status(200).send(rows[0]);
28
+ }
29
+
30
+ if (!params.id) {
31
+ return reply.status(400).send('not enough params: id');
32
+ }
33
+
34
+ const row = await dataUpdate({
35
+ pg,
36
+ id: params.id,
37
+ table: 'gis.maps',
38
+ data: body,
39
+ uid,
40
+ });
41
+ return reply.status(200).send(row);
42
+ }
@@ -0,0 +1,19 @@
1
+ import { dataDelete, pgClients } from "@opengis/fastify-table/utils.js";
2
+
3
+ export default async function delMap({
4
+ params = {}, pg = pgClients.client, user = {},
5
+ }, reply) {
6
+ const { uid } = user;
7
+
8
+ if (!uid) {
9
+ return reply.status(401).send('unauthorized');
10
+ }
11
+
12
+ const row = await dataDelete({
13
+ pg,
14
+ id: params.id,
15
+ table: 'gis.maps',
16
+ uid,
17
+ });
18
+ return reply.status(200).send(row);
19
+ }
@@ -0,0 +1,67 @@
1
+ import path from 'node:path';
2
+ import yaml from 'js-yaml';
3
+ import { getMeta, getTemplate, pgClients, getTemplates, getTemplateSync } from "@opengis/fastify-table/utils.js";
4
+
5
+ const table = 'gis.maps';
6
+
7
+ const columnType = {
8
+ text: 'text',
9
+ date: 'date',
10
+ bool: 'yes/no',
11
+ numeric: 'number',
12
+ integer: 'number',
13
+ 'timestamp without time zone': 'date',
14
+ 'timestamp with time zone': 'date',
15
+ };
16
+
17
+ export default async function getMap({ params = {}, pg = pgClients.client }, reply) {
18
+ const { columns = [] } = await getMeta({ pg, table }) || {};
19
+
20
+ const fields = columns.map(({ name, dataTypeID, title }) => ({ name, type: columnType[pg.pgType?.[dataTypeID] || 'text'], label: title || name }));
21
+ const mapList = getTemplates('map').map(el => el[0]);
22
+
23
+ const rows = pg.pk?.['gis.maps'] ? await pg.query(
24
+ `SELECT map_id as id, * FROM gis.maps where ${params.id ? 'map_id=$1' : '1=1'}`,
25
+ [params.id].filter(Boolean),
26
+ ).then(el => el.rows || []) : [];
27
+
28
+ if (params.id && !mapList.includes(params.id) && !rows[0]) {
29
+ return { status: 404, message: 'map not found' }
30
+ }
31
+
32
+ const totals = pg.queryCache ? await pg.queryCache(`select json_object_agg(oid::regclass, reltuples) from pg_class`)
33
+ .then(el => el.rows?.[0]?.json_object_agg || {}) : {};
34
+
35
+ if (params.id) {
36
+ const map = rows[0] || {};
37
+ const loadTemplate = await getTemplate('map', params.id) || await getTemplate('map', map.map_key);
38
+
39
+ const obj = loadTemplate;
40
+
41
+ if (Array.isArray(obj?.layers) && typeof obj?.layers?.[0] === 'string') {
42
+ const layers = await Promise.all(obj.layers.map(async (layer) => {
43
+ const layerData = await getTemplate('layer', layer);
44
+ 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]);
45
+ Object.assign(serviceData, { count: totals[serviceData.source_path || ''] || 0 });
46
+ serviceData.style = yaml.load(serviceData.style);
47
+ return { ...serviceData, id: layer, visible: true };
48
+ }));
49
+ return { ...rows[0], ...obj, layers };
50
+ }
51
+
52
+ return reply.status(200).send({ ...rows[0], ...loadTemplate });
53
+ }
54
+
55
+ if (params.id && !rows.length) {
56
+ return reply.status(404).send('map not found');
57
+ }
58
+
59
+ if (params.id) {
60
+ return reply.status(200).send({ ...rows[0], fields });
61
+ }
62
+
63
+ return reply.status(200).send({
64
+ rows,
65
+ fields,
66
+ });
67
+ }
@@ -4,9 +4,11 @@ const headers = {
4
4
  };
5
5
  import Sphericalmercator from '@mapbox/sphericalmercator';
6
6
  const mercator = new Sphericalmercator({ size: 256 });
7
- import { getTemplate, getMeta, getFilterSQL } from '@opengis/fastify-table/utils.js';
7
+ import { getColumnCLS, getTemplate, getMeta, getFilterSQL } from '@opengis/fastify-table/utils.js';
8
8
  import yaml from 'js-yaml';
9
9
 
10
+ const propsCache = {};
11
+
10
12
  export default async function vtile({ params = {}, query, pg, user }, reply) {
11
13
  const { y, z } = params;
12
14
  const x = params.x.split('.')[0] - 0;
@@ -22,10 +24,18 @@ export default async function vtile({ params = {}, query, pg, user }, reply) {
22
24
  const mapData = map ? await getTemplate('map', map) : {};
23
25
  const mapStyle = mapData?.widgets?.find?.(el => el.type === 'attribute')?.config?.layer?.style;
24
26
 
25
- const geom = data1?.geometry_column || 'geom';
26
- const table = data?.table_name || data1?.source_path;
27
- const style = mapStyle || data?.style || yaml.load(data1?.style);
28
- const filterList = data?.filter_list || data1?.filters;
27
+ const geom = data?.geometry_column
28
+ || data1?.geometry_column
29
+ || 'geom';
30
+ const table = data?.source_path
31
+ || data?.table_name
32
+ || data1?.source_path;
33
+ const style = mapStyle
34
+ || data?.style
35
+ || (data1?.style ? yaml.load(data1?.style) : null);
36
+ const filterList = data?.filters
37
+ || data?.filter_list
38
+ || data1?.filters;
29
39
  const layerQuery = data?.query || data1?.query;
30
40
 
31
41
  // bbox
@@ -47,6 +57,32 @@ export default async function vtile({ params = {}, query, pg, user }, reply) {
47
57
  return el.type?.[0] === '_' ? `${el.name}[1] as ${el.name}` : `${el.name}${['int4'].includes(el.type) ? '::text' : ''}`;
48
58
  });
49
59
 
60
+ const obj = (data1.attributes || []).concat(data1.card || []).concat(data1.popup || []).filter(el => el.data).reduce((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
61
+
62
+ const propsWithCls = propsCache[layer] ?? await Promise.all(props.map(async (key, idx) => {
63
+ const { name, type, sql } = getColumnCLS(table, key) || {};
64
+ if (name && type === 'cls') {
65
+ return `(select name from admin.cls where parent='${name}' and code::text="${key}"::text limit 1) as "${key}_text","${key}"::text`;
66
+ }
67
+ if (type === 'select' && sql) {
68
+ const { fields = [] } = await pg.query(sql + ' limit 0');
69
+ return `(select "${fields[1].name}" from (${sql})s${idx} where "${fields[0].name}"="${key}" limit 1) as "${key}_text","${key}"::text`
70
+ }
71
+
72
+ if (obj[key]) {
73
+ const clsdata = await pg.query('select name, type, data as sql from admin.cls where name=$1', [obj[key]]).then(el => el.rows?.[0] || {});
74
+ if (clsdata.name && clsdata.type === 'json') {
75
+ return `(select name from admin.cls where parent='${clsdata.name}' and code::text="${key}"::text limit 1) as "${key}_text","${key}"::text`;
76
+ }
77
+ if (clsdata.type === 'sql' && clsdata.sql) {
78
+ const { fields = [] } = await pg.query(clsdata.sql + ' limit 0');
79
+ return `(select "${fields[1].name}" from (${clsdata.sql})s${idx} where "${fields[0].name}"="${key}" limit 1) as "${key}_text","${key}"::text`
80
+ }
81
+ }
82
+ return `"${key}"::text`;
83
+ }));
84
+ if (!propsCache[layer]) { propsCache[layer] = propsWithCls; }
85
+
50
86
  const geomCol = (style?.type === 'point' ? `ST_Centroid(${geom})` : null)
51
87
  || (parseInt(z, 10) < parseInt(query.pointZoom || style?.pointZoom || style?.iconZoom || '0', 10) ? `ST_Centroid(${geom})` : geom);
52
88
 
@@ -82,7 +118,7 @@ export default async function vtile({ params = {}, query, pg, user }, reply) {
82
118
 
83
119
  floor(random() * 100000 + 1)::int + row_number() over() as row,
84
120
 
85
- ${props?.length ? `${props.map(el => `"${el}"::text`).join(',')},` : ''}
121
+ ${props?.length ? `${propsWithCls.join(',')},` : ''}
86
122
 
87
123
  ${pkey} as id,
88
124
  ST_AsMVTGeom(st_transform(${geomCol},3857),ST_TileEnvelope(${z},${y},${x})::box2d,4096,256,false) geom
@@ -0,0 +1,39 @@
1
+ import { dataInsert, dataUpdate, pgClients } from "@opengis/fastify-table/utils.js";
2
+ export default async function addWidget({
3
+ method, params = {}, body, pg = pgClients.client, user = {},
4
+ }, reply) {
5
+ const { uid } = user;
6
+
7
+ if (!uid) {
8
+ return reply.status(401).send('unauthorized');
9
+ }
10
+
11
+ if (!params.map) {
12
+ return reply.status(400).send('not enough params: map id');
13
+ }
14
+
15
+ if (method === 'PUT' && !params.id) {
16
+ return reply.status(400).send('not enough params: id');
17
+ }
18
+
19
+ if (method === 'POST') {
20
+ Object.assign(body, { map_id: params.map });
21
+ const { rows = [] } = await dataInsert({
22
+ pg,
23
+ id: params.id,
24
+ table: 'gis.widgets',
25
+ data: body,
26
+ uid,
27
+ });
28
+ return reply.status(200).send(rows[0]);
29
+ }
30
+
31
+ const row = await dataUpdate({
32
+ pg,
33
+ id: params.id,
34
+ table: 'gis.widgets',
35
+ data: body,
36
+ uid,
37
+ });
38
+ return reply.status(200).send(row);
39
+ }
@@ -0,0 +1,23 @@
1
+ import { dataDelete, pgClients } from "@opengis/fastify-table/utils.js";
2
+
3
+ export default async function delWidget({
4
+ params = {}, pg = pgClients.client, user = {},
5
+ }, reply) {
6
+ const { uid } = user;
7
+
8
+ if (!uid) {
9
+ return reply.status(401).send('unauthorized');
10
+ }
11
+
12
+ if (!params.map) {
13
+ return reply.status(400).send('not enough params: map id');
14
+ }
15
+
16
+ const row = await dataDelete({
17
+ pg,
18
+ id: params.id,
19
+ table: 'gis.widgets',
20
+ uid,
21
+ });
22
+ return reply.status(200).send(row);
23
+ }
@@ -0,0 +1,41 @@
1
+ import { getMeta, pgClients } from "@opengis/fastify-table/utils.js";
2
+
3
+ const table = 'gis.widgets';
4
+
5
+ const columnType = {
6
+ text: 'text',
7
+ date: 'date',
8
+ bool: 'yes/no',
9
+ numeric: 'number',
10
+ integer: 'number',
11
+ 'timestamp without time zone': 'date',
12
+ 'timestamp with time zone': 'date',
13
+ };
14
+
15
+ export default async function getWidget({ params = {}, pg = pgClients.client }, reply) {
16
+ if (!params.map) {
17
+ return reply.status(400).send('not enough params: map id');
18
+ }
19
+
20
+ const { columns = [] } = await getMeta({ pg, table }) || {};
21
+
22
+ const fields = columns.map(({ name, dataTypeID, title }) => ({ name, type: columnType[pg.pgType?.[dataTypeID] || 'text'], label: title || name }));
23
+
24
+ const rows = pg.pk?.['gis.maps'] && pg.pk?.['gis.widgets'] ? await pg.query(
25
+ `SELECT widget_id as id, * FROM gis.widgets where map_id=$1 and ${params.id ? 'widget_id=$2' : '1=1'}`,
26
+ [params.map, params.id].filter(Boolean),
27
+ ).then(el => el.rows || []) : [];
28
+
29
+ if (params.id && !rows.length) {
30
+ return reply.status(404).send('widget not found');
31
+ }
32
+
33
+ if (params.id) {
34
+ return reply.status(200).send({ ...rows[0], fields });
35
+ }
36
+
37
+ return reply.status(200).send({
38
+ rows,
39
+ fields,
40
+ });
41
+ }