@opengis/gis 0.2.176 → 0.2.178
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/README.md +181 -181
- package/dist/{CardIcon-c1Q2M3wQ.js → CardIcon-CMRD1LLh.js} +1 -1
- package/dist/{EntityTablePage-B5gpkH4S.js → EntityTablePage-XNNCltAN.js} +2 -2
- package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-DnGSvmMU.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BqUjKTDY.js} +1 -1
- package/dist/{HeaderActions.vue_vue_type_script_setup_true_lang-C2B61JP6.js → HeaderActions.vue_vue_type_script_setup_true_lang-BXQ3hKwa.js} +1 -1
- package/dist/{MapSettings-6-Xru5Q8.js → MapSettings-P3h-vHn3.js} +2 -2
- package/dist/{RastersTablePage-CXNOcTy-.js → RastersTablePage-DnhGZLiH.js} +2 -2
- package/dist/{cartocss-BFVqWvfP.js → cartocss-BkrOeQg4.js} +6 -6
- package/dist/{import-utils-uxk4LdUJ.js → import-utils-BCATsbB5.js} +1 -1
- package/dist/{index-CahlV-Xs.js → index-cUagVqgA.js} +39 -39
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/{raster-CEi56f0P.js → raster-CP0tUp3j.js} +3 -3
- package/dist/{register-NFAGBNa3.js → register-Cr-uQcby.js} +3 -3
- package/dist/{service-BYspag8U.js → service-DwJaKrOd.js} +6 -6
- package/dist/{vs-datatable-CHcBr6zy.js → vs-datatable-B9WoVk-b.js} +2 -2
- package/module/gis/cls/service_type.json +42 -42
- package/module/gis/form/gis.registers.form.json +127 -127
- package/module/test/map/addr.json +302 -302
- package/module/test/map/addr1.yml +23 -23
- package/module/test/select/address.str_id.sql +3 -3
- package/package.json +77 -77
- package/plugin.js +64 -64
- package/server/migrations/array_intersect.sql +13 -13
- package/server/migrations/cartocss.sql +27 -27
- package/server/migrations/group_list.sql +74 -74
- package/server/migrations/maps.sql +30 -30
- package/server/migrations/metadata.sql +415 -415
- package/server/migrations/ogc.sql +106 -106
- package/server/migrations/rasters.sql +265 -265
- package/server/migrations/services.sql +247 -247
- package/server/migrations/services_users_rel.sql +22 -22
- package/server/migrations/widgets.sql +20 -20
- package/server/plugins/crons.js +21 -21
- package/server/plugins/mapnik/funcs/checkRasterFile.js +107 -107
- package/server/plugins/mapnik/funcs/mapnik.js +151 -151
- package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
- package/server/plugins/mapnik/map.proto +437 -437
- package/server/plugins/vite.js +74 -74
- package/server/routes/cartocss/cartocss.route.js +31 -31
- package/server/routes/cartocss/cartocss.route.test.js +78 -78
- package/server/routes/cartocss/cartocss.schema.js +73 -73
- package/server/routes/cartocss/functions/add.cartocss.js +39 -39
- package/server/routes/cartocss/functions/get.cartocss.js +57 -57
- package/server/routes/gis/functions/checkXML.js +107 -107
- package/server/routes/gis/functions/dashboard.js +24 -24
- package/server/routes/gis/gis.route.js +26 -26
- package/server/routes/gis/gis.route.test.js +33 -33
- package/server/routes/map/functions/clearTiles.js +35 -35
- package/server/routes/map/functions/geojson.js +187 -187
- package/server/routes/map/functions/gis.convert.js +65 -65
- package/server/routes/map/functions/gis.icon.js +220 -220
- package/server/routes/map/functions/jsonData.js +206 -206
- package/server/routes/map/functions/layerList.js +102 -102
- package/server/routes/map/functions/map.js +122 -122
- package/server/routes/map/functions/mapCatalog.js +72 -72
- package/server/routes/map/functions/mapCatalogAttribute.js +53 -53
- package/server/routes/map/functions/mapFeatures.js +133 -133
- package/server/routes/map/functions/mapFormat.js +232 -232
- package/server/routes/map/functions/mapTiles.js +162 -162
- package/server/routes/map/functions/maps.js +15 -15
- package/server/routes/map/functions/marker_icon.js +43 -43
- package/server/routes/map/functions/parseGeoFile.js +85 -85
- package/server/routes/map/functions/pointHeight.js +51 -51
- package/server/routes/map/functions/vtile.js +174 -174
- package/server/routes/map/functions/vtile1.js +185 -185
- package/server/routes/map/map.route.js +280 -280
- package/server/routes/map/map.route.test.js +503 -503
- package/server/routes/map/map.schema.js +356 -356
- package/server/routes/map/pin/circle1.svg +76 -76
- package/server/routes/map/pin/circle2.svg +18 -18
- package/server/routes/map/pin/none.svg +12 -12
- package/server/routes/map/pin/pin.svg +14 -14
- package/server/routes/map/pin/pin1.svg +16 -16
- package/server/routes/map/pin/pin2.svg +7 -7
- package/server/routes/map/pin/pin3.svg +34 -34
- package/server/routes/map/pin/pin4.svg +14 -14
- package/server/routes/map/pin/pin5.svg +7 -7
- package/server/routes/map/pin/pin6.svg +12 -12
- package/server/routes/map/pin/pin7.svg +12 -12
- package/server/routes/mapnik/functions/cartoBounds.js +32 -32
- package/server/routes/mapnik/functions/clearTiles.js +103 -103
- package/server/routes/mapnik/functions/convertBoundToTile.js +27 -27
- package/server/routes/mapnik/functions/createXml.js +76 -76
- package/server/routes/mapnik/functions/createXmlMulti.js +72 -72
- package/server/routes/mapnik/functions/fileSearch.js +35 -35
- package/server/routes/mapnik/functions/fileStat.js +28 -28
- package/server/routes/mapnik/functions/pretile.js +138 -138
- package/server/routes/mapnik/functions/rasterInfo.js +66 -66
- package/server/routes/mapnik/functions/readDir.js +22 -22
- package/server/routes/mapnik/functions/rtile.js +164 -164
- package/server/routes/mapnik/functions/uploadRaster.js +152 -152
- package/server/routes/mapnik/functions/uploadXML.js +140 -140
- package/server/routes/mapnik/mapnik.route.js +102 -102
- package/server/routes/mapnik/mapnik.route.test.js +370 -370
- package/server/routes/mapnik/mapnik.schema.mjs +195 -195
- package/server/routes/mapnik.prefixless/functions/mapnikLogger.js +31 -31
- package/server/routes/mapnik.prefixless/functions/mapnikStat.js +21 -21
- package/server/routes/mapnik.prefixless/mapnik.prefixless.route.js +20 -20
- package/server/routes/mapnik.prefixless/mapnik.prefixless.route.test.js +91 -91
- package/server/routes/mapnik.prefixless/mapnik.prefixless.schema.mjs +27 -27
- package/server/routes/maps/functions/add.map.js +42 -42
- package/server/routes/maps/functions/del.map.js +17 -17
- package/server/routes/maps/functions/get.map.js +119 -119
- package/server/routes/maps/maps.route.js +58 -58
- package/server/routes/maps/maps.route.test.js +231 -231
- package/server/routes/maps/maps.schema.js +9 -9
- package/server/routes/metadata/functions/editMetadata.js +35 -35
- package/server/routes/metadata/functions/metadataXML.js +19 -19
- package/server/routes/metadata/metadata.route.js +26 -26
- package/server/routes/metadata/metadata.route.test.js +46 -46
- package/server/routes/metadata/metadata.schema.js +53 -53
- package/server/routes/ogc/functions/map.info.point.js +117 -117
- package/server/routes/ogc/ogc.route.js +21 -21
- package/server/routes/ogc/ogc.route.test.js +53 -53
- package/server/routes/ogc/ogc.schema.js +16 -16
- package/server/routes/permissions/functions/catalog.permissions.edit.js +20 -20
- package/server/routes/permissions/functions/catalog.permissions.js +12 -12
- package/server/routes/permissions/functions/get.permissions.js +59 -59
- package/server/routes/permissions/functions/gis.catalog.js +80 -80
- package/server/routes/permissions/permissions.route.js +35 -35
- package/server/routes/permissions/permissions.route.test.js +35 -35
- package/server/routes/permissions/permissions.schema.js +43 -43
- package/server/routes/registers/functions/add.registry.js +37 -37
- package/server/routes/registers/functions/classifiers.js +100 -100
- package/server/routes/registers/functions/columns.js +3 -3
- package/server/routes/registers/functions/content.type.js +9 -9
- package/server/routes/registers/functions/del.registry.js +14 -14
- package/server/routes/registers/functions/get.info.js +93 -93
- package/server/routes/registers/functions/getFilterSQLParametrized/formatValue.js +312 -0
- package/server/routes/registers/functions/getFilterSQLParametrized/getFilterQuery.js +126 -0
- package/server/routes/registers/functions/getFilterSQLParametrized/getRangeQuery.js +353 -0
- package/server/routes/registers/functions/getFilterSQLParametrized/index.js +81 -0
- package/server/routes/registers/functions/getTableColumnMeta.js +125 -0
- package/server/routes/registers/functions/gis.export.js +159 -159
- package/server/routes/registers/functions/gis.registry.js +71 -71
- package/server/routes/registers/functions/gis.registry.list.js +61 -61
- package/server/routes/registers/functions/gis.suggest.js +275 -0
- package/server/routes/registers/functions/handleRegistryRequest.js +175 -147
- package/server/routes/registers/functions/map.registry.js +87 -87
- package/server/routes/registers/registers.route.js +91 -80
- package/server/routes/registers/registers.route.test.js +173 -144
- package/server/routes/registers/registers.schema.js +275 -246
- package/server/routes/root.mjs +3 -3
- package/server/routes/services/functions/add.service.js +62 -62
- package/server/routes/services/functions/create.route.js +93 -93
- package/server/routes/services/functions/del.service.js +12 -12
- package/server/routes/services/functions/get.layer.geom.js +27 -27
- package/server/routes/services/functions/get.service.users.js +76 -76
- package/server/routes/services/functions/get.services.col.js +34 -34
- package/server/routes/services/functions/get.services.js +89 -89
- package/server/routes/services/functions/legend.auto.js +77 -77
- package/server/routes/services/services.route.js +76 -76
- package/server/routes/services/services.route.test.js +167 -167
- package/server/routes/services/services.schema.js +285 -278
- package/server/routes/widgets/functions/add.widget.js +38 -38
- package/server/routes/widgets/functions/del.widget.js +17 -17
- package/server/routes/widgets/functions/get.widget.js +41 -41
- package/server/routes/widgets/widgets.route.js +61 -61
- package/server/routes/widgets/widgets.route.test.js +144 -144
- package/server/routes/widgets/widgets.schema.js +24 -24
- package/server/shared/listFiles.js +14 -14
- package/utils.js +13 -13
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import { createHash } from 'node:crypto';
|
|
5
|
-
|
|
6
|
-
import { config, getMeta, getTemplate, getTemplateSync, pgClients, getSelect, getSelectVal, getTemplatePath } from '@opengis/fastify-table/utils.js';
|
|
7
|
-
import { NotFoundError } from '@opengis/fastify-table/errors.js';
|
|
8
|
-
|
|
9
|
-
const { prefix = '/api' } = config;
|
|
10
|
-
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
-
|
|
12
|
-
const maps = getTemplatePath('map')?.map?.(el => {
|
|
13
|
-
const { name = el[0] } = getTemplateSync('map', el[0]) || {};
|
|
14
|
-
return { slug: el[0], name };
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
async function processObject(loadTemplate, pg = pgClients.client, unittest = process.env.NODE_ENV === 'test' || process.env.VITEST) {
|
|
18
|
-
// default center for all maps (frontend dependends on it)
|
|
19
|
-
const { bbox = [], center = [30, 50] } = loadTemplate?.source_path && pg.pk?.[loadTemplate.source_path]
|
|
20
|
-
? await pg.query(`select
|
|
21
|
-
array[ST_XMin(env), ST_YMin(env), ST_XMax(env),ST_YMax(env)] as bbox,
|
|
22
|
-
st_asgeojson(st_centroid(env))::json->'coordinates' as center
|
|
23
|
-
from ( select st_extent(geom) as env from ${loadTemplate.source_path} where ${loadTemplate.source_query || '1=1'})q`
|
|
24
|
-
).then(el => el.rows?.[0] || {})
|
|
25
|
-
: {};
|
|
26
|
-
loadTemplate.map = { bbox, center };
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (!loadTemplate?.widgets?.length) return;
|
|
30
|
-
// add legend if not exists in widget
|
|
31
|
-
const idx = loadTemplate.widgets.findIndex(el => el.type === 'attribute_style');
|
|
32
|
-
const { source_path: attrTable, attribute, cls: clsName, legend = [], colors } = loadTemplate.widgets.find(el => el.type === 'attribute_style')?.config || {};
|
|
33
|
-
const colors1 = colors || ['red', 'black', 'blue', 'green', 'orange'];
|
|
34
|
-
|
|
35
|
-
if (!legend?.length && attribute && attrTable) {
|
|
36
|
-
const { columns = {} } = await getMeta({ pg, table: attrTable });
|
|
37
|
-
const { dataTypeID = 0 } = columns.find(item => item.name === attribute) || {};
|
|
38
|
-
const q = pg.pgType?.[dataTypeID]?.includes?.('[]')
|
|
39
|
-
? `select unnest(${attribute})::text as id,count(*) from ${attrTable} group by unnest(${attribute}) limit 100`
|
|
40
|
-
: `select ${attribute}::text as id,count(*) from ${attrTable} group by ${attribute} limit 100`;
|
|
41
|
-
|
|
42
|
-
if (config.trace || unittest) console.log(q);
|
|
43
|
-
const countArr = await pg.queryCache(q, { time: 5 });
|
|
44
|
-
|
|
45
|
-
const ids = countArr.rows.map(item => item.id);
|
|
46
|
-
|
|
47
|
-
const cls = await getSelect(clsName, pg);
|
|
48
|
-
const clsData = await getSelectVal({ pg, values: ids, cls: clsName });
|
|
49
|
-
|
|
50
|
-
const options = countArr.rows.map((cel, idx) => {
|
|
51
|
-
const data = cls?.arr?.find?.(c => c.id?.toString?.() === cel.id?.toString?.()) || { text: clsData?.[cel.id]?.text || clsData?.[cel.id] };
|
|
52
|
-
const color = (colors?.length ? colors1[idx % colors1.length] : null) || data?.color || colors1[idx % colors1.length];
|
|
53
|
-
return { ...cel, ...data, color };
|
|
54
|
-
});
|
|
55
|
-
loadTemplate.widgets[idx].config.legend = options;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const { source_path: table, filters = [] } = loadTemplate.widgets.find(el => el.type === 'filters')?.config || {};
|
|
60
|
-
|
|
61
|
-
filters.forEach(el => Object.assign(el, { name: el.name || el.id }));
|
|
62
|
-
|
|
63
|
-
// md5 hash for suggest security
|
|
64
|
-
filters.filter(el => el.type?.toLowerCase() === 'select').map(async (el) => {
|
|
65
|
-
const hash = createHash('md5').update([table, el.name].join()).digest('hex');
|
|
66
|
-
el.api = `${prefix}/suggest/hash-${hash}`;
|
|
67
|
-
const filepath = path.join(dirname, `../../../../log/suggest/${hash}.json`);
|
|
68
|
-
if (existsSync(filepath)) { return; };
|
|
69
|
-
mkdirSync(path.dirname(filepath), { recursive: true });
|
|
70
|
-
writeFileSync(filepath, JSON.stringify({ table, column: el.name }), { encoding: 'utf8' });
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// add options to filters
|
|
74
|
-
if (filters.filter(el => el.data).length && table) {
|
|
75
|
-
const { columns = {} } = await getMeta({ pg, table });
|
|
76
|
-
await Promise.all(filters.filter(el => el.data && el.name).map(async (el) => {
|
|
77
|
-
const { dataTypeID = 0 } = columns.find(item => item.name === el.name) || {};
|
|
78
|
-
const q = pg.pgType?.[dataTypeID]?.includes?.('[]')
|
|
79
|
-
? `select unnest(${el.name})::text as id,count(*) from ${table} group by unnest(${el.name}) limit 100`
|
|
80
|
-
: `select ${el.name}::text as id,count(*) from ${table} group by ${el.name} limit 100`;
|
|
81
|
-
|
|
82
|
-
if (config.trace || unittest) console.log(q);
|
|
83
|
-
const countArr = await pg.queryCache(q, { time: 5 });
|
|
84
|
-
|
|
85
|
-
const ids = countArr.rows.map(item => item.id);
|
|
86
|
-
|
|
87
|
-
const cls = await getSelect(el.data, pg);
|
|
88
|
-
const clsData = await getSelectVal({ pg, values: ids, name: el.data });
|
|
89
|
-
|
|
90
|
-
const options = countArr.rows.map(cel => {
|
|
91
|
-
const data = cls?.arr?.find?.(c => c.id?.toString?.() === cel.id?.toString?.()) || { text: clsData[cel.id]?.text || clsData[cel.id] };
|
|
92
|
-
return { ...cel, ...data };
|
|
93
|
-
});
|
|
94
|
-
Object.assign(el, { options });
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
return loadTemplate;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export default async function map({ slug }, pg = pgClients.client) {
|
|
101
|
-
const loadTemplate = await getTemplate('map', slug);
|
|
102
|
-
|
|
103
|
-
if (!loadTemplate) {
|
|
104
|
-
throw NotFoundError('map not found');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!Array.isArray(loadTemplate)) {
|
|
108
|
-
await processObject(loadTemplate, pg);
|
|
109
|
-
return { ...loadTemplate, maps };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const index = loadTemplate?.find?.(el => el[0].split('.').shift() === 'index')?.[1];
|
|
113
|
-
|
|
114
|
-
if (!index) {
|
|
115
|
-
throw NotFoundError('map index not found');
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
await processObject(index, pg);
|
|
119
|
-
|
|
120
|
-
const layers = loadTemplate?.filter?.(el => el[0].split('.').shift() !== 'index')?.map(el => ({ ...el[1], id: el[0].replace('.yml', '').replace('.json', '') }));
|
|
121
|
-
|
|
122
|
-
return { ...index, layers, maps };
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
|
|
6
|
+
import { config, getMeta, getTemplate, getTemplateSync, pgClients, getSelect, getSelectVal, getTemplatePath } from '@opengis/fastify-table/utils.js';
|
|
7
|
+
import { NotFoundError } from '@opengis/fastify-table/errors.js';
|
|
8
|
+
|
|
9
|
+
const { prefix = '/api' } = config;
|
|
10
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
|
|
12
|
+
const maps = getTemplatePath('map')?.map?.(el => {
|
|
13
|
+
const { name = el[0] } = getTemplateSync('map', el[0]) || {};
|
|
14
|
+
return { slug: el[0], name };
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
async function processObject(loadTemplate, pg = pgClients.client, unittest = process.env.NODE_ENV === 'test' || process.env.VITEST) {
|
|
18
|
+
// default center for all maps (frontend dependends on it)
|
|
19
|
+
const { bbox = [], center = [30, 50] } = loadTemplate?.source_path && pg.pk?.[loadTemplate.source_path]
|
|
20
|
+
? await pg.query(`select
|
|
21
|
+
array[ST_XMin(env), ST_YMin(env), ST_XMax(env),ST_YMax(env)] as bbox,
|
|
22
|
+
st_asgeojson(st_centroid(env))::json->'coordinates' as center
|
|
23
|
+
from ( select st_extent(geom) as env from ${loadTemplate.source_path} where ${loadTemplate.source_query || '1=1'})q`
|
|
24
|
+
).then(el => el.rows?.[0] || {})
|
|
25
|
+
: {};
|
|
26
|
+
loadTemplate.map = { bbox, center };
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if (!loadTemplate?.widgets?.length) return;
|
|
30
|
+
// add legend if not exists in widget
|
|
31
|
+
const idx = loadTemplate.widgets.findIndex(el => el.type === 'attribute_style');
|
|
32
|
+
const { source_path: attrTable, attribute, cls: clsName, legend = [], colors } = loadTemplate.widgets.find(el => el.type === 'attribute_style')?.config || {};
|
|
33
|
+
const colors1 = colors || ['red', 'black', 'blue', 'green', 'orange'];
|
|
34
|
+
|
|
35
|
+
if (!legend?.length && attribute && attrTable) {
|
|
36
|
+
const { columns = {} } = await getMeta({ pg, table: attrTable });
|
|
37
|
+
const { dataTypeID = 0 } = columns.find(item => item.name === attribute) || {};
|
|
38
|
+
const q = pg.pgType?.[dataTypeID]?.includes?.('[]')
|
|
39
|
+
? `select unnest(${attribute})::text as id,count(*) from ${attrTable} group by unnest(${attribute}) limit 100`
|
|
40
|
+
: `select ${attribute}::text as id,count(*) from ${attrTable} group by ${attribute} limit 100`;
|
|
41
|
+
|
|
42
|
+
if (config.trace || unittest) console.log(q);
|
|
43
|
+
const countArr = await pg.queryCache(q, { time: 5 });
|
|
44
|
+
|
|
45
|
+
const ids = countArr.rows.map(item => item.id);
|
|
46
|
+
|
|
47
|
+
const cls = await getSelect(clsName, pg);
|
|
48
|
+
const clsData = await getSelectVal({ pg, values: ids, cls: clsName });
|
|
49
|
+
|
|
50
|
+
const options = countArr.rows.map((cel, idx) => {
|
|
51
|
+
const data = cls?.arr?.find?.(c => c.id?.toString?.() === cel.id?.toString?.()) || { text: clsData?.[cel.id]?.text || clsData?.[cel.id] };
|
|
52
|
+
const color = (colors?.length ? colors1[idx % colors1.length] : null) || data?.color || colors1[idx % colors1.length];
|
|
53
|
+
return { ...cel, ...data, color };
|
|
54
|
+
});
|
|
55
|
+
loadTemplate.widgets[idx].config.legend = options;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const { source_path: table, filters = [] } = loadTemplate.widgets.find(el => el.type === 'filters')?.config || {};
|
|
60
|
+
|
|
61
|
+
filters.forEach(el => Object.assign(el, { name: el.name || el.id }));
|
|
62
|
+
|
|
63
|
+
// md5 hash for suggest security
|
|
64
|
+
filters.filter(el => el.type?.toLowerCase() === 'select').map(async (el) => {
|
|
65
|
+
const hash = createHash('md5').update([table, el.name].join()).digest('hex');
|
|
66
|
+
el.api = `${prefix}/suggest/hash-${hash}`;
|
|
67
|
+
const filepath = path.join(dirname, `../../../../log/suggest/${hash}.json`);
|
|
68
|
+
if (existsSync(filepath)) { return; };
|
|
69
|
+
mkdirSync(path.dirname(filepath), { recursive: true });
|
|
70
|
+
writeFileSync(filepath, JSON.stringify({ table, column: el.name }), { encoding: 'utf8' });
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// add options to filters
|
|
74
|
+
if (filters.filter(el => el.data).length && table) {
|
|
75
|
+
const { columns = {} } = await getMeta({ pg, table });
|
|
76
|
+
await Promise.all(filters.filter(el => el.data && el.name).map(async (el) => {
|
|
77
|
+
const { dataTypeID = 0 } = columns.find(item => item.name === el.name) || {};
|
|
78
|
+
const q = pg.pgType?.[dataTypeID]?.includes?.('[]')
|
|
79
|
+
? `select unnest(${el.name})::text as id,count(*) from ${table} group by unnest(${el.name}) limit 100`
|
|
80
|
+
: `select ${el.name}::text as id,count(*) from ${table} group by ${el.name} limit 100`;
|
|
81
|
+
|
|
82
|
+
if (config.trace || unittest) console.log(q);
|
|
83
|
+
const countArr = await pg.queryCache(q, { time: 5 });
|
|
84
|
+
|
|
85
|
+
const ids = countArr.rows.map(item => item.id);
|
|
86
|
+
|
|
87
|
+
const cls = await getSelect(el.data, pg);
|
|
88
|
+
const clsData = await getSelectVal({ pg, values: ids, name: el.data });
|
|
89
|
+
|
|
90
|
+
const options = countArr.rows.map(cel => {
|
|
91
|
+
const data = cls?.arr?.find?.(c => c.id?.toString?.() === cel.id?.toString?.()) || { text: clsData[cel.id]?.text || clsData[cel.id] };
|
|
92
|
+
return { ...cel, ...data };
|
|
93
|
+
});
|
|
94
|
+
Object.assign(el, { options });
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
return loadTemplate;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default async function map({ slug }, pg = pgClients.client) {
|
|
101
|
+
const loadTemplate = await getTemplate('map', slug);
|
|
102
|
+
|
|
103
|
+
if (!loadTemplate) {
|
|
104
|
+
throw NotFoundError('map not found');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!Array.isArray(loadTemplate)) {
|
|
108
|
+
await processObject(loadTemplate, pg);
|
|
109
|
+
return { ...loadTemplate, maps };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const index = loadTemplate?.find?.(el => el[0].split('.').shift() === 'index')?.[1];
|
|
113
|
+
|
|
114
|
+
if (!index) {
|
|
115
|
+
throw NotFoundError('map index not found');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
await processObject(index, pg);
|
|
119
|
+
|
|
120
|
+
const layers = loadTemplate?.filter?.(el => el[0].split('.').shift() !== 'index')?.map(el => ({ ...el[1], id: el[0].replace('.yml', '').replace('.json', '') }));
|
|
121
|
+
|
|
122
|
+
return { ...index, layers, maps };
|
|
123
123
|
}
|
|
@@ -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
|
}
|