@opengis/gis 0.2.207 → 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 -248
  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,73 +1,73 @@
1
- import { config, pgClients, yml2json } from "@opengis/fastify-table/utils.js";
2
-
3
- const { prefix = '/api' } = config;
4
-
5
- function getBBox(coordinates) {
6
- return coordinates[0].reduce(
7
- ([minLon, minLat, maxLon, maxLat], [lon, lat]) => [
8
- Math.min(minLon, lon),
9
- Math.min(minLat, lat),
10
- Math.max(maxLon, lon),
11
- Math.max(maxLat, lat)
12
- ],
13
- [coordinates[0][0][0], coordinates[0][0][1], coordinates[0][0][0], coordinates[0][0][1]]
14
- );
15
- }
16
-
17
- export default async function mapCatalog({ } = {}, pg = pgClients.client) {
18
- const { rows: services = [] } = pg.pk?.['gis.services']
19
- ? await pg.query(`select
20
- service_id as id, name, service_type, service_url as url,
21
- source_type, source_path, geometry_column, style, layers,
22
- st_asgeojson(bbox)::json->'coordinates' as bbox,
23
- st_asgeojson(center)::json->'coordinates' as center,
24
- popup, card, filters
25
- from gis.services where is_active and is_public`
26
- )
27
- : {};
28
-
29
- const bboxq = services.filter(el => el.source_path && pg?.pk?.[el.source_path] && !el.bbox).map(el => `update gis.services set bbox = (select st_extent(${el.geometry_column || 'geom'})::geometry from ${el.source_path}) where service_id='${el.id}'`).join(';');
30
- await pg.query(bboxq).catch(err => console.error(err.toString()));
31
-
32
- services.filter(row => row.style).map(row => {
33
- row.style = yml2json(row.style);
34
- });
35
-
36
- services.filter(el => el.bbox).forEach(el => {
37
- el.bbox = getBBox(el.bbox);
38
- });
39
-
40
- services.filter(el => el.source_type === 'database').forEach(el => {
41
- el.url = `${prefix}/layer-vtile/${el.id}/{z}/{x}/{y}.vmt`;
42
- });
43
-
44
- const { rows: rasters = [] } = pg.pk?.['gis.rasters']
45
- ? await pg.query(
46
- `select
47
- raster_id as id, name, source_type,
48
- st_asgeojson(bbox):: json -> 'coordinates' as bbox,
49
- st_asgeojson(center):: json -> 'coordinates' as center
50
- from gis.rasters where is_active and is_public`
51
- )
52
- : {};
53
-
54
- const { rows: ogc = [] } = pg.pk?.['gis.ogc_service']
55
- ? await pg.query(
56
- `select
57
- service_id as id, name, 'raster' as source_type, url
58
- from gis.ogc_service `
59
- )
60
- : {};
61
-
62
-
63
-
64
- rasters.forEach(el => {
65
- el.url = `${prefix}/layer-rtile/${el.id}/{z}/{x}/{y}.png`;
66
- });
67
-
68
- rasters.filter(el => el.bbox).forEach(el => {
69
- el.bbox = getBBox(el.bbox);
70
- });
71
-
72
- return { services, rasters: rasters.concat(ogc) };
1
+ import { config, pgClients, yml2json } from "@opengis/fastify-table/utils.js";
2
+
3
+ const { prefix = '/api' } = config;
4
+
5
+ function getBBox(coordinates) {
6
+ return coordinates[0].reduce(
7
+ ([minLon, minLat, maxLon, maxLat], [lon, lat]) => [
8
+ Math.min(minLon, lon),
9
+ Math.min(minLat, lat),
10
+ Math.max(maxLon, lon),
11
+ Math.max(maxLat, lat)
12
+ ],
13
+ [coordinates[0][0][0], coordinates[0][0][1], coordinates[0][0][0], coordinates[0][0][1]]
14
+ );
15
+ }
16
+
17
+ export default async function mapCatalog({ } = {}, pg = pgClients.client) {
18
+ const { rows: services = [] } = pg.pk?.['gis.services']
19
+ ? await pg.query(`select
20
+ service_id as id, name, service_type, service_url as url,
21
+ source_type, source_path, geometry_column, style, layers,
22
+ st_asgeojson(bbox)::json->'coordinates' as bbox,
23
+ st_asgeojson(center)::json->'coordinates' as center,
24
+ popup, card, filters
25
+ from gis.services where is_active and is_public`
26
+ )
27
+ : {};
28
+
29
+ const bboxq = services.filter(el => el.source_path && pg?.pk?.[el.source_path] && !el.bbox).map(el => `update gis.services set bbox = (select st_extent(${el.geometry_column || 'geom'})::geometry from ${el.source_path}) where service_id='${el.id}'`).join(';');
30
+ await pg.query(bboxq).catch(err => console.error(err.toString()));
31
+
32
+ services.filter(row => row.style).map(row => {
33
+ row.style = yml2json(row.style);
34
+ });
35
+
36
+ services.filter(el => el.bbox).forEach(el => {
37
+ el.bbox = getBBox(el.bbox);
38
+ });
39
+
40
+ services.filter(el => el.source_type === 'database').forEach(el => {
41
+ el.url = `${prefix}/layer-vtile/${el.id}/{z}/{x}/{y}.vmt`;
42
+ });
43
+
44
+ const { rows: rasters = [] } = pg.pk?.['gis.rasters']
45
+ ? await pg.query(
46
+ `select
47
+ raster_id as id, name, source_type,
48
+ st_asgeojson(bbox):: json -> 'coordinates' as bbox,
49
+ st_asgeojson(center):: json -> 'coordinates' as center
50
+ from gis.rasters where is_active and is_public`
51
+ )
52
+ : {};
53
+
54
+ const { rows: ogc = [] } = pg.pk?.['gis.ogc_service']
55
+ ? await pg.query(
56
+ `select
57
+ service_id as id, name, 'raster' as source_type, url
58
+ from gis.ogc_service `
59
+ )
60
+ : {};
61
+
62
+
63
+
64
+ rasters.forEach(el => {
65
+ el.url = `${prefix}/layer-rtile/${el.id}/{z}/{x}/{y}.png`;
66
+ });
67
+
68
+ rasters.filter(el => el.bbox).forEach(el => {
69
+ el.bbox = getBBox(el.bbox);
70
+ });
71
+
72
+ return { services, rasters: rasters.concat(ogc) };
73
73
  }
@@ -1,54 +1,54 @@
1
- import { BadRequestError } from "@opengis/fastify-table/errors.js";
2
- import { pgClients, getMeta, getSelect, getSelectVal } from "@opengis/fastify-table/utils.js";
3
-
4
- export default async function mapCatalogAttribute({ service, attr, cls: queryCls }, pg = pgClients.client) {
5
- if (!service) {
6
- throw BadRequestError('not enough params: service');
7
- }
8
-
9
- if (!attr) {
10
- throw BadRequestError('not enough params: attr');
11
- }
12
-
13
- if (!pg.pk?.['gis.services']) {
14
- throw NotFoundError('services table not found');
15
- }
16
-
17
- const source = await pg.query(
18
- 'select source_path from gis.services where service_id=$1 and is_active and is_public',
19
- [service]
20
- ).then(r => r.rows?.[0]?.source_path);
21
-
22
- if (!source) {
23
- throw NotFoundError('service not found');
24
- }
25
-
26
- const cls = await getSelect(queryCls || attr, pg);
27
- const colname = queryCls ? attr : attr.split(':').pop();
28
-
29
- if (!colname) {
30
- throw BadRequestError('invalid params: attr');
31
- }
32
-
33
- const columns = await getMeta({ pg, table: source }).then(r => r.columns || []);
34
- const { dataTypeID } = columns.find(col => col.name === colname) || {};
35
-
36
- const q = dataTypeID && pg.pgType[dataTypeID]?.includes('[]')
37
- ? `select unnest(${colname})::text as id,count(*) from ${source} group by unnest(${colname}) limit 100`
38
- : `select ${colname}::text as id,count(*) from ${source} group by ${colname} limit 100`;
39
-
40
- const countArr = await pg.queryCache(q).then(r => r.rows || []);
41
-
42
- const clsData = await getSelectVal({ pg, values: countArr.map(el => el.id), name: queryCls || attr });
43
-
44
- const legend = countArr.map(cel => {
45
- const data = cls?.arr?.find(c => c.id?.toString?.() === cel.id?.toString?.()) || { text: clsData?.[cel.id]?.text || clsData?.[cel.id] };
46
- return { ...cel, ...data };
47
- });
48
-
49
- const { min, max } = await pg.queryCache(
50
- `select min(${attr}), max(${attr}) from ${source} where 1=1`,
51
- ).then(r => r.rows?.[0] || {});
52
-
53
- return { legend, min, max };
1
+ import { BadRequestError } from "@opengis/fastify-table/errors.js";
2
+ import { pgClients, getMeta, getSelect, getSelectVal } from "@opengis/fastify-table/utils.js";
3
+
4
+ export default async function mapCatalogAttribute({ service, attr, cls: queryCls }, pg = pgClients.client) {
5
+ if (!service) {
6
+ throw BadRequestError('not enough params: service');
7
+ }
8
+
9
+ if (!attr) {
10
+ throw BadRequestError('not enough params: attr');
11
+ }
12
+
13
+ if (!pg.pk?.['gis.services']) {
14
+ throw NotFoundError('services table not found');
15
+ }
16
+
17
+ const source = await pg.query(
18
+ 'select source_path from gis.services where service_id=$1 and is_active and is_public',
19
+ [service]
20
+ ).then(r => r.rows?.[0]?.source_path);
21
+
22
+ if (!source) {
23
+ throw NotFoundError('service not found');
24
+ }
25
+
26
+ const cls = await getSelect(queryCls || attr, pg);
27
+ const colname = queryCls ? attr : attr.split(':').pop();
28
+
29
+ if (!colname) {
30
+ throw BadRequestError('invalid params: attr');
31
+ }
32
+
33
+ const columns = await getMeta({ pg, table: source }).then(r => r.columns || []);
34
+ const { dataTypeID } = columns.find(col => col.name === colname) || {};
35
+
36
+ const q = dataTypeID && pg.pgType[dataTypeID]?.includes('[]')
37
+ ? `select unnest(${colname})::text as id,count(*) from ${source} group by unnest(${colname}) limit 100`
38
+ : `select ${colname}::text as id,count(*) from ${source} group by ${colname} limit 100`;
39
+
40
+ const countArr = await pg.queryCache(q).then(r => r.rows || []);
41
+
42
+ const clsData = await getSelectVal({ pg, values: countArr.map(el => el.id), name: queryCls || attr });
43
+
44
+ const legend = countArr.map(cel => {
45
+ const data = cls?.arr?.find(c => c.id?.toString?.() === cel.id?.toString?.()) || { text: clsData?.[cel.id]?.text || clsData?.[cel.id] };
46
+ return { ...cel, ...data };
47
+ });
48
+
49
+ const { min, max } = await pg.queryCache(
50
+ `select min(${attr}), max(${attr}) from ${source} where 1=1`,
51
+ ).then(r => r.rows?.[0] || {});
52
+
53
+ return { legend, min, max };
54
54
  }
@@ -1,133 +1,133 @@
1
- import { BadRequestError, NotFoundError } from '@opengis/fastify-table/errors.js';
2
- import {
3
- getMeta, getFilterSQL, getTemplate, metaFormat, pgClients, yml2json,
4
- } from '@opengis/fastify-table/utils.js';
5
-
6
- const layerMetaColumns = ['id', 'name', 'label', 'source', 'table', 'pk', 'geomColumn', 'srid', 'cls', 'htmls'];
7
-
8
- export default async function mapFeaturesPoint({ slug, id, x, y, sql }, pg = pgClients.client) {
9
- if (!slug) {
10
- throw BadRequestError('not enough params: slug');
11
- }
12
-
13
- if (!(x && y) && !id) {
14
- throw BadRequestError('not enough params: xy');
15
- }
16
-
17
- const loadTemplate = await getTemplate('map', slug);
18
-
19
- if (!loadTemplate) {
20
- throw NotFoundError('map not found');
21
- }
22
-
23
- const index = loadTemplate?.find?.(el => el[0].split('.').shift() === 'index')?.[1];
24
-
25
- const layers1 = !index
26
- ? loadTemplate?.layers
27
- : loadTemplate?.filter?.(el => el[0].split('.').shift() !== 'index')?.map(el => ({ ...el[1], id: el[0].replace('.yml', '').replace('.json', '') }));
28
-
29
- const serviceLayers = await Promise.all((layers1 || []).filter(el => typeof el === 'string').map(async (layer) => {
30
- const layerData = await getTemplate('layer', layer);
31
- const serviceData = layerData || await pg.query('select service_id as id, *, st_asgeojson(bbox)::json as bbox, st_asgeojson(center)::json as center from gis.services where service_id=$1', [layer]).then(el => el.rows?.[0]);
32
- serviceData.style = yml2json(serviceData.style);
33
- return { ...serviceData, id: layer, visible: true };
34
- }));
35
-
36
- const layers = (layers1 || []).filter(el => el && typeof el === 'object').concat(serviceLayers);
37
-
38
- if (!layers?.length) {
39
- throw NotFoundError('map layers not found');
40
- }
41
-
42
- if (!layers.filter(el => el.source_path).length) {
43
- throw NotFoundError('map layers sources not provided');
44
- }
45
-
46
- const point = `srid=4326;point(${x} ${y})`; // 30, 50
47
-
48
- const { srids } = await pg.queryCache?.('select json_agg(srid) as srids from spatial_ref_sys').then(el => el.rows?.[0] || {}) || {};
49
-
50
- await Promise.all(layers.map(async (layer, idx) => {
51
- const {
52
- source_path: source, srid = 4326, id: layerId, name,
53
- } = layer;
54
-
55
- const loadTable = await getTemplate('table', source);
56
- const meta = await getMeta({ pg, table: loadTable?.table || source });
57
- const { geom = 'geom' } = meta || {};
58
- const { table = source, columns = meta?.columns } = loadTable || {};
59
-
60
- const cls = columns
61
- ?.filter(el => el.name && el.data)
62
- ?.reduce?.((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
63
- const htmls = columns
64
- ?.filter(el => el.name && el.html)
65
- ?.reduce?.((acc, curr) => ({ ...acc, [curr.name]: curr.html }), {});
66
-
67
- const pk = pg.pk?.[table] || loadTable?.key;
68
-
69
- const { optimizedSQL } = await getFilterSQL({ pg, table: source, query: layer?.query });
70
-
71
- Object.assign(layer, {
72
- layer: (layerId || name || idx.toString())?.replace?.(/'/g, "''"),
73
- table,
74
- pk,
75
- cls,
76
- htmls,
77
- geomColumn: geom,
78
- optimizedSQL,
79
- srid,
80
- step: srids?.includes?.(srid - 0) && srid !== 4326 ? 10 : 0.0002,
81
- });
82
- }));
83
-
84
- const unique = layers
85
- .filter((el, idx, arr) => el.table && arr.map((item) => item.table).indexOf(el.table) === idx);
86
-
87
- const q = unique.map((el) => {
88
- const where = id
89
- ? `${el.pk}::text='${id.replace(/'/g, "''")}'`
90
- : `case
91
- when ST_GeometryType(${el.geomColumn}) in ('ST_Polygon','ST_MultiPolygon')
92
- then st_intersects(${el.geomColumn},st_buffer('${point.replace(/'/g, "''")}',${el.step}))
93
-
94
- when ST_GeometryType(${el.geomColumn}) in ('ST_Line','ST_MultiLineString', 'ST_MultiPoint', 'ST_Point')
95
- then st_distance(${el.geomColumn},'${point.replace(/'/g, "''")}') < ${el.step}
96
- else false
97
- end`;
98
- return `select ${el.pk}::text as pk, '${el.layer}' as layer,
99
- row_to_json(t) as data,
100
- ${id ? 'null' : `st_distance(${el.geomColumn},'${point.replace(/'/g, "''")}')`} as distance,
101
- st_asgeojson(${el.geomColumn})::json as geom from (${el.optimizedSQL}) t
102
- where ${where}`;
103
- }).join(' union all ').concat(' order by distance');
104
-
105
- if (sql === 1) return q;
106
-
107
- const { rows: objects = [] } = await pg.query(q);
108
-
109
- if (!objects.length) {
110
- return `object not found: ${id}`;
111
- }
112
-
113
- const layerData = layers.find((el) => (el.id || el.name) === objects[0].layer) || {};
114
- const rows = objects.slice(0, 1).map(el => ({ ...el.data, data: undefined }));
115
-
116
- const { cls, htmls } = layerData;
117
- await metaFormat({
118
- rows, cls, htmls, sufix: false,
119
- }, pg);
120
-
121
- const resp = {
122
- meta: {
123
- ...layerMetaColumns.reduce((acc, curr) => ({ ...acc, [curr]: layerData[curr] }), {}),
124
- distance: objects[0].distance,
125
- },
126
- data: {
127
- id: rows[0][layerData.pk],
128
- ...rows[0],
129
- },
130
- };
131
-
132
- return resp;
133
- }
1
+ import { BadRequestError, NotFoundError } from '@opengis/fastify-table/errors.js';
2
+ import {
3
+ getMeta, getFilterSQL, getTemplate, metaFormat, pgClients, yml2json,
4
+ } from '@opengis/fastify-table/utils.js';
5
+
6
+ const layerMetaColumns = ['id', 'name', 'label', 'source', 'table', 'pk', 'geomColumn', 'srid', 'cls', 'htmls'];
7
+
8
+ export default async function mapFeaturesPoint({ slug, id, x, y, sql }, pg = pgClients.client) {
9
+ if (!slug) {
10
+ throw BadRequestError('not enough params: slug');
11
+ }
12
+
13
+ if (!(x && y) && !id) {
14
+ throw BadRequestError('not enough params: xy');
15
+ }
16
+
17
+ const loadTemplate = await getTemplate('map', slug);
18
+
19
+ if (!loadTemplate) {
20
+ throw NotFoundError('map not found');
21
+ }
22
+
23
+ const index = loadTemplate?.find?.(el => el[0].split('.').shift() === 'index')?.[1];
24
+
25
+ const layers1 = !index
26
+ ? loadTemplate?.layers
27
+ : loadTemplate?.filter?.(el => el[0].split('.').shift() !== 'index')?.map(el => ({ ...el[1], id: el[0].replace('.yml', '').replace('.json', '') }));
28
+
29
+ const serviceLayers = await Promise.all((layers1 || []).filter(el => typeof el === 'string').map(async (layer) => {
30
+ const layerData = await getTemplate('layer', layer);
31
+ const serviceData = layerData || await pg.query('select service_id as id, *, st_asgeojson(bbox)::json as bbox, st_asgeojson(center)::json as center from gis.services where service_id=$1', [layer]).then(el => el.rows?.[0]);
32
+ serviceData.style = yml2json(serviceData.style);
33
+ return { ...serviceData, id: layer, visible: true };
34
+ }));
35
+
36
+ const layers = (layers1 || []).filter(el => el && typeof el === 'object').concat(serviceLayers);
37
+
38
+ if (!layers?.length) {
39
+ throw NotFoundError('map layers not found');
40
+ }
41
+
42
+ if (!layers.filter(el => el.source_path).length) {
43
+ throw NotFoundError('map layers sources not provided');
44
+ }
45
+
46
+ const point = `srid=4326;point(${x} ${y})`; // 30, 50
47
+
48
+ const { srids } = await pg.queryCache?.('select json_agg(srid) as srids from spatial_ref_sys').then(el => el.rows?.[0] || {}) || {};
49
+
50
+ await Promise.all(layers.map(async (layer, idx) => {
51
+ const {
52
+ source_path: source, srid = 4326, id: layerId, name,
53
+ } = layer;
54
+
55
+ const loadTable = await getTemplate('table', source);
56
+ const meta = await getMeta({ pg, table: loadTable?.table || source });
57
+ const { geom = 'geom' } = meta || {};
58
+ const { table = source, columns = meta?.columns } = loadTable || {};
59
+
60
+ const cls = columns
61
+ ?.filter(el => el.name && el.data)
62
+ ?.reduce?.((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
63
+ const htmls = columns
64
+ ?.filter(el => el.name && el.html)
65
+ ?.reduce?.((acc, curr) => ({ ...acc, [curr.name]: curr.html }), {});
66
+
67
+ const pk = pg.pk?.[table] || loadTable?.key;
68
+
69
+ const { optimizedSQL } = await getFilterSQL({ pg, table: source, query: layer?.query });
70
+
71
+ Object.assign(layer, {
72
+ layer: (layerId || name || idx.toString())?.replace?.(/'/g, "''"),
73
+ table,
74
+ pk,
75
+ cls,
76
+ htmls,
77
+ geomColumn: geom,
78
+ optimizedSQL,
79
+ srid,
80
+ step: srids?.includes?.(srid - 0) && srid !== 4326 ? 10 : 0.0002,
81
+ });
82
+ }));
83
+
84
+ const unique = layers
85
+ .filter((el, idx, arr) => el.table && arr.map((item) => item.table).indexOf(el.table) === idx);
86
+
87
+ const q = unique.map((el) => {
88
+ const where = id
89
+ ? `${el.pk}::text='${id.replace(/'/g, "''")}'`
90
+ : `case
91
+ when ST_GeometryType(${el.geomColumn}) in ('ST_Polygon','ST_MultiPolygon')
92
+ then st_intersects(${el.geomColumn},st_buffer('${point.replace(/'/g, "''")}',${el.step}))
93
+
94
+ when ST_GeometryType(${el.geomColumn}) in ('ST_Line','ST_MultiLineString', 'ST_MultiPoint', 'ST_Point')
95
+ then st_distance(${el.geomColumn},'${point.replace(/'/g, "''")}') < ${el.step}
96
+ else false
97
+ end`;
98
+ return `select ${el.pk}::text as pk, '${el.layer}' as layer,
99
+ row_to_json(t) as data,
100
+ ${id ? 'null' : `st_distance(${el.geomColumn},'${point.replace(/'/g, "''")}')`} as distance,
101
+ st_asgeojson(${el.geomColumn})::json as geom from (${el.optimizedSQL}) t
102
+ where ${where}`;
103
+ }).join(' union all ').concat(' order by distance');
104
+
105
+ if (sql === 1) return q;
106
+
107
+ const { rows: objects = [] } = await pg.query(q);
108
+
109
+ if (!objects.length) {
110
+ return `object not found: ${id}`;
111
+ }
112
+
113
+ const layerData = layers.find((el) => (el.id || el.name) === objects[0].layer) || {};
114
+ const rows = objects.slice(0, 1).map(el => ({ ...el.data, data: undefined }));
115
+
116
+ const { cls, htmls } = layerData;
117
+ await metaFormat({
118
+ rows, cls, htmls, sufix: false,
119
+ }, pg);
120
+
121
+ const resp = {
122
+ meta: {
123
+ ...layerMetaColumns.reduce((acc, curr) => ({ ...acc, [curr]: layerData[curr] }), {}),
124
+ distance: objects[0].distance,
125
+ },
126
+ data: {
127
+ id: rows[0][layerData.pk],
128
+ ...rows[0],
129
+ },
130
+ };
131
+
132
+ return resp;
133
+ }