@opengis/gis 0.2.5 → 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.
- package/dist/index.css +1 -1
- package/dist/index.js +3290 -2881
- package/dist/index.umd.cjs +34 -34
- package/module/gis/form/gis.ogc_service.form.json +5 -0
- package/module/test/map/main.json +1 -8
- package/package.json +2 -2
- package/server/routes/gis/index.mjs +4 -4
- package/server/routes/gis/ogc/map.info.point.js +98 -94
- package/server/routes/gis/services/get.services.js +1 -1
- package/server/routes/map/controllers/mapFormat.js +4 -6
- package/server/routes/map/vtile1.js +3 -1
|
@@ -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.
|
|
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.
|
|
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 {
|
|
1
|
+
import {
|
|
2
|
+
pgClients, handlebars, getMeta, getTemplate, getFilterSQL,
|
|
3
|
+
} from '@opengis/fastify-table/utils.js';
|
|
2
4
|
|
|
3
5
|
const columnType = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
69
|
-
|
|
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
|
-
|
|
78
|
-
|
|
80
|
+
end`, */
|
|
81
|
+
where: `${el.geomColumn} && '${point.replace(/'/g, "''")}'`,
|
|
82
|
+
}));
|
|
79
83
|
|
|
80
|
-
|
|
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
|
-
|
|
86
|
+
const qCount = qList.map(el => `${el.queryCount} and ${el.where}`).join(' union all ');
|
|
83
87
|
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
if (query.sql === '1') return q;
|
|
89
|
+
if (query.sql === '2') return qCount;
|
|
86
90
|
|
|
87
|
-
|
|
91
|
+
const count = await pg.query(qCount).then(el => el.rowCount);
|
|
88
92
|
|
|
89
|
-
|
|
93
|
+
const row = await pg.query(q).then(el => el.rows?.[0]);
|
|
90
94
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
if (!row) {
|
|
96
|
+
return reply.status(404).send('object not found');
|
|
97
|
+
}
|
|
94
98
|
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
106
|
+
const html = await handlebars.compile(htmlTemplate || 'template not found')(row.data);
|
|
103
107
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
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.
|
|
63
|
-
? await pg.query('select body from admin.templates where name=$1 limit 1', [template ||
|
|
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
|
|
66
|
+
const html1 = htmlTemplate ? await handlebars.compile(htmlTemplate)(fullRow) : null;
|
|
67
67
|
|
|
68
|
-
const html =
|
|
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
|
+
|
|
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));
|
|
48
|
-
|
|
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);
|