@opengis/gis 0.2.206 → 0.2.208

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 (166) hide show
  1. package/README.md +181 -181
  2. package/dist/{CardIcon-Das_4-zP.js → CardIcon-iGo8QJu9.js} +1 -1
  3. package/dist/{EntityTablePage-VnczwXQf.js → EntityTablePage-BiVoVAhN.js} +2 -2
  4. package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-CSmMFcSb.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BdL5cQgN.js} +1 -1
  5. package/dist/{MapSettings-DQ8UiQm3.js → MapSettings-CXqiYxV4.js} +2 -2
  6. package/dist/{MapToolbarRight.vue_vue_type_script_setup_true_lang-D1pkL5Zi.js → MapToolbarRight.vue_vue_type_script_setup_true_lang-BHCChxmg.js} +1 -1
  7. package/dist/{RastersTablePage-P5UlG30e.js → RastersTablePage-Dgk1wp3d.js} +2 -2
  8. package/dist/{cartocss-jQ06BuDY.js → cartocss-BIpgQU6F.js} +6 -6
  9. package/dist/{import-utils-BSzqf3hF.js → import-utils-CfXKgZFd.js} +1 -1
  10. package/dist/{index-Bbe7SAdS.js → index-CM_DTEUa.js} +49 -43
  11. package/dist/index.css +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/index.umd.cjs +48 -42
  14. package/dist/{raster-C9rmMnma.js → raster-D_vEBha8.js} +3 -3
  15. package/dist/{register-j_ATka3H.js → register-C5_Un1Ms.js} +3 -3
  16. package/dist/service-JN82JN81.js +3676 -0
  17. package/dist/{vs-datatable-Zl_KZIHN.js → vs-datatable--K-DxayK.js} +2 -2
  18. package/module/gis/cls/service_type.json +42 -42
  19. package/module/gis/form/gis.registers.form.json +127 -127
  20. package/module/test/map/addr.json +302 -302
  21. package/module/test/map/addr1.yml +23 -23
  22. package/module/test/select/address.str_id.sql +3 -3
  23. package/package.json +79 -79
  24. package/plugin.js +64 -64
  25. package/server/migrations/array_intersect.sql +13 -13
  26. package/server/migrations/cartocss.sql +27 -27
  27. package/server/migrations/group_list.sql +74 -74
  28. package/server/migrations/maps.sql +30 -30
  29. package/server/migrations/metadata.sql +415 -415
  30. package/server/migrations/ogc.sql +106 -106
  31. package/server/migrations/rasters.sql +265 -265
  32. package/server/migrations/services.sql +248 -247
  33. package/server/migrations/services_users_rel.sql +22 -22
  34. package/server/migrations/widgets.sql +20 -20
  35. package/server/plugins/crons.js +21 -21
  36. package/server/plugins/mapnik/funcs/checkRasterFile.js +107 -107
  37. package/server/plugins/mapnik/funcs/mapnik.js +151 -151
  38. package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
  39. package/server/plugins/mapnik/map.proto +437 -437
  40. package/server/plugins/vite.js +74 -74
  41. package/server/routes/cartocss/cartocss.route.js +31 -31
  42. package/server/routes/cartocss/cartocss.route.test.js +78 -78
  43. package/server/routes/cartocss/cartocss.schema.js +76 -73
  44. package/server/routes/cartocss/functions/add.cartocss.js +39 -39
  45. package/server/routes/cartocss/functions/get.cartocss.js +57 -57
  46. package/server/routes/gis/functions/checkXML.js +107 -107
  47. package/server/routes/gis/functions/dashboard.js +24 -24
  48. package/server/routes/gis/gis.route.js +26 -26
  49. package/server/routes/gis/gis.route.test.js +33 -33
  50. package/server/routes/map/fonts/index.js +1933 -1933
  51. package/server/routes/map/functions/clearTiles.js +35 -35
  52. package/server/routes/map/functions/geojson.js +187 -187
  53. package/server/routes/map/functions/gis.convert.js +65 -65
  54. package/server/routes/map/functions/gis.icon.js +327 -327
  55. package/server/routes/map/functions/jsonData.js +206 -206
  56. package/server/routes/map/functions/layerList.js +144 -144
  57. package/server/routes/map/functions/map.js +122 -122
  58. package/server/routes/map/functions/mapCatalog.js +72 -72
  59. package/server/routes/map/functions/mapCatalogAttribute.js +53 -53
  60. package/server/routes/map/functions/mapFeatures.js +133 -133
  61. package/server/routes/map/functions/mapFormat.js +246 -246
  62. package/server/routes/map/functions/mapTiles.js +162 -162
  63. package/server/routes/map/functions/maps.js +15 -15
  64. package/server/routes/map/functions/marker_icon.js +43 -43
  65. package/server/routes/map/functions/parseGeoFile.js +85 -85
  66. package/server/routes/map/functions/pointHeight.js +51 -51
  67. package/server/routes/map/functions/vtile.js +174 -174
  68. package/server/routes/map/functions/vtile1.js +191 -191
  69. package/server/routes/map/map.route.js +283 -283
  70. package/server/routes/map/map.route.test.js +693 -693
  71. package/server/routes/map/map.schema.js +356 -356
  72. package/server/routes/map/pin/circle1.svg +76 -76
  73. package/server/routes/map/pin/circle2.svg +18 -18
  74. package/server/routes/map/pin/none.svg +12 -12
  75. package/server/routes/map/pin/pin.svg +14 -14
  76. package/server/routes/map/pin/pin1.svg +16 -16
  77. package/server/routes/map/pin/pin2.svg +7 -7
  78. package/server/routes/map/pin/pin3.svg +34 -34
  79. package/server/routes/map/pin/pin4.svg +14 -14
  80. package/server/routes/map/pin/pin5.svg +7 -7
  81. package/server/routes/map/pin/pin6.svg +12 -12
  82. package/server/routes/map/pin/pin7.svg +12 -12
  83. package/server/routes/mapnik/functions/cartoBounds.js +32 -32
  84. package/server/routes/mapnik/functions/clearTiles.js +103 -103
  85. package/server/routes/mapnik/functions/convertBoundToTile.js +27 -27
  86. package/server/routes/mapnik/functions/createXml.js +76 -76
  87. package/server/routes/mapnik/functions/createXmlMulti.js +72 -72
  88. package/server/routes/mapnik/functions/fileSearch.js +35 -35
  89. package/server/routes/mapnik/functions/fileStat.js +28 -28
  90. package/server/routes/mapnik/functions/pretile.js +138 -138
  91. package/server/routes/mapnik/functions/rasterInfo.js +66 -66
  92. package/server/routes/mapnik/functions/readDir.js +22 -22
  93. package/server/routes/mapnik/functions/rtile.js +164 -164
  94. package/server/routes/mapnik/functions/uploadRaster.js +152 -152
  95. package/server/routes/mapnik/functions/uploadXML.js +140 -140
  96. package/server/routes/mapnik/mapnik.route.js +102 -102
  97. package/server/routes/mapnik/mapnik.route.test.js +370 -370
  98. package/server/routes/mapnik/mapnik.schema.mjs +195 -195
  99. package/server/routes/mapnik.prefixless/functions/mapnikLogger.js +31 -31
  100. package/server/routes/mapnik.prefixless/functions/mapnikStat.js +21 -21
  101. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.js +20 -20
  102. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.test.js +91 -91
  103. package/server/routes/mapnik.prefixless/mapnik.prefixless.schema.mjs +27 -27
  104. package/server/routes/maps/functions/add.map.js +42 -42
  105. package/server/routes/maps/functions/del.map.js +17 -17
  106. package/server/routes/maps/functions/get.map.js +119 -119
  107. package/server/routes/maps/maps.route.js +58 -58
  108. package/server/routes/maps/maps.route.test.js +231 -231
  109. package/server/routes/maps/maps.schema.js +9 -9
  110. package/server/routes/metadata/functions/editMetadata.js +35 -35
  111. package/server/routes/metadata/functions/metadataXML.js +19 -19
  112. package/server/routes/metadata/metadata.route.js +26 -26
  113. package/server/routes/metadata/metadata.route.test.js +46 -46
  114. package/server/routes/metadata/metadata.schema.js +53 -53
  115. package/server/routes/ogc/functions/map.info.point.js +117 -117
  116. package/server/routes/ogc/ogc.route.js +21 -21
  117. package/server/routes/ogc/ogc.route.test.js +53 -53
  118. package/server/routes/ogc/ogc.schema.js +16 -16
  119. package/server/routes/permissions/functions/catalog.permissions.edit.js +20 -20
  120. package/server/routes/permissions/functions/catalog.permissions.js +12 -12
  121. package/server/routes/permissions/functions/get.permissions.js +59 -59
  122. package/server/routes/permissions/functions/gis.catalog.js +80 -80
  123. package/server/routes/permissions/permissions.route.js +35 -35
  124. package/server/routes/permissions/permissions.route.test.js +35 -35
  125. package/server/routes/permissions/permissions.schema.js +43 -43
  126. package/server/routes/registers/functions/add.registry.js +37 -37
  127. package/server/routes/registers/functions/classifiers.js +100 -100
  128. package/server/routes/registers/functions/columns.js +3 -3
  129. package/server/routes/registers/functions/content.type.js +9 -9
  130. package/server/routes/registers/functions/del.registry.js +14 -14
  131. package/server/routes/registers/functions/get.info.js +93 -93
  132. package/server/routes/registers/functions/getFilterSQLParametrized/formatValue.js +328 -328
  133. package/server/routes/registers/functions/getFilterSQLParametrized/getFilterQuery.js +126 -126
  134. package/server/routes/registers/functions/getFilterSQLParametrized/getRangeQuery.js +353 -353
  135. package/server/routes/registers/functions/getFilterSQLParametrized/index.js +81 -81
  136. package/server/routes/registers/functions/getTableColumnMeta.js +148 -148
  137. package/server/routes/registers/functions/gis.export.js +159 -159
  138. package/server/routes/registers/functions/gis.registry.js +71 -71
  139. package/server/routes/registers/functions/gis.registry.list.js +61 -61
  140. package/server/routes/registers/functions/gis.suggest.js +310 -310
  141. package/server/routes/registers/functions/handleRegistryRequest.js +178 -178
  142. package/server/routes/registers/functions/map.registry.js +87 -87
  143. package/server/routes/registers/registers.route.js +92 -92
  144. package/server/routes/registers/registers.route.test.js +173 -173
  145. package/server/routes/registers/registers.schema.js +276 -276
  146. package/server/routes/root.mjs +3 -3
  147. package/server/routes/services/functions/add.service.js +62 -62
  148. package/server/routes/services/functions/create.route.js +93 -93
  149. package/server/routes/services/functions/del.service.js +12 -12
  150. package/server/routes/services/functions/get.layer.geom.js +27 -27
  151. package/server/routes/services/functions/get.service.users.js +76 -76
  152. package/server/routes/services/functions/get.services.col.js +34 -34
  153. package/server/routes/services/functions/get.services.js +124 -124
  154. package/server/routes/services/functions/legend.auto.js +77 -77
  155. package/server/routes/services/services.route.js +76 -76
  156. package/server/routes/services/services.route.test.js +171 -171
  157. package/server/routes/services/services.schema.js +459 -459
  158. package/server/routes/widgets/functions/add.widget.js +38 -38
  159. package/server/routes/widgets/functions/del.widget.js +17 -17
  160. package/server/routes/widgets/functions/get.widget.js +41 -41
  161. package/server/routes/widgets/widgets.route.js +61 -61
  162. package/server/routes/widgets/widgets.route.test.js +144 -144
  163. package/server/routes/widgets/widgets.schema.js +24 -24
  164. package/server/shared/listFiles.js +14 -14
  165. package/utils.js +13 -13
  166. package/dist/service-DJAlc1rE.js +0 -3484
@@ -1,124 +1,124 @@
1
- import { createHash } from 'node:crypto';
2
-
3
- import { NotFoundError } from '@opengis/fastify-table/errors.js';
4
- import {
5
- dataUpdate, getMeta, pgClients, yml2json,
6
- getTemplate, getSelect, getRedis
7
- } from '@opengis/fastify-table/utils.js';
8
-
9
- const columnType = {
10
- text: 'text',
11
- date: 'date',
12
- bool: 'yes/no',
13
- numeric: 'number',
14
- integer: 'number',
15
- 'timestamp without time zone': 'date',
16
- 'timestamp with time zone': 'date',
17
- };
18
-
19
- const rclient = getRedis();
20
-
21
- export default async function getServices({ id }, pg = pgClients.client) {
22
- const t = await getTemplate('layer', id);
23
- if (t) return t;
24
-
25
- if (!pg.tlist.includes('gis.services')) {
26
- throw NotFoundError('table not found');
27
- }
28
-
29
- const rows = await pg.query(`
30
- SELECT
31
- service_id, service_key, name, description, keywords, category, holder, group_id, b.group_name, service_type, card_mode,
32
- source_type, service_url, source_path, query, geom_type, geometry_column, sql_list, attributes, filters,
33
- 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,
34
- metadata_url, thumbnail_url, created_by, updated_by, updated_at, created_at, template
35
- FROM gis.services a
36
- left join lateral (select group_name from gis.group_list where group_id=a.group_id)b on 1=1
37
- where ${id ? 'service_id=$1' : '1=1'}
38
- `, [id].filter(Boolean)).then(r => r.rows || []);
39
-
40
- if (id && !rows.length) {
41
- throw NotFoundError('service not found');
42
- }
43
-
44
- const totals = pg.queryCache ? await pg.queryCache('select json_object_agg(oid::regclass, reltuples) from pg_class')
45
- .then(r => r.rows?.[0]?.json_object_agg || {}) : {};
46
-
47
- if (id) {
48
- const html = await pg.query('select body from admin.templates where template_id=$1', [id]).then(r => r.rows?.[0]?.body);
49
- Object.assign(rows[0], { html });
50
- }
51
-
52
- rows.filter(row => row.source_path).forEach(row => {
53
- Object.assign(row, { count: totals[row.source_path] || 0 });
54
- });
55
-
56
- const columns = rows[0].source_path ? await getMeta({ pg, table: rows[0].source_path }).then(r => r?.columns || []) : [];
57
-
58
- const fields = columns.map(({ name, dataTypeID, title }) => ({ name, type: columnType[pg.pgType?.[dataTypeID] || 'text'], label: title || name }));
59
-
60
- // Віртуальне поле: файли з crm.files (не колонка таблиці source_path)
61
- if (rows[0]?.source_path && pg.tlist?.includes('crm.files') && !fields.some((f) => f.name === 'files')) {
62
- fields.push({ name: 'files', type: 'file', format: 'file', label: 'Файли' });
63
- }
64
-
65
- const noCenterIds = rows.filter(row => !row.center && row.bbox).map(row => row.service_id);
66
-
67
- const centers = noCenterIds.length ? await pg.query('SELECT json_object_agg(service_id, st_pointonsurface(bbox)::json) FROM gis.services where service_id=any($1)', [noCenterIds].filter(Boolean)).then(r => r.rows?.[0]?.json_object_agg || {}) : {};
68
-
69
- await Promise.all(rows.filter(row => centers[row.service_id]).map(async (row) => {
70
- // console.log('update service center', row.service_id, JSON.stringify(centers[row.service_id]));
71
- await dataUpdate({
72
- pg, id: row.service_id, table: 'gis.services', data: { center: centers[row.service_id] },
73
- });
74
- Object.assign(row, { center: centers[row.service_id] });
75
- }));
76
-
77
- rows.forEach(row => Object.assign(row, {
78
- center: row.center?.coordinates,
79
- style: row.style ? yml2json(row.style) : undefined,
80
- }));
81
- rows.filter(row => row.extent).forEach(row => Object.assign(row, {
82
- extent: row.extent.match(/BOX\(([^)]+)\)/)?.[1]
83
- ?.replace?.(/ /g, ',')
84
- ?.split?.(','),
85
- }));
86
-
87
-
88
- if (id && rows.length && rows[0].filters) {
89
- const activeFilters = await Promise.all((rows[0].filters || []).filter((f) => f.disabled !== true).map(async (el) => {
90
- const hash = createHash('md5').update([id, el.name, el.data].filter(Boolean).join('-')).digest('hex');
91
- const redisKey = `${pg?.options?.database}:gis-suggest-filter:${hash}`;
92
-
93
- const cls = el.data ? await getSelect(el.data, pg) : undefined;
94
- const { arr, sql } = cls || {};
95
-
96
- const r = {
97
- ...el, id: el.name || el.id, type: el.type, api: `/api/gis-suggest/${hash}`, options: arr, select: sql
98
- };
99
-
100
- const unique = await rclient.setnx(redisKey, 1);
101
- const ttl = await rclient.ttl(redisKey);
102
-
103
- // skip subsequent calls
104
- if (!unique && ttl !== -1) {
105
- return r;
106
- }
107
-
108
- await rclient.set(redisKey, JSON.stringify({ service: id, filter: el.name }), 'EX', 15 * 60);
109
- return r;
110
- }));
111
- Object.assign(rows[0], {
112
- filters: activeFilters,
113
- });
114
- }
115
-
116
- if (id) {
117
- return { ...rows[0], fields };
118
- }
119
-
120
- return {
121
- rows,
122
- fields,
123
- };
124
- }
1
+ import { createHash } from 'node:crypto';
2
+
3
+ import { NotFoundError } from '@opengis/fastify-table/errors.js';
4
+ import {
5
+ dataUpdate, getMeta, pgClients, yml2json,
6
+ getTemplate, getSelect, getRedis
7
+ } from '@opengis/fastify-table/utils.js';
8
+
9
+ const columnType = {
10
+ text: 'text',
11
+ date: 'date',
12
+ bool: 'yes/no',
13
+ numeric: 'number',
14
+ integer: 'number',
15
+ 'timestamp without time zone': 'date',
16
+ 'timestamp with time zone': 'date',
17
+ };
18
+
19
+ const rclient = getRedis();
20
+
21
+ export default async function getServices({ id }, pg = pgClients.client) {
22
+ const t = await getTemplate('layer', id);
23
+ if (t) return t;
24
+
25
+ if (!pg.tlist.includes('gis.services')) {
26
+ throw NotFoundError('table not found');
27
+ }
28
+
29
+ const rows = await pg.query(`
30
+ SELECT
31
+ service_id, service_key, name, description, keywords, category, holder, group_id, b.group_name, service_type, card_mode,
32
+ source_type, service_url, source_path, query, geom_type, geometry_column, sql_list, attributes, filters,
33
+ 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,
34
+ metadata_url, thumbnail_url, created_by, updated_by, updated_at, created_at, template
35
+ FROM gis.services a
36
+ left join lateral (select group_name from gis.group_list where group_id=a.group_id)b on 1=1
37
+ where ${id ? 'service_id=$1' : '1=1'}
38
+ `, [id].filter(Boolean)).then(r => r.rows || []);
39
+
40
+ if (id && !rows.length) {
41
+ throw NotFoundError('service not found');
42
+ }
43
+
44
+ const totals = pg.queryCache ? await pg.queryCache('select json_object_agg(oid::regclass, reltuples) from pg_class')
45
+ .then(r => r.rows?.[0]?.json_object_agg || {}) : {};
46
+
47
+ if (id) {
48
+ const html = await pg.query('select body from admin.templates where template_id=$1', [id]).then(r => r.rows?.[0]?.body);
49
+ Object.assign(rows[0], { html });
50
+ }
51
+
52
+ rows.filter(row => row.source_path).forEach(row => {
53
+ Object.assign(row, { count: totals[row.source_path] || 0 });
54
+ });
55
+
56
+ const columns = rows[0].source_path ? await getMeta({ pg, table: rows[0].source_path }).then(r => r?.columns || []) : [];
57
+
58
+ const fields = columns.map(({ name, dataTypeID, title }) => ({ name, type: columnType[pg.pgType?.[dataTypeID] || 'text'], label: title || name }));
59
+
60
+ // Віртуальне поле: файли з crm.files (не колонка таблиці source_path)
61
+ if (rows[0]?.source_path && pg.tlist?.includes('crm.files') && !fields.some((f) => f.name === 'files')) {
62
+ fields.push({ name: 'files', type: 'file', format: 'file', label: 'Файли' });
63
+ }
64
+
65
+ const noCenterIds = rows.filter(row => !row.center && row.bbox).map(row => row.service_id);
66
+
67
+ const centers = noCenterIds.length ? await pg.query('SELECT json_object_agg(service_id, st_pointonsurface(bbox)::json) FROM gis.services where service_id=any($1)', [noCenterIds].filter(Boolean)).then(r => r.rows?.[0]?.json_object_agg || {}) : {};
68
+
69
+ await Promise.all(rows.filter(row => centers[row.service_id]).map(async (row) => {
70
+ // console.log('update service center', row.service_id, JSON.stringify(centers[row.service_id]));
71
+ await dataUpdate({
72
+ pg, id: row.service_id, table: 'gis.services', data: { center: centers[row.service_id] },
73
+ });
74
+ Object.assign(row, { center: centers[row.service_id] });
75
+ }));
76
+
77
+ rows.forEach(row => Object.assign(row, {
78
+ center: row.center?.coordinates,
79
+ style: row.style ? yml2json(row.style) : undefined,
80
+ }));
81
+ rows.filter(row => row.extent).forEach(row => Object.assign(row, {
82
+ extent: row.extent.match(/BOX\(([^)]+)\)/)?.[1]
83
+ ?.replace?.(/ /g, ',')
84
+ ?.split?.(','),
85
+ }));
86
+
87
+
88
+ if (id && rows.length && rows[0].filters) {
89
+ const activeFilters = await Promise.all((rows[0].filters || []).filter((f) => f.disabled !== true).map(async (el) => {
90
+ const hash = createHash('md5').update([id, el.name, el.data].filter(Boolean).join('-')).digest('hex');
91
+ const redisKey = `${pg?.options?.database}:gis-suggest-filter:${hash}`;
92
+
93
+ const cls = el.data ? await getSelect(el.data, pg) : undefined;
94
+ const { arr, sql } = cls || {};
95
+
96
+ const r = {
97
+ ...el, id: el.name || el.id, type: el.type, api: `/api/gis-suggest/${hash}`, options: arr, select: sql
98
+ };
99
+
100
+ const unique = await rclient.setnx(redisKey, 1);
101
+ const ttl = await rclient.ttl(redisKey);
102
+
103
+ // skip subsequent calls
104
+ if (!unique && ttl !== -1) {
105
+ return r;
106
+ }
107
+
108
+ await rclient.set(redisKey, JSON.stringify({ service: id, filter: el.name }), 'EX', 15 * 60);
109
+ return r;
110
+ }));
111
+ Object.assign(rows[0], {
112
+ filters: activeFilters,
113
+ });
114
+ }
115
+
116
+ if (id) {
117
+ return { ...rows[0], fields };
118
+ }
119
+
120
+ return {
121
+ rows,
122
+ fields,
123
+ };
124
+ }
@@ -1,78 +1,78 @@
1
- import { dataUpdate, getMeta, getSelectVal, yml2json } from "@opengis/fastify-table/utils.js";
2
-
3
- export default async function legendAuto({ params = {}, query = {}, user = {}, pg = pgClients.client }, reply) {
4
- if (!params.id) {
5
- return reply.status(400).send({ error: "not enough params: id", code: 400 });
6
- }
7
-
8
- const service = await pg.query(`SELECT source_path as table, style, legend as dblegend FROM gis.services where service_id=$1`, [params.id]).then(el => el.rows?.[0]);
9
-
10
- if (!service) {
11
- return reply.status(404).send({ error: "Service not found", code: 404 });
12
- }
13
-
14
- const { style, dblegend, table } = service;
15
-
16
- if (!table) {
17
- return reply.status(400).send({ error: "service table not specified", code: 400 });
18
- }
19
-
20
- if (dblegend && !query.nocache) {
21
- return reply.status(400).send({ error: "legend already exists", code: 400 });
22
- }
23
-
24
- if (!style) {
25
- return reply.status(400).send({ error: "empty service style", code: 400 });
26
- }
27
-
28
- const { colorAttr, iconAttr } = yml2json(style);
29
-
30
- if (!colorAttr && !iconAttr) {
31
- return reply.status(400).send({ error: "colorAttr / iconAttr not specified", code: 400 });
32
- }
33
-
34
- const { columns = [] } = await getMeta({ pg, table });
35
-
36
- const attr = columns.find(col => col.name === (colorAttr || iconAttr));
37
-
38
- if (!attr?.name) {
39
- return reply.status(404).send({ error: "attribute column not found", code: 404 });
40
- }
41
-
42
- const values = await pg.query(`select array_agg(distinct "${attr.name}") from ${table}`).then(el => el.rows?.[0]?.array_agg || []);
43
- const arr = await getSelectVal({ pg, name: `${table}.${attr.name}`, table, values, ar: true });
44
-
45
- const colors = {
46
- 1: "#FFCF1F1F",
47
- 2: "#FF1FCF2D",
48
- 3: "#FF1F77CF"
49
- };
50
-
51
- const colorKeys = Object.keys(colors).map(Number);
52
-
53
- const legend = arr
54
- ? arr.map((el, idx) => ({
55
- name: el.id,
56
- label: el.text,
57
- icon: iconAttr ? el.icon : undefined,
58
- color: colorAttr ? (el.color || colors[colorKeys[idx % colorKeys.length]]) : undefined,
59
- }))
60
- : values.map((el, idx) => ({
61
- name: el,
62
- label: el,
63
- icon: undefined,
64
- color: colorAttr ? (colors[colorKeys[idx % colorKeys.length]]) : undefined,
65
- }));
66
-
67
- const res = await dataUpdate({
68
- pg,
69
- table: 'gis.services',
70
- id: params.id,
71
- data: {
72
- legend
73
- },
74
- uid: user.uid,
75
- });
76
-
77
- return reply.status(200).send(res);
1
+ import { dataUpdate, getMeta, getSelectVal, yml2json } from "@opengis/fastify-table/utils.js";
2
+
3
+ export default async function legendAuto({ params = {}, query = {}, user = {}, pg = pgClients.client }, reply) {
4
+ if (!params.id) {
5
+ return reply.status(400).send({ error: "not enough params: id", code: 400 });
6
+ }
7
+
8
+ const service = await pg.query(`SELECT source_path as table, style, legend as dblegend FROM gis.services where service_id=$1`, [params.id]).then(el => el.rows?.[0]);
9
+
10
+ if (!service) {
11
+ return reply.status(404).send({ error: "Service not found", code: 404 });
12
+ }
13
+
14
+ const { style, dblegend, table } = service;
15
+
16
+ if (!table) {
17
+ return reply.status(400).send({ error: "service table not specified", code: 400 });
18
+ }
19
+
20
+ if (dblegend && !query.nocache) {
21
+ return reply.status(400).send({ error: "legend already exists", code: 400 });
22
+ }
23
+
24
+ if (!style) {
25
+ return reply.status(400).send({ error: "empty service style", code: 400 });
26
+ }
27
+
28
+ const { colorAttr, iconAttr } = yml2json(style);
29
+
30
+ if (!colorAttr && !iconAttr) {
31
+ return reply.status(400).send({ error: "colorAttr / iconAttr not specified", code: 400 });
32
+ }
33
+
34
+ const { columns = [] } = await getMeta({ pg, table });
35
+
36
+ const attr = columns.find(col => col.name === (colorAttr || iconAttr));
37
+
38
+ if (!attr?.name) {
39
+ return reply.status(404).send({ error: "attribute column not found", code: 404 });
40
+ }
41
+
42
+ const values = await pg.query(`select array_agg(distinct "${attr.name}") from ${table}`).then(el => el.rows?.[0]?.array_agg || []);
43
+ const arr = await getSelectVal({ pg, name: `${table}.${attr.name}`, table, values, ar: true });
44
+
45
+ const colors = {
46
+ 1: "#FFCF1F1F",
47
+ 2: "#FF1FCF2D",
48
+ 3: "#FF1F77CF"
49
+ };
50
+
51
+ const colorKeys = Object.keys(colors).map(Number);
52
+
53
+ const legend = arr
54
+ ? arr.map((el, idx) => ({
55
+ name: el.id,
56
+ label: el.text,
57
+ icon: iconAttr ? el.icon : undefined,
58
+ color: colorAttr ? (el.color || colors[colorKeys[idx % colorKeys.length]]) : undefined,
59
+ }))
60
+ : values.map((el, idx) => ({
61
+ name: el,
62
+ label: el,
63
+ icon: undefined,
64
+ color: colorAttr ? (colors[colorKeys[idx % colorKeys.length]]) : undefined,
65
+ }));
66
+
67
+ const res = await dataUpdate({
68
+ pg,
69
+ table: 'gis.services',
70
+ id: params.id,
71
+ data: {
72
+ legend
73
+ },
74
+ uid: user.uid,
75
+ });
76
+
77
+ return reply.status(200).send(res);
78
78
  }
@@ -1,76 +1,76 @@
1
- // import getLayerGeom from './functions/get.layer.geom.js';
2
- import getServices from './functions/get.services.js';
3
- import getServiceUsers from './functions/get.service.users.js';
4
- import deleteService from './functions/del.service.js';
5
- import addService from './functions/add.service.js';
6
- import getServicesCol from './functions/get.services.col.js';
7
- // import legendAuto from './functions/legend.auto.js';
8
- import createRoute from './functions/create.route.js';
9
-
10
- import {
11
- getServicesSchema,
12
- getServicesColSchema,
13
- addServiceSchema,
14
- editServiceSchema,
15
- deleteServiceSchema,
16
- getServiceUsersSchema,
17
- createRouteSchema,
18
- } from './services.schema.js';
19
- const publicParams = { config: { policy: 'L0', package: 'gis' } };
20
-
21
- async function route(app) {
22
- app.get('/gis-service/:id?', { ...publicParams, schema: getServicesSchema }, async ({ params, pg }) => {
23
- const result = await getServices({
24
- id: params.id,
25
- }, pg);
26
- return result;
27
- });
28
- app.get('/gis-service/:id/:col', { ...publicParams, schema: getServicesColSchema }, async ({ params, pg }) => {
29
- const result = await getServicesCol({
30
- id: params.id,
31
- column: params.col,
32
- }, pg);
33
- return result;
34
- });
35
- app.post('/gis-service/:id?', { ...publicParams, schema: addServiceSchema }, async ({ method, params, body, user, pg }) => {
36
- const result = await addService({
37
- method,
38
- id: params.id,
39
- body,
40
- uid: user?.uid,
41
- }, pg);
42
- return result;
43
- });
44
- app.put('/gis-service/:id', { ...publicParams, schema: editServiceSchema }, async ({ method, params, body, user, pg }) => {
45
- const result = await addService({
46
- method,
47
- id: params.id,
48
- body,
49
- uid: user?.uid,
50
- }, pg);
51
- return result;
52
- });
53
- app.delete('/gis-service/:id', { ...publicParams, schema: deleteServiceSchema }, async ({ params, user, pg }) => {
54
- const result = await deleteService({
55
- id: params.id,
56
- uid: user?.uid
57
- }, pg);
58
- return result;
59
- });
60
- // app.get('/legend-auto/:id', { ...publicParams, schema: legendAutoSchema }, legendAuto);
61
- app.get('/gis-service-users/:id', { ...publicParams, schema: getServiceUsersSchema }, async ({ params, query, pg }) => {
62
- const result = await getServiceUsers({
63
- id: params.id,
64
- search: query.search,
65
- limit: query.limit,
66
- offset: query.offset,
67
- }, pg);
68
- return result;
69
- });
70
- app.get('/routes', { ...publicParams, schema: createRouteSchema }, async ({ query }) => {
71
- const { from, to, via, mode, alternatives, steps, optimize, surface, weight } = query;
72
- const result = await createRoute({ from, to, via, mode, alternatives, steps, optimize, surface, weight });
73
- return result;
74
- });
75
- }
76
- export default route;
1
+ // import getLayerGeom from './functions/get.layer.geom.js';
2
+ import getServices from './functions/get.services.js';
3
+ import getServiceUsers from './functions/get.service.users.js';
4
+ import deleteService from './functions/del.service.js';
5
+ import addService from './functions/add.service.js';
6
+ import getServicesCol from './functions/get.services.col.js';
7
+ // import legendAuto from './functions/legend.auto.js';
8
+ import createRoute from './functions/create.route.js';
9
+
10
+ import {
11
+ getServicesSchema,
12
+ getServicesColSchema,
13
+ addServiceSchema,
14
+ editServiceSchema,
15
+ deleteServiceSchema,
16
+ getServiceUsersSchema,
17
+ createRouteSchema,
18
+ } from './services.schema.js';
19
+ const publicParams = { config: { policy: 'L0', package: 'gis' } };
20
+
21
+ async function route(app) {
22
+ app.get('/gis-service/:id?', { ...publicParams, schema: getServicesSchema }, async ({ params, pg }) => {
23
+ const result = await getServices({
24
+ id: params.id,
25
+ }, pg);
26
+ return result;
27
+ });
28
+ app.get('/gis-service/:id/:col', { ...publicParams, schema: getServicesColSchema }, async ({ params, pg }) => {
29
+ const result = await getServicesCol({
30
+ id: params.id,
31
+ column: params.col,
32
+ }, pg);
33
+ return result;
34
+ });
35
+ app.post('/gis-service/:id?', { ...publicParams, schema: addServiceSchema }, async ({ method, params, body, user, pg }) => {
36
+ const result = await addService({
37
+ method,
38
+ id: params.id,
39
+ body,
40
+ uid: user?.uid,
41
+ }, pg);
42
+ return result;
43
+ });
44
+ app.put('/gis-service/:id', { ...publicParams, schema: editServiceSchema }, async ({ method, params, body, user, pg }) => {
45
+ const result = await addService({
46
+ method,
47
+ id: params.id,
48
+ body,
49
+ uid: user?.uid,
50
+ }, pg);
51
+ return result;
52
+ });
53
+ app.delete('/gis-service/:id', { ...publicParams, schema: deleteServiceSchema }, async ({ params, user, pg }) => {
54
+ const result = await deleteService({
55
+ id: params.id,
56
+ uid: user?.uid
57
+ }, pg);
58
+ return result;
59
+ });
60
+ // app.get('/legend-auto/:id', { ...publicParams, schema: legendAutoSchema }, legendAuto);
61
+ app.get('/gis-service-users/:id', { ...publicParams, schema: getServiceUsersSchema }, async ({ params, query, pg }) => {
62
+ const result = await getServiceUsers({
63
+ id: params.id,
64
+ search: query.search,
65
+ limit: query.limit,
66
+ offset: query.offset,
67
+ }, pg);
68
+ return result;
69
+ });
70
+ app.get('/routes', { ...publicParams, schema: createRouteSchema }, async ({ query }) => {
71
+ const { from, to, via, mode, alternatives, steps, optimize, surface, weight } = query;
72
+ const result = await createRoute({ from, to, via, mode, alternatives, steps, optimize, surface, weight });
73
+ return result;
74
+ });
75
+ }
76
+ export default route;