@opengis/gis 0.2.194 → 0.2.195
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/package.json
CHANGED
|
@@ -5,13 +5,13 @@ import {
|
|
|
5
5
|
} from '@opengis/fastify-table/utils.js';
|
|
6
6
|
|
|
7
7
|
import getPermissions from '../../permissions/functions/get.permissions.js';
|
|
8
|
+
import gisSuggest from '../../registers/functions/gis.suggest.js';
|
|
8
9
|
|
|
9
10
|
const rclient = getRedis();
|
|
10
11
|
|
|
11
12
|
export default async function layerList({
|
|
12
13
|
sql, uid,
|
|
13
14
|
}, pg = pgClients.client) {
|
|
14
|
-
|
|
15
15
|
const layers = getTemplates('layer');
|
|
16
16
|
const files = Promise.all(layers.map(async (el) => {
|
|
17
17
|
const layer = await getTemplate('layer', el[0]);
|
|
@@ -40,40 +40,40 @@ export default async function layerList({
|
|
|
40
40
|
: (uid && !all_layers) ? '(s.is_public or s.cartocss_id = any($1))'
|
|
41
41
|
: 'is_public';
|
|
42
42
|
const q = `
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
43
|
+
select * from
|
|
44
|
+
(
|
|
45
|
+
select service_id as id, name, category, style, bbox::box2d as extent, st_asgeojson(bbox)::json as geom, coalesce('/api/vtile/'||service_id||'/ua/{z}/{x}/{y}.vmt',null) as url, coalesce(service_type, 'vtile') as service, group_id,
|
|
46
|
+
popup, card, filters, source_path, legend
|
|
47
|
+
from gis.services s where is_active and
|
|
48
|
+
${whereServices}
|
|
49
|
+
union all
|
|
50
|
+
select ogc_service_id as id, name, category, null as style, geom::box2d as extent, st_asgeojson(geom)::json as geom, url, 'ogc' as service, group_id,
|
|
51
|
+
null as popup, null as card, null as filters, table_name as source_path, null as legend
|
|
52
|
+
from gis.ogc_service s where enabled and
|
|
53
|
+
${whereOgcServices}
|
|
54
|
+
union all
|
|
55
|
+
select raster_id as id, name, null as category, null as style, geom::box2d as extent, st_asgeojson(geom)::json as geom,
|
|
56
|
+
coalesce('/api/gis-rtile/'||rtrim(
|
|
57
|
+
replace(
|
|
58
|
+
replace(
|
|
59
|
+
encode(source_path::bytea, 'base64'),
|
|
60
|
+
'+', '-'
|
|
61
|
+
),
|
|
62
|
+
'/', '_'
|
|
63
|
+
),
|
|
64
|
+
'='
|
|
65
|
+
)||'/{z}/{x}/{y}.png',null) as url, 'raster' as service, group_id,
|
|
66
|
+
null as popup, null as card, null as filters, source_path, null as legend
|
|
67
|
+
from gis.rasters s where is_active and
|
|
68
|
+
${whereRasters}
|
|
69
|
+
union all
|
|
70
|
+
select cartocss_id as id, name, null as category, style, geom::box2d as bbox, st_asgeojson(geom)::json as geom,
|
|
71
|
+
coalesce('/api/gis-rtile/'||cartocss_id||'/{z}/{x}/{y}.png',null) as url, 'cartocss' as service, group_id,
|
|
72
|
+
null as popup, null as card, null as filters, null as source_path, null as legend
|
|
73
|
+
from gis.cartocss s where enabled and
|
|
74
|
+
${whereCartocss}
|
|
75
|
+
)q order by q.name
|
|
76
|
+
`;
|
|
77
77
|
|
|
78
78
|
if (uid && sql) return q;
|
|
79
79
|
|
|
@@ -98,10 +98,9 @@ export default async function layerList({
|
|
|
98
98
|
const redisKey = `${pg?.options?.database}:gis-suggest-filter:${hash}`;
|
|
99
99
|
|
|
100
100
|
const cls = el.data ? await getSelect(el.data, pg) : undefined;
|
|
101
|
-
const { arr, sql } = cls || {};
|
|
102
101
|
|
|
103
102
|
const r = {
|
|
104
|
-
...el, id: el.name || el.id, type: el.type, api: `/api/gis-suggest/${hash}`,
|
|
103
|
+
...el, id: el.name || el.id, type: el.type, api: `/api/gis-suggest/${hash}`,
|
|
105
104
|
};
|
|
106
105
|
|
|
107
106
|
const unique = await rclient.setnx(redisKey, 1);
|
|
@@ -109,11 +108,22 @@ export default async function layerList({
|
|
|
109
108
|
|
|
110
109
|
// skip subsequent calls
|
|
111
110
|
if (!unique && ttl !== -1) {
|
|
111
|
+
const str = cls?.arr ? await rclient.get(`${redisKey}:options`) : undefined;
|
|
112
|
+
if (str && str.startsWith('[{') && str.endsWith('}]')) {
|
|
113
|
+
return { ...r, options: JSON.parse(str) };
|
|
114
|
+
}
|
|
112
115
|
return r;
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
await rclient.set(redisKey, JSON.stringify({ service: row.id, filter: el.name }), 'EX', 15 * 60);
|
|
116
|
-
|
|
119
|
+
|
|
120
|
+
const arr = cls?.arr?.length ? await gisSuggest({ token: hash, uid }, pg).then((r => r.data)) : undefined;
|
|
121
|
+
// const options = arr ? cls.arr.map(el => ({ ...el, count: arr.find(r => r.id === el.id)?.count || 0 })) : undefined;
|
|
122
|
+
if (arr) {
|
|
123
|
+
await rclient.set(`${redisKey}:options`, JSON.stringify(arr), 'EX', 15 * 60);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return { ...r, options: arr };
|
|
117
127
|
}));
|
|
118
128
|
row.filters = filters;
|
|
119
129
|
}));
|
|
@@ -130,4 +140,5 @@ export default async function layerList({
|
|
|
130
140
|
// return files;
|
|
131
141
|
|
|
132
142
|
return rows.concat(files);
|
|
143
|
+
|
|
133
144
|
}
|
|
@@ -84,17 +84,17 @@ export default async function getTableColumnMeta(
|
|
|
84
84
|
: `id in ( with cc(id, text) as (${select}) select id from cc where (lower("text") ~ $1) )`;
|
|
85
85
|
|
|
86
86
|
const countQuery = pg.pgType?.[dataTypeID]?.includes("[]")
|
|
87
|
-
? `select count(distinct id)::int from ( select unnest("${queryColumn.replace(
|
|
87
|
+
? `select count(distinct id::text)::int from ( select unnest("${queryColumn.replace(
|
|
88
88
|
/"/g,
|
|
89
89
|
""
|
|
90
|
-
)}"::text[]) as id from ${tableName})q where ${arr?.length ? 'id=any($1::text[])' : '1=1'}`
|
|
91
|
-
: `select count(distinct ${queryColumn.replace(
|
|
90
|
+
)}"::text[]) as id from ${tableName})q where ${arr?.length ? 'id::text=any($1::text[])' : '1=1'}`
|
|
91
|
+
: `select count(distinct "${queryColumn.replace(
|
|
92
92
|
/"/g,
|
|
93
93
|
""
|
|
94
|
-
)})::int from ${tableName} where ${arr?.length ? `"${queryColumn.replace(
|
|
94
|
+
)}"::text)::int from ${tableName} where ${arr?.length ? `"${queryColumn.replace(
|
|
95
95
|
/"/g,
|
|
96
96
|
""
|
|
97
|
-
)}"=any($1::text[])` : '1=1'}`;
|
|
97
|
+
)}"::text=any($1::text[])` : '1=1'}`;
|
|
98
98
|
|
|
99
99
|
const total = arr?.length ? await pg
|
|
100
100
|
.query(countQuery, [arr.map((el) => el.id)])
|
|
@@ -115,7 +115,7 @@ export default async function getTableColumnMeta(
|
|
|
115
115
|
|
|
116
116
|
return {
|
|
117
117
|
arr,
|
|
118
|
-
original,
|
|
118
|
+
original: select ? `with c(id,text) as (${select}) select id, text from c` : original,
|
|
119
119
|
total,
|
|
120
120
|
searchQuery: select ? searchQuerySelect : searchQueryDefault,
|
|
121
121
|
pk: "id",
|
|
@@ -140,7 +140,7 @@ export default async function getTableColumnMeta(
|
|
|
140
140
|
|
|
141
141
|
return {
|
|
142
142
|
arr,
|
|
143
|
-
original,
|
|
143
|
+
original: select ? `with c(id,text) as (${select}) select id, text from c` : original,
|
|
144
144
|
total,
|
|
145
145
|
searchQuery: select ? searchQuerySelect : searchQueryDefault,
|
|
146
146
|
pk: "id",
|