@opengis/gis 0.2.21 → 0.2.22

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.
@@ -0,0 +1,46 @@
1
+ {
2
+ "schema": {
3
+ "name": {
4
+ "ua": "Назва",
5
+ "col": 12,
6
+ "type": "Text",
7
+ "validators": [
8
+ "required"
9
+ ]
10
+ },
11
+ "group_id": {
12
+ "type": "Autocomplete",
13
+ "data": "gis.group_list",
14
+ "col": 6,
15
+ "ua": "Група"
16
+ },
17
+ "cartocss_key": {
18
+ "ua": "Унікальний ключ",
19
+ "col": 6,
20
+ "type": "Text",
21
+ "validators": [
22
+ "required"
23
+ ]
24
+ },
25
+ "description": {
26
+ "ua": "Опис",
27
+ "col": 12,
28
+ "type": "TextArea",
29
+ "validators": [
30
+ "required"
31
+ ]
32
+ },
33
+ "is_public": {
34
+ "ua": "Чи є карта публічною?",
35
+ "col": 6,
36
+ "type": "Switcher",
37
+ "data": "yes_no"
38
+ },
39
+ "enabled": {
40
+ "ua": "Чи включена карта?",
41
+ "col": 6,
42
+ "type": "Switcher",
43
+ "data": "yes_no"
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,61 @@
1
+ {
2
+ "key": "cartocss_id",
3
+ "table": "gis.cartocss",
4
+ "form": "gis.cartocss.form",
5
+ "meta": {
6
+ "title": "name",
7
+ "search": "name,description"
8
+ },
9
+ "card": true,
10
+ "order": "created_at desc",
11
+ "columns": [
12
+ {
13
+ "ua": "Назва",
14
+ "name": "name",
15
+ "format": "text"
16
+ },
17
+ {
18
+ "ua": "Опис",
19
+ "name": "description",
20
+ "format": "text"
21
+ },
22
+ {
23
+ "ua": "Група",
24
+ "name": "group_id",
25
+ "data": "gis.group_list",
26
+ "format": "select"
27
+ },
28
+ {
29
+ "ua": "On/Off",
30
+ "name": "enabled",
31
+ "data": "yes_no",
32
+ "format": "badge"
33
+ },
34
+ {
35
+ "ua": "Чи публічний",
36
+ "name": "is_public",
37
+ "data": "yes_no",
38
+ "format": "badge"
39
+ }
40
+ ],
41
+ "filterList": [
42
+ {
43
+ "ua": "Група",
44
+ "name": "group_id",
45
+ "data": "gis.group_list",
46
+ "type": "Check"
47
+ },
48
+ {
49
+ "ua": "On/Off",
50
+ "name": "enabled",
51
+ "data": "yes_no",
52
+ "type": "Check"
53
+ },
54
+ {
55
+ "ua": "Чи публічний",
56
+ "name": "is_public",
57
+ "data": "yes_no",
58
+ "type": "Check"
59
+ }
60
+ ]
61
+ }
@@ -41,7 +41,7 @@
41
41
  "format": "badge"
42
42
  },
43
43
  {
44
- "ua": "Is public",
44
+ "ua": "Чи публічний",
45
45
  "name": "is_public",
46
46
  "data": "yes_no",
47
47
  "format": "badge"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/gis",
3
- "version": "0.2.21",
3
+ "version": "0.2.22",
4
4
  "type": "module",
5
5
  "author": "Softpro",
6
6
  "main": "./dist/index.js",
@@ -66,4 +66,4 @@
66
66
  "vue-router": "4.5.1",
67
67
  "vuedraggable": "^4.1.0"
68
68
  }
69
- }
69
+ }
@@ -12,8 +12,8 @@ const columnType = {
12
12
  'timestamp with time zone': 'date',
13
13
  };
14
14
 
15
- export async function handleRegistryRequest({ settings, query, object_id, offset = 0, limit = 16, page = 1, pg, sql }) {
16
- const { name, table_name, description, card, columns, filters, query: whereQuery, order, pk, register_id, is_files, view } = settings;
15
+ export async function handleRegistryRequest({ settings, query, object_id, is_downloadable, register_key, is_map, is_register, service_id, is_files, offset = 0, limit = 16, page = 1, pg, sql }) {
16
+ const { name, table_name, description, card, columns, filters, query: whereQuery, order, pk, register_id, view } = settings;
17
17
  const parsedColumns = Array.isArray(columns) ? columns : JSON.parse(columns);
18
18
  const filtersParsed = Array.isArray(filters) ? filters : JSON.parse(filters);
19
19
  const activeFilters = (filtersParsed || []).filter((f) => f.disabled !== true).map(el => ({ ...el, id: el.name || el.id, type: el.type, api: '/api/suggest/' + table_name + ':' + el.name + (el.data ? `?sel=${el.data}` : '') }));
@@ -52,9 +52,14 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
52
52
  card,
53
53
  d: 1,
54
54
  columns: visibleColumns,
55
+ is_downloadable,
56
+ register_key,
55
57
  register_id,
58
+ service_id,
56
59
  name,
57
60
  is_files,
61
+ is_map,
62
+ is_register,
58
63
  };
59
64
  }
60
65
 
@@ -106,15 +111,21 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
106
111
  name,
107
112
  card,
108
113
  table_name,
114
+ register_key,
109
115
  description,
110
116
  rows,
111
117
  total,
118
+ service_id,
112
119
  columns: visibleColumns,
113
120
  filters: activeFilters,
114
121
  fields,
115
122
  limit,
116
123
  page,
117
124
  view,
125
+ is_downloadable,
126
+ is_map,
127
+ is_register,
128
+ is_files,
118
129
  config: {
119
130
  listConfig
120
131
  }
@@ -20,19 +20,51 @@ export default async function gisRegistry({
20
20
  const {
21
21
  rows: [registry],
22
22
  } = await pg.query(
23
- `SELECT register_id, name, description, card, table_name, columns, filters, query, "order", pk, register_key, is_files, view
23
+ `SELECT register_id, name, description, card, table_name,
24
+ columns, filters, query, "order", pk, register_key,
25
+ is_files, view, is_downloadable, is_map, is_register, service_id
24
26
  FROM gis.registers
25
27
  WHERE $1 in (register_key,register_id)`,
26
28
  [slug]
27
29
  );
28
30
 
29
31
  if (registry) {
30
- return handleRegistryRequest({ settings: registry, query, object_id: objectId, offset, limit, page: query.page, pg, sql });
32
+ return handleRegistryRequest({
33
+ settings: registry,
34
+ query,
35
+ is_downloadable: registry.is_downloadable,
36
+ register_key: registry.register_key,
37
+ object_id: objectId,
38
+ is_map: registry.is_map,
39
+ is_register: registry.is_register,
40
+ is_files: registry.is_files,
41
+ service_id: registry.service_id,
42
+ offset,
43
+ limit,
44
+ page: query.page,
45
+ pg,
46
+ sql
47
+ });
31
48
  }
32
49
 
33
50
  const registryTemplate = await getTemplate('registry', slug);
34
51
  //if (!registryTemplate) return reply.code(404).send({ message: 'Template not found', status: 404 });
35
52
  if (!registryTemplate) throw new Error('Template not found');
36
53
 
37
- return handleRegistryRequest({ settings: registryTemplate, query, object_id: objectId, offset, limit, page: query.page, pg, sql });
54
+ return handleRegistryRequest({
55
+ settings: registryTemplate,
56
+ query,
57
+ object_id: objectId,
58
+ register_key: registry.register_key,
59
+ is_downloadable: registry?.is_downloadable || registryTemplate?.is_downloadable,
60
+ is_map: registryTemplate.is_map,
61
+ is_register: registryTemplate.is_register,
62
+ is_files: registryTemplate.is_files,
63
+ service_id: registryTemplate.service_id,
64
+ offset,
65
+ limit,
66
+ page: query.page,
67
+ pg,
68
+ sql
69
+ });
38
70
  }
@@ -0,0 +1,187 @@
1
+ import path from 'node:path';
2
+ import { existsSync } from 'node:fs';
3
+ import { createHash } from 'node:crypto';
4
+ import {
5
+ readFile, stat, mkdir, writeFile,
6
+ } from 'node:fs/promises';
7
+
8
+ import {
9
+ pgClients, getMeta,
10
+ } from '@opengis/fastify-table/utils.js';
11
+
12
+ import rootFolder from '../../../plugins/mapnik/funcs/rootFolder.mjs';
13
+
14
+ const systemColumns = ['uid', 'cdate', 'editor_id', 'editor_date', 'created_by', 'created_at', 'updated_by', 'updated_at'];
15
+
16
+ /**
17
+ * Повертає GeoJSON для сервісу на основі налаштувань з gis.services
18
+ *
19
+ * @method GET
20
+ * @param {string} params.layer - service_id
21
+ * @param {string} query.sql - повернути SQL запит замість даних
22
+ * @param {boolean} query.nocache - не використовувати кеш
23
+ */
24
+ export default async function geojson({
25
+ pg = pgClients.client, params = {}, query = {}, unittest,
26
+ }, reply) {
27
+ const { layer } = params;
28
+ const { sql, nocache, srid, type, extent } = query;
29
+
30
+ if (!layer) {
31
+ return reply.status(400).send('not enough params: layer (service_id)');
32
+ }
33
+
34
+ const serviceId = layer.replace('.json', '');
35
+
36
+ if (!pg.pk?.['gis.services']) {
37
+ return reply.status(404).send('services table not found');
38
+ }
39
+
40
+ const service = await pg.query(
41
+ `select
42
+ source_path,
43
+ query,
44
+ geometry_column,
45
+ attributes,
46
+ srid,
47
+ is_public,
48
+ is_active,
49
+ geom_type
50
+ from gis.services
51
+ where service_id = $1 and is_active = true and is_public = true`,
52
+ [serviceId],
53
+ ).then(el => el.rows?.[0]);
54
+
55
+ if (!service) {
56
+ return reply.status(404).send('service not found or not available');
57
+ }
58
+
59
+ const {
60
+ source_path: source,
61
+ query: serviceQuery,
62
+ geometry_column: gc,
63
+ attributes,
64
+ srid: serviceSrid,
65
+ geom_type: geomType,
66
+ } = service;
67
+
68
+ if (!source) {
69
+ return reply.status(400).send('invalid service source path');
70
+ }
71
+
72
+ const table = source;
73
+
74
+ if (!pg.pk?.[table]?.length) {
75
+ return reply.status(404).send('layer table not found');
76
+ }
77
+
78
+ const meta = await getMeta({ pg, table });
79
+ const { columns = [] } = meta || {};
80
+
81
+ const geom = gc || meta?.geom || 'geom';
82
+ const pk = pg.pk?.[table] || columns[0]?.name;
83
+
84
+ let attributeColumns = [];
85
+ if (attributes && Array.isArray(attributes)) {
86
+ attributeColumns = attributes
87
+ .filter(attr => attr.name && !systemColumns.includes(attr.name))
88
+ .map(attr => attr.name);
89
+ }
90
+
91
+ const columnsFiltered = attributeColumns.length > 0
92
+ ? columns.filter(col => attributeColumns.includes(col.name) && !systemColumns.includes(col.name))
93
+ : [];
94
+
95
+ const props = columnsFiltered.map(el =>
96
+ `"${el.name}"${['int4'].includes(el.type) ? '::text' : ''}`
97
+ ).join(', ');
98
+
99
+ const geometryType = (geomType || 'point').toLowerCase();
100
+ const limit = geometryType === 'point' ? 40000 : 2500;
101
+ const cacheHash = createHash('md5')
102
+ .update([serviceId, serviceQuery, srid, type, extent].filter(el => el).join('-'))
103
+ .digest('hex');
104
+
105
+ const today = new Date().toISOString().split('T')[0];
106
+ const filepath = path.join(
107
+ rootFolder,
108
+ `/geojson/${serviceId}/${today}/${cacheHash}.json`,
109
+ );
110
+
111
+ if (existsSync(filepath) && !nocache && !sql && !unittest) {
112
+ const { birthtimeMs = Date.now() } = await stat(filepath);
113
+ const ageInMs = Date.now() - birthtimeMs;
114
+ if (ageInMs < 86400000) {
115
+ const content = await readFile(filepath, 'utf8');
116
+ return reply
117
+ .status(200)
118
+ .header('Content-Type', 'application/json')
119
+ .header('Cache-Control', 'public, max-age=86400')
120
+ .send(content);
121
+ }
122
+ }
123
+
124
+ const targetSrid = srid || serviceSrid || 4326;
125
+ const useCentroid = type === 'centroid';
126
+
127
+ let geomExpression = geom;
128
+
129
+ if (useCentroid) {
130
+ geomExpression = `st_centroid(${geomExpression})`;
131
+ }
132
+
133
+ if (targetSrid !== 4326) {
134
+ geomExpression = `st_transform(${geomExpression}, 4326)`;
135
+ } else if (serviceSrid && serviceSrid !== 4326) {
136
+ geomExpression = `st_transform(${geomExpression}, 4326)`;
137
+ }
138
+
139
+ const quotedTable = table.split('.').map(el => `"${el}"`).join('.');
140
+ const quotedGeom = `"${geom}"`;
141
+
142
+ const geomFinal = `st_force2d(${geomExpression.replace(new RegExp(`(\\b)${geom}(\\b)`, 'g'), `$1${quotedGeom}$2`)})`;
143
+ const q = `
144
+ SELECT 'FeatureCollection' As type,
145
+ json_agg(f) As features
146
+ FROM (
147
+ SELECT 'Feature' As type,
148
+ row_number() over() as id,
149
+ st_asgeojson(${geomFinal}, 6, 0)::json as geometry,
150
+ (select row_to_json(tc) from (
151
+ select "${pk}" as id ${props ? ', ' + props : ''}
152
+ ) tc) as properties
153
+ FROM ${quotedTable}
154
+ WHERE ${serviceQuery || '1=1'}
155
+ AND ${quotedGeom} is not null
156
+ AND st_srid(${quotedGeom}) > 0
157
+ ${extent ? `AND ${quotedGeom} && 'BOX(${extent.split(',').reduce((p, el, i) => p + el + (i % 2 ? ',' : ' '), '')})'::box2d` : ''}
158
+ LIMIT ${limit}
159
+ ) f
160
+ `;
161
+
162
+ if (sql === '1') return q;
163
+ if (sql === '2') return filepath.replace(/\\/g, '/');
164
+
165
+ try {
166
+ const result = await pg.query(q);
167
+ const geojsonData = result.rows[0] || { type: 'FeatureCollection', features: [] };
168
+
169
+ geojsonData.service_id = serviceId;
170
+ geojsonData.count = geojsonData.features?.length || 0;
171
+
172
+ const jsonString = JSON.stringify(geojsonData);
173
+
174
+ if (!nocache && !unittest) {
175
+ await mkdir(path.dirname(filepath), { recursive: true });
176
+ await writeFile(filepath, jsonString, 'utf8');
177
+ }
178
+
179
+ return reply
180
+ .status(200)
181
+ .header('Content-Type', 'application/json')
182
+ .header('Cache-Control', nocache ? 'no-cache' : 'public, max-age=86400')
183
+ .send(jsonString);
184
+ } catch (err) {
185
+ return reply.status(500).send({ error: err.message });
186
+ }
187
+ }
@@ -0,0 +1,205 @@
1
+ import path from 'node:path';
2
+ import { existsSync } from 'node:fs';
3
+ import { createHash } from 'node:crypto';
4
+ import {
5
+ readFile, stat, mkdir, writeFile,
6
+ } from 'node:fs/promises';
7
+
8
+ import {
9
+ pgClients, getMeta, metaFormat,
10
+ } from '@opengis/fastify-table/utils.js';
11
+
12
+ import rootFolder from '../../../plugins/mapnik/funcs/rootFolder.mjs';
13
+
14
+ const systemColumns = ['uid', 'cdate', 'editor_id', 'editor_date', 'created_by', 'created_at', 'updated_by', 'updated_at', 'geom'];
15
+
16
+ /**
17
+ * Повертає JSON дані для реєстру на основі налаштувань з gis.registers
18
+ *
19
+ * @method GET
20
+ * @param {string} params.layer - register_id
21
+ * @param {string} query.page - номер сторінки (default: 1)
22
+ * @param {string} query.limit - кількість записів на сторінку (default: 100)
23
+ * @param {string} query.where - додаткова WHERE умова
24
+ * @param {string} query.sql - повернути SQL запит замість даних
25
+ * @param {boolean} query.nocache - не використовувати кеш
26
+ */
27
+ export default async function jsonData({
28
+ pg = pgClients.client, params = {}, query = {}, unittest,
29
+ }, reply) {
30
+ const { layer } = params;
31
+ const {
32
+ page = 1,
33
+ limit = 100,
34
+ where,
35
+ sql,
36
+ nocache
37
+ } = query;
38
+
39
+ if (!layer) {
40
+ return reply.status(400).send('not enough params: layer (register_id)');
41
+ }
42
+
43
+ const registerId = layer.replace('.json', '');
44
+ const pageNum = parseInt(page, 10) || 1;
45
+ const limitNum = Math.min(parseInt(limit, 10) || 100, 1000); // max 1000
46
+ const offset = (pageNum - 1) * limitNum;
47
+
48
+ if (!pg.pk?.['gis.registers']) {
49
+ return reply.status(404).send('registers table not found');
50
+ }
51
+
52
+ const register = await pg.query(
53
+ `select
54
+ table_name,
55
+ pk,
56
+ query,
57
+ columns,
58
+ is_public,
59
+ is_active,
60
+ "order"
61
+ from gis.registers
62
+ where register_id = $1 and is_active = true and is_public = true`,
63
+ [registerId],
64
+ ).then(el => el.rows?.[0]);
65
+
66
+ if (!register) {
67
+ return reply.status(404).send('register not found or not available');
68
+ }
69
+
70
+ const {
71
+ table_name: table,
72
+ pk,
73
+ query: registerQuery,
74
+ columns,
75
+ order: orderBy,
76
+ } = register;
77
+
78
+ if (!table) {
79
+ return reply.status(400).send('invalid register table_name');
80
+ }
81
+
82
+ if (!pg.pk?.[table]?.length) {
83
+ return reply.status(404).send('table not found');
84
+ }
85
+
86
+ const meta = await getMeta({ pg, table });
87
+ const { columns: metaColumns = [] } = meta || {};
88
+
89
+ let attributeColumns = [];
90
+ if (columns && Array.isArray(columns)) {
91
+ attributeColumns = columns
92
+ .filter(col => col.name && !systemColumns.includes(col.name))
93
+ .map(col => col.name);
94
+ }
95
+
96
+ const columnsFiltered = attributeColumns.length > 0
97
+ ? metaColumns.filter(col => attributeColumns.includes(col.name) && !systemColumns.includes(col.name))
98
+ : metaColumns.filter(col => !systemColumns.includes(col.name));
99
+
100
+ const props = columnsFiltered.map(el =>
101
+ `"${el.name}"${['int4'].includes(el.type) ? '::text' : ''}`
102
+ ).join(', ');
103
+
104
+ if (!props) {
105
+ return reply.status(400).send('no columns to select');
106
+ }
107
+
108
+ const cacheHash = createHash('md5')
109
+ .update([registerId, where, registerQuery, pageNum, limitNum].filter(el => el).join('-'))
110
+ .digest('hex');
111
+
112
+ const today = new Date().toISOString().split('T')[0];
113
+ const filepath = path.join(
114
+ rootFolder,
115
+ `/json/${registerId}/${today}/${cacheHash}.json`,
116
+ );
117
+
118
+ if (existsSync(filepath) && !nocache && !sql && !unittest) {
119
+ const { birthtimeMs = Date.now() } = await stat(filepath);
120
+ const ageInMs = Date.now() - birthtimeMs;
121
+ if (ageInMs < 86400000) {
122
+ const content = await readFile(filepath, 'utf8');
123
+ return reply
124
+ .status(200)
125
+ .header('Content-Type', 'application/json')
126
+ .header('Cache-Control', 'public, max-age=86400')
127
+ .send(content);
128
+ }
129
+ }
130
+
131
+ const whereConditions = [
132
+ registerQuery || '1=1',
133
+ where || 'true',
134
+ ].join(' AND ');
135
+
136
+ const quotedTable = table.split('.').map(el => `"${el}"`).join('.');
137
+
138
+ const countQuery = `
139
+ SELECT COUNT(*) as total
140
+ FROM ${quotedTable}
141
+ WHERE ${whereConditions}
142
+ `;
143
+
144
+ const dataQuery = `
145
+ SELECT "${pk}" as id ${props ? ', ' + props : ''}
146
+ FROM ${quotedTable}
147
+ WHERE ${whereConditions}
148
+ ${orderBy ? `ORDER BY ${orderBy}` : ''}
149
+ LIMIT ${limitNum}
150
+ OFFSET ${offset}
151
+ `;
152
+
153
+ if (sql === '1') return { countQuery, dataQuery };
154
+ if (sql === '2') return filepath.replace(/\\/g, '/');
155
+
156
+ try {
157
+ const [countResult, dataResult] = await Promise.all([
158
+ pg.query(countQuery),
159
+ pg.query(dataQuery),
160
+ ]);
161
+
162
+ const total = parseInt(countResult.rows[0]?.total || 0, 10);
163
+ const rows = dataResult.rows || [];
164
+
165
+ // Обробка класифікаторів
166
+ if (columns && Array.isArray(columns)) {
167
+ const classifiers = columns
168
+ .filter(col => col.data && ['select', 'badge', 'tags', 'integer', 'text', 'text[]'].includes(col.format))
169
+ .reduce((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
170
+
171
+ if (Object.keys(classifiers).length > 0) {
172
+ await metaFormat({
173
+ rows,
174
+ table,
175
+ cls: classifiers,
176
+ suffix: true,
177
+ });
178
+ }
179
+ }
180
+
181
+ const result = {
182
+ register_id: registerId,
183
+ total,
184
+ page: pageNum,
185
+ limit: limitNum,
186
+ pages: Math.ceil(total / limitNum),
187
+ data: rows,
188
+ };
189
+
190
+ const jsonString = JSON.stringify(result);
191
+
192
+ if (!nocache && !unittest) {
193
+ await mkdir(path.dirname(filepath), { recursive: true });
194
+ await writeFile(filepath, jsonString, 'utf8');
195
+ }
196
+
197
+ return reply
198
+ .status(200)
199
+ .header('Content-Type', 'application/json')
200
+ .header('Cache-Control', nocache ? 'no-cache' : 'public, max-age=86400')
201
+ .send(jsonString);
202
+ } catch (err) {
203
+ return reply.status(500).send({ error: err.message });
204
+ }
205
+ }
@@ -7,6 +7,8 @@ import mapCatalogAttribute from './controllers/mapCatalogAttribute.js';
7
7
  import rtile from './controllers/rtile.js';
8
8
  import vtile from './controllers/vtile.js';
9
9
  import vtile1 from './vtile1.js';
10
+ import geojson from './controllers/geojson.js';
11
+ import jsonData from './controllers/jsonData.js';
10
12
  import layerList from './controllers/layerList.js';
11
13
 
12
14
  import mapFormat from './controllers/mapFormat.js';
@@ -108,6 +110,17 @@ export default async function route(app) {
108
110
  console.log('\x1b[34m%s\x1b[0m', 'add vtile from gis');
109
111
  app.get('/vtile/:layer/:lang/:z/:y/:x', publicParams, vtile1);
110
112
  }
113
+
114
+ if (!app.hasRoute({ method: 'GET', url: '/api/geojson/:layer' })) {
115
+ console.log('\x1b[34m%s\x1b[0m', 'add geojson from gis');
116
+ app.get('/geojson/:layer', publicParams, geojson);
117
+ }
118
+
119
+ if (!app.hasRoute({ method: 'GET', url: '/api/json/:layer' })) {
120
+ console.log('\x1b[34m%s\x1b[0m', 'add json from gis');
121
+ app.get('/json/:layer', publicParams, jsonData);
122
+ }
123
+
111
124
  if (!app.hasRoute({ method: 'GET', url: '/api/gis-layer-list' })) {
112
125
  console.log('\x1b[34m%s\x1b[0m', 'add gis-layer-list from gis');
113
126
  app.get('/gis-layer-list', publicParams, layerList);
@@ -107,7 +107,8 @@ export default async function vtile({
107
107
  }[z] || 0.0005;
108
108
 
109
109
  const types = { point: 'ST_Point' /* ,ST_MultiPoint */, polygon: 'ST_Polygon,ST_MultiPolygon' };
110
- const queryMode = ((clusterZoom - z) > 2 ? 1 : null) || ((clusterZoom - z) > 0 ? 2 : null) || 3;
110
+ const clusterZoom1 = style?.clusterZoom || clusterZoom;
111
+ const queryMode = ((clusterZoom1 - z) > 2 ? 1 : null) || ((clusterZoom1 - z) > 0 ? 2 : null) || 3;
111
112
  // console.log(z, clusterZoom, queryMode);
112
113
  const props1 = props.filter((el, idx, arr) => idx === arr.findIndex(item => item.name === el.name));
113
114
  const q = {
@@ -120,11 +121,10 @@ export default async function vtile({
120
121
  )q`,
121
122
  2: `SELECT ST_AsMVT(q, '${layer}', 4096, 'geom','row') as tile
122
123
  FROM (
123
- SELECT floor(random() * 100000 + 1)::int +row_number() over() as row, count(*) as point_count,
124
- ${props?.length ? `${props1.map(prop => `case when count(*)=1 then min(${prop.name.replace(/'/g, "''")}) else null end as "${prop.name.replace(/'/g, "''")}"`).join(',')},` : ''}
124
+ SELECT floor(random() * 100000 + 1)::int +row_number() over() as row, count(*) as point_count,
125
125
  ST_AsMVTGeom(st_transform(st_centroid(ST_Union(geom)),3857),ST_TileEnvelope(${z},${y},${x})::box2d,4096,256,false) as geom
126
126
  FROM (
127
- SELECT ${props?.length ? `${props1.map(prop => prop.name).join(',')},` : ''} geom, ST_ClusterDBSCAN(geom,${koef},1) OVER () AS cluster
127
+ SELECT geom, ST_ClusterDBSCAN(geom,${koef},1) OVER () AS cluster
128
128
  FROM ${table} where ${layerQuery || 'true'} and ${filterData?.q || 'true'} and ${geom} && ${bbox2d} ) j
129
129
  WHERE cluster IS NOT NULL
130
130
  GROUP BY cluster