@opengis/gis 0.2.4 → 0.2.6

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.
@@ -31,6 +31,11 @@
31
31
  "type": "Text",
32
32
  "ua": "Посилання",
33
33
  "col": 8
34
+ },
35
+ "html": {
36
+ "type": "Textarea",
37
+ "ua": "Шаблон",
38
+ "col": 12
34
39
  }
35
40
  }
36
41
  }
@@ -7,14 +7,7 @@
7
7
  ],
8
8
  "zoom": 11,
9
9
  "widgets": [
10
- {
11
- "type": "info",
12
- "position": "top-left",
13
- "config": {
14
- "title": "Містобудівна документація",
15
- "content": "<p style='font-size: 14px; color: #34495E;'>Затверджені текстові і графічні матеріали, якими регулюється планування, забудова та інше використання територій.</p>"
16
- }
17
- },
10
+
18
11
  {
19
12
  "type": "catalog",
20
13
  "position": "top-left"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/gis",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "author": "Softpro",
6
6
  "main": "./dist/index.js",
@@ -45,7 +45,7 @@
45
45
  "devDependencies": {
46
46
  "@opengis/core": "^0.0.23",
47
47
  "@opengis/fastify-table": "^2.0.32",
48
- "@opengis/filter": "^0.1.7",
48
+ "@opengis/filter": "^0.1.11",
49
49
  "@opengis/form": "^0.0.48",
50
50
  "@opengis/table": "^0.0.27",
51
51
  "@vitejs/plugin-vue": "^5.2.3",
@@ -23,10 +23,10 @@ const mapInfoPointSchema = {
23
23
  x: { type: 'number' },
24
24
  y: { type: 'number' },
25
25
  layers: { type: 'string' },
26
- index: { type: 'number', minimum: 0 }
26
+ index: { type: 'number', minimum: 0 },
27
27
  },
28
- required: ['x', 'y', 'layers']
29
- }
28
+ required: ['x', 'y', 'layers'],
29
+ },
30
30
  };
31
31
 
32
32
  async function route(app) {
@@ -56,4 +56,4 @@ async function route(app) {
56
56
  app.get('/map-info-point', { config: { policy: ['public'] }, schema: mapInfoPointSchema }, mapInfoPoint);
57
57
  }
58
58
 
59
- export default route;
59
+ export default route;
@@ -1,120 +1,124 @@
1
- import { pgClients, handlebars, getMeta, getTemplate, getFilterSQL } from "@opengis/fastify-table/utils.js";
1
+ import {
2
+ pgClients, handlebars, getMeta, getTemplate, getFilterSQL,
3
+ } from '@opengis/fastify-table/utils.js';
2
4
 
3
5
  const columnType = {
4
- text: 'text',
5
- date: 'date',
6
- bool: 'yes/no',
7
- numeric: 'number',
8
- integer: 'number',
9
- 'timestamp without time zone': 'date',
10
- 'timestamp with time zone': 'date',
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',
11
13
  };
12
14
 
13
15
  export default async function mapInfoPoint(req, reply) {
14
- const { pg = pgClients.client, query = {} } = req;
15
- const { x, y, layers, index = 0 } = query;
16
- const time = Date.now();
17
-
18
- if (!x || !y || !layers) {
19
- return reply.status(400).send('not enough query params: x, y, layers are required');
20
- }
21
-
22
- const rows = pg?.pk?.['gis.ogc_service'] ? await pg.query(`select * from gis.ogc_service WHERE enabled and table_name is not null and ogc_service_id = any($1)`, [layers.split(',')]).then(el => el.rows || []) : [];
23
-
24
- if (!rows.length) {
25
- return reply.status(404).send('layers not found');
26
- }
27
-
28
- const point = `srid=4326;point(${x} ${y})`; // 30, 50
29
-
30
- const srids = pg.queryCache ? await pg.queryCache('select json_agg(srid) as srids from spatial_ref_sys').then(el => el.rows?.[0]?.srids || {}) : {};
31
-
32
- await Promise.all(rows.map(async (layer, idx) => {
33
- const { table_name: source, ogc_service_id: layerId } = layer;
34
- const loadTable = await getTemplate('table', source);
35
- const meta = await getMeta({ pg, table: loadTable?.table || source });
36
- const { geom = 'geom' } = meta || {};
37
- const { table = source, columns = meta?.columns } = loadTable || {};
38
- const { srid, x } = await pg.query(`select st_srid(${geom}) as srid, st_x(st_pointonsurface(${geom})) as x from ${table} where geom is not null limit 1`).then(el => el.rows?.[0] || {});
39
-
40
- const cls = columns
41
- ?.filter(el => el.name && el.data)
42
- ?.reduce?.((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
43
-
44
- const pk = pg.pk?.[table] || loadTable?.key;
45
-
46
- const { optimizedSQL } = await getFilterSQL({ pg, table: source, query: layer?.query });
47
-
48
- Object.assign(layer, {
49
- layer: (layerId || idx.toString())?.replace?.(/'/g, "''"),
50
- table,
51
- pk,
52
- cls,
53
- geomColumn: srid === 4326 ? geom : `st_transform(${geom},4326)`,
54
- optimizedSQL,
55
- srid,
56
- step: srids?.includes?.(srid - 0) && srid !== 4326 && x > 100 ? 10 : 0.0002,
57
- });
58
- }));
59
-
60
- const unique = rows.filter((el, idx, arr) => el.table && arr.map((item) => item.table).indexOf(el.table) === idx);
61
-
62
- const qList = unique.map((el) => ({
63
- query: `select ${el.pk}::text as pk, '${el.layer}' as layer, '${el.table}' as table,
16
+ const { pg = pgClients.client, query = {} } = req;
17
+ const {
18
+ x, y, layers, index = 0,
19
+ } = query;
20
+ const time = Date.now();
21
+
22
+ if (!x || !y || !layers) {
23
+ return reply.status(400).send('not enough query params: x, y, layers are required');
24
+ }
25
+
26
+ const rows = pg?.pk?.['gis.ogc_service'] ? await pg.query('select * from gis.ogc_service WHERE enabled and table_name is not null and ogc_service_id = any($1)', [layers.split(',')]).then(el => el.rows || []) : [];
27
+
28
+ if (!rows.length) {
29
+ return reply.status(404).send('layers not found');
30
+ }
31
+
32
+ const point = `srid=4326;point(${x} ${y})`; // 30, 50
33
+
34
+ const srids = pg.queryCache ? await pg.queryCache('select json_agg(srid) as srids from spatial_ref_sys').then(el => el.rows?.[0]?.srids || {}) : {};
35
+
36
+ await Promise.all(rows.map(async (layer, idx) => {
37
+ const { table_name: source, ogc_service_id: layerId } = layer;
38
+ const loadTable = await getTemplate('table', source);
39
+ const meta = await getMeta({ pg, table: loadTable?.table || source });
40
+ const { geom = 'geom' } = meta || {};
41
+ const { table = source, columns = meta?.columns } = loadTable || {};
42
+ const { srid, x } = await pg.query(`select st_srid(${geom}) as srid, st_x(st_pointonsurface(${geom})) as x from ${table} where geom is not null limit 1`).then(el => el.rows?.[0] || {});
43
+
44
+ const cls = columns
45
+ ?.filter(el => el.name && el.data)
46
+ ?.reduce?.((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
47
+
48
+ const pk = pg.pk?.[table] || loadTable?.key;
49
+
50
+ const { optimizedSQL } = await getFilterSQL({ pg, table: source, query: layer?.query });
51
+
52
+ Object.assign(layer, {
53
+ layer: (layerId || idx.toString())?.replace?.(/'/g, "''"),
54
+ table,
55
+ pk,
56
+ cls,
57
+ geomColumn: srid === 4326 ? geom : `st_transform(${geom},4326)`,
58
+ optimizedSQL,
59
+ srid,
60
+ step: srids?.includes?.(srid - 0) && srid !== 4326 && x > 100 ? 10 : 0.0002,
61
+ });
62
+ }));
63
+
64
+ const unique = rows.filter((el, idx, arr) => el.table && arr.map((item) => item.table).indexOf(el.table) === idx);
65
+
66
+ const qList = unique.map((el) => ({
67
+ query: `select ${el.pk}::text as pk, '${el.layer}' as layer, '${el.table}' as table,
64
68
  row_to_json(t) as data,
65
69
  st_distance(${el.geomColumn},'${point.replace(/'/g, "''")}') as distance,
66
70
  st_asgeojson(${el.geomColumn})::json as geom from (${el.optimizedSQL}) t
67
71
  where 1=1`,
68
- queryCount: `select 1 from (${el.optimizedSQL})t where 1=1`,
69
- /*where: `case
72
+ queryCount: `select 1 from (${el.optimizedSQL})t where 1=1`,
73
+ /* where: `case
70
74
  when ST_GeometryType(${el.geomColumn}) in ('ST_Polygon','ST_MultiPolygon')
71
75
  then st_intersects(${el.geomColumn},st_buffer('${point.replace(/'/g, "''")}',${el.step}))
72
-
76
+
73
77
  when ST_GeometryType(${el.geomColumn}) in ('ST_Line','ST_MultiLineString', 'ST_MultiPoint', 'ST_Point')
74
78
  then st_distance(${el.geomColumn},'${point.replace(/'/g, "''")}') < ${el.step}
75
79
  else false
76
- end`,*/
77
- where: `${el.geomColumn} && '${point.replace(/'/g, "''")}'`
78
- }));
80
+ end`, */
81
+ where: `${el.geomColumn} && '${point.replace(/'/g, "''")}'`,
82
+ }));
79
83
 
80
- const q = qList.map(el => el.query + ' and ' + el.where).join(' union all ').concat(` order by distance limit 1 offset ${Math.max(+index || 0, 0)}`);
84
+ const q = qList.map(el => `${el.query} and ${el.where}`).join(' union all ').concat(` order by distance limit 1 offset ${Math.max(+index || 0, 0)}`);
81
85
 
82
- const qCount = qList.map(el => el.queryCount + ' and ' + el.where).join(' union all ');
86
+ const qCount = qList.map(el => `${el.queryCount} and ${el.where}`).join(' union all ');
83
87
 
84
- if (query.sql === '1') return q;
85
- if (query.sql === '2') return qCount;
88
+ if (query.sql === '1') return q;
89
+ if (query.sql === '2') return qCount;
86
90
 
87
- const count = await pg.query(qCount).then(el => el.rowCount);
91
+ const count = await pg.query(qCount).then(el => el.rowCount);
88
92
 
89
- const row = await pg.query(q).then(el => el.rows?.[0]);
93
+ const row = await pg.query(q).then(el => el.rows?.[0]);
90
94
 
91
- if (!row) {
92
- return reply.status(404).send('object not found');
93
- }
95
+ if (!row) {
96
+ return reply.status(404).send('object not found');
97
+ }
94
98
 
95
- const { columns = [] } = await getMeta({ pg, table: row.table }) || {};
96
- const fields = columns.map(({ name, dataTypeID, title }) => ({ name, type: columnType[pg.pgType?.[dataTypeID] || 'text'], label: title || name }));
99
+ const { columns = [] } = await getMeta({ pg, table: row.table }) || {};
100
+ const fields = columns.map(({ name, dataTypeID, title }) => ({ name, type: columnType[pg.pgType?.[dataTypeID] || 'text'], label: title || name }));
97
101
 
98
- const htmlTemplate = pg?.pk?.['admin.template'] && row.layer && false
99
- ? await pg.query('select body from admin.templates where name=$1 limit 1', [row.layer]).then(el => el.rows?.[0]?.body)
100
- : rows.find(el => el.ogc_service_id === row.layer)?.html;
102
+ const htmlTemplate = pg?.pk?.['admin.templates'] && row.layer && false
103
+ ? await pg.query('select body from admin.templates where name=$1 limit 1', [row.layer]).then(el => el.rows?.[0]?.body)
104
+ : rows.find(el => el.ogc_service_id === row.layer)?.html;
101
105
 
102
- const html = await handlebars.compile(htmlTemplate || 'template not found')(row.data);
106
+ const html = await handlebars.compile(htmlTemplate || 'template not found')(row.data);
103
107
 
104
- const res = {
105
- time: Date.now() - time,
106
- index,
107
- count,
108
- data: {
109
- layer: row.layer,
110
- geom: row.geom,
111
- id: row.pk,
112
- distance: row.distance,
113
- data: row.data,
114
- },
115
- fields,
116
- html
117
- };
108
+ const res = {
109
+ time: Date.now() - time,
110
+ index,
111
+ count,
112
+ data: {
113
+ layer: row.layer,
114
+ geom: row.geom,
115
+ id: row.pk,
116
+ distance: row.distance,
117
+ data: row.data,
118
+ },
119
+ fields,
120
+ html,
121
+ };
118
122
 
119
- return res;
123
+ return res;
120
124
  }
@@ -18,7 +18,7 @@ export default async function getServices({ params = {}, pg = pgClients.client }
18
18
  if (!pg.tlist.includes('gis.services')) return { status: 404, message: 'not found' };
19
19
  const rows = await pg.query(`
20
20
  SELECT
21
- service_id, service_key, name, description, keywords, category, holder, group_id, b.group_name, service_type,
21
+ service_id, service_key, name, description, keywords, category, holder, group_id, b.group_name, service_type, card_mode,
22
22
  source_type, service_url, source_path, query, geom_type, geometry_column, sql_list, attributes, filters,
23
23
  popup, style, legend, card, srid, bbox::box2d as extent, st_asgeojson(bbox)::json as bbox, st_asgeojson(center)::json as center, is_active as enabled, is_public, is_active, is_downloadable, metadata,
24
24
  metadata_url, thumbnail_url, created_by, updated_by, updated_at, created_at, template
@@ -59,15 +59,13 @@ export default async function mapFormat(req, reply) {
59
59
  </div>`);
60
60
  }
61
61
 
62
- const htmlTemplate = pg?.pk?.['admin.template']
63
- ? await pg.query('select body from admin.templates where name=$1 limit 1', [template || id]).then(el => el.rows?.[0]?.body)
62
+ const htmlTemplate = pg?.pk?.['admin.templates'] && service.card_mode === 'html'
63
+ ? await pg.query('select body from admin.templates where name=$1 limit 1', [template || layer]).then(el => el.rows?.[0]?.body)
64
64
  : null;
65
65
 
66
- const html1 = await handlebars.compile(htmlTemplate || 'template not found')(fullRow);
66
+ const html1 = htmlTemplate ? await handlebars.compile(htmlTemplate)(fullRow) : null;
67
67
 
68
- const html = template
69
- ? html1
70
- : `<dl class="divide-y divide-gray-100 py-[5px]">${result.join('')}</dl>`;
68
+ const html = html1 || `<dl class="divide-y divide-gray-100 py-[5px]">${result.join('')}</dl>`;
71
69
 
72
70
  const res = {
73
71
  time: Date.now() - time,
@@ -44,8 +44,10 @@ export default async function vtile({
44
44
  const { pk: pkey, columns } = metaTable;
45
45
 
46
46
  // props
47
- const props = !query.all ? data.popup || [] : columns.filter(el => !['json', 'geometry'].includes(pg.pgType[el.dataTypeID]) && !['uid', 'cdate', 'editor_id', 'editor_date'].includes(el.name));
48
- const cache = layer + (query.all ? '-all' : '');
47
+
48
+ const props = !query.all ? (data.popup || []).concat(data.card || []) : columns.filter(el => !['json', 'geometry'].includes(pg.pgType[el.dataTypeID]) && !['uid', 'cdate', 'editor_id', 'editor_date'].includes(el.name));
49
+
50
+ const cache = layer + (query.all ? '-all' : '') + JSON.stringify(data.popup || []).length;
49
51
  const propsWithCls = propsCache[cache] ?? await Promise.all(props.map(async (col, idx) => {
50
52
  const key = col.name;
51
53
  const select = data.popup?.find(el => el.name === key);