@opengis/gis 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -9
- package/module/gis/card/gis.maps.table/index.yml +0 -11
- package/module/gis/card/gis.maps.table/main_info.hbs +0 -25
- package/module/gis/card/gis.maps.table/maps_layers.hbs +0 -19
- package/module/gis/card/gis.metadata.table/index.yml +0 -19
- package/module/gis/card/gis.metadata.table/main_info.hbs +0 -21
- package/module/gis/card/gis.metadata.table/metadata_info.hbs +0 -28
- package/module/gis/card/gis.metadata.table/other.hbs +0 -26
- package/module/gis/card/gis.rasters.table/index.yml +0 -8
- package/module/gis/card/gis.rasters.table/main_info.hbs +0 -27
- package/module/gis/card/gis.registers.table/cls.hbs +0 -36
- package/module/gis/card/gis.registers.table/columns.hbs +0 -83
- package/module/gis/card/gis.registers.table/filters.hbs +0 -80
- package/module/gis/card/gis.registers.table/index.yml +0 -21
- package/module/gis/card/gis.registers.table/main_info.hbs +0 -35
- package/module/gis/card/gis.registers.table/source.hbs +0 -45
- package/module/gis/card/gis.services.table/attributes.hbs +0 -85
- package/module/gis/card/gis.services.table/filters.hbs +0 -83
- package/module/gis/card/gis.services.table/index.yml +0 -20
- package/module/gis/card/gis.services.table/main_info.hbs +0 -27
- package/module/gis/card/gis.services.table/source.hbs +0 -25
- package/module/gis/cls/bool.yes_no.json +0 -12
- package/module/gis/cls/encoding.json +0 -14
- package/module/gis/cls/geom_type.json +0 -14
- package/module/gis/cls/gis.column_type.json +0 -34
- package/module/gis/cls/gis.column_view_type.json +0 -18
- package/module/gis/cls/gis.filter_type.json +0 -22
- package/module/gis/cls/language.json +0 -10
- package/module/gis/cls/meta.service_type.json +0 -43
- package/module/gis/cls/ogc.service.json +0 -22
- package/module/gis/cls/service_type.json +0 -42
- package/module/gis/cls/source_type.json +0 -10
- package/module/gis/cls/standarts.json +0 -6
- package/module/gis/cls/topic_category.json +0 -107
- package/module/gis/cls/update_frequency.json +0 -30
- package/module/gis/form/gis.group_list.form.json +0 -17
- package/module/gis/form/gis.maps.form.json +0 -67
- package/module/gis/form/gis.metadata.form.json +0 -240
- package/module/gis/form/gis.ogc_service.form.json +0 -36
- package/module/gis/form/gis.rasters.form.json +0 -100
- package/module/gis/form/gis.registers.form.json +0 -264
- package/module/gis/form/gis.registers_column.form.json +0 -77
- package/module/gis/form/gis.registers_filter.form.json +0 -65
- package/module/gis/form/gis.services.form.json +0 -300
- package/module/gis/form/gis.services_attributes.form.json +0 -68
- package/module/gis/form/gis.services_filter.form.json +0 -65
- package/module/gis/menu.json +0 -43
- package/module/gis/select/gis.group_list.sql +0 -1
- package/module/gis/select/pg.columns.parent.sql +0 -6
- package/module/gis/select/pg.table_name.sql +0 -17
- package/module/gis/select/service_id.sql +0 -1
- package/module/gis/table/gis.maps.table.json +0 -78
- package/module/gis/table/gis.metadata.table.json +0 -71
- package/module/gis/table/gis.ogc_service.table.json +0 -81
- package/module/gis/table/gis.rasters.table.json +0 -98
- package/module/gis/table/gis.registers.table.json +0 -79
- package/module/gis/table/gis.services.table.json +0 -105
- package/module/gis/table/site.gis.registers.table.json +0 -75
- package/module/gis/table/site.gis.services.table.json +0 -104
- package/module/gis/templates/ISO19136_2017_gml_template.xml +0 -331
- package/module/gis/tokens.yml +0 -5
- package/plugin.js +0 -12
- package/server/plugins/mapnik/funcs/createXML.js +0 -72
- package/server/plugins/mapnik/funcs/gdalWrapper.js +0 -72
- package/server/plugins/mapnik/funcs/mapnik.js +0 -101
- package/server/plugins/mapnik/funcs/rasterConfig.js +0 -11
- package/server/plugins/mapnik/funcs/rasterExists.js +0 -21
- package/server/plugins/mapnik/funcs/rasterInfo.js +0 -109
- package/server/plugins/mapnik/funcs/rasterVrt.js +0 -56
- package/server/plugins/mapnik/funcs/rasterXML.js +0 -65
- package/server/plugins/mapnik/funcs/rootFolder.mjs +0 -8
- package/server/plugins/mapnik/index.mjs +0 -12
- package/server/plugins/mapnik/utils/map.proto +0 -241
- package/server/routes/gis/index.mjs +0 -19
- package/server/routes/gis/metadata/metadataXML.js +0 -13
- package/server/routes/gis/registers/funcs/classifiers.js +0 -26
- package/server/routes/gis/registers/funcs/columns.js +0 -5
- package/server/routes/gis/registers/funcs/handleRegistryRequest.js +0 -100
- package/server/routes/gis/registers/gis.registry.js +0 -32
- package/server/routes/gis/registers/gis.registry.list.js +0 -59
- package/server/routes/gis/registers/insert.columns.js +0 -107
- package/server/routes/gis/registers/insert.filters.js +0 -110
- package/server/routes/gis/registers/map.registry.js +0 -79
- package/server/routes/gis/services/get.layer.geom.js +0 -27
- package/server/routes/map/controllers/map.js +0 -123
- package/server/routes/map/controllers/mapCatalog.js +0 -55
- package/server/routes/map/controllers/mapCatalogAttribute.js +0 -56
- package/server/routes/map/controllers/mapFeatures.js +0 -120
- package/server/routes/map/controllers/mapFormat.js +0 -111
- package/server/routes/map/controllers/mapTiles.js +0 -148
- package/server/routes/map/controllers/maps.js +0 -16
- package/server/routes/map/controllers/marker_icon.js +0 -42
- package/server/routes/map/controllers/rtile.js +0 -133
- package/server/routes/map/controllers/vtile.js +0 -146
- package/server/routes/map/index.mjs +0 -51
- package/server/routes/root.mjs +0 -3
- package/utils.js +0 -9
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { config, getMeta, getFilterSQL, getTemplate, metaFormat, pgClients } from '@opengis/fastify-table/utils.js';
|
|
2
|
-
|
|
3
|
-
const layerMetaColumns = ['id', 'name', 'label', 'source', 'table', 'pk', 'geomColumn', 'srid', 'cls', 'htmls'];
|
|
4
|
-
|
|
5
|
-
export default async function mapFeaturesPoint({ pg = pgClients.client, params = {}, query = {} }, reply) {
|
|
6
|
-
const { slug, id } = params;
|
|
7
|
-
const { x, y, sql } = query;
|
|
8
|
-
|
|
9
|
-
if (!slug) {
|
|
10
|
-
return reply.status(400).send('not enough params: slug');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (!(x && y) && !id) {
|
|
14
|
-
return reply.status(400).send('not enough params: xy');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const loadTemplate = await getTemplate('map', slug);
|
|
18
|
-
|
|
19
|
-
if (!loadTemplate) {
|
|
20
|
-
return reply.status(404).send('map not found');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const index = loadTemplate?.find?.(el => el[0].split('.').shift() === 'index')?.[1];
|
|
24
|
-
|
|
25
|
-
const layers = !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
|
-
if (!layers?.length) {
|
|
30
|
-
return reply.status(404).send('map layers not found');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!layers.filter(el => el.source_path).length) {
|
|
34
|
-
return reply.status(404).send('map layers sources not provided');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const point = `srid=4326;point(${x} ${y})`; // 30, 50
|
|
38
|
-
|
|
39
|
-
const { srids } = await pg.queryCache?.('select json_agg(srid) as srids from spatial_ref_sys').then(el => el.rows?.[0] || {}) || {};
|
|
40
|
-
|
|
41
|
-
await Promise.all(layers.map(async (layer, idx) => {
|
|
42
|
-
const { source_path: source, srid = 4326, id: layerId, name } = layer;
|
|
43
|
-
|
|
44
|
-
const loadTable = await getTemplate('table', source);
|
|
45
|
-
const meta = await getMeta({ pg, table: loadTable?.table || source });
|
|
46
|
-
const { geom = 'geom' } = meta || {};
|
|
47
|
-
const { table = source, columns = meta?.columns } = loadTable || {};
|
|
48
|
-
|
|
49
|
-
const cls = columns
|
|
50
|
-
?.filter(el => el.name && el.data)
|
|
51
|
-
?.reduce?.((acc, curr) => ({ ...acc, [curr.name]: curr.data }), {});
|
|
52
|
-
const htmls = columns
|
|
53
|
-
?.filter(el => el.name && el.html)
|
|
54
|
-
?.reduce?.((acc, curr) => ({ ...acc, [curr.name]: curr.html }), {});
|
|
55
|
-
|
|
56
|
-
const pk = pg.pk?.[table] || loadTable?.key;
|
|
57
|
-
|
|
58
|
-
const { optimizedSQL } = await getFilterSQL({ pg, table: source, query: layer?.query });
|
|
59
|
-
|
|
60
|
-
Object.assign(layer, {
|
|
61
|
-
layer: (layerId || name || idx.toString())?.replace?.(/'/g, "''"),
|
|
62
|
-
table,
|
|
63
|
-
pk,
|
|
64
|
-
cls,
|
|
65
|
-
htmls,
|
|
66
|
-
geomColumn: geom,
|
|
67
|
-
optimizedSQL,
|
|
68
|
-
srid,
|
|
69
|
-
step: srids?.includes?.(srid - 0) && srid !== 4326 ? 10 : 0.0002,
|
|
70
|
-
});
|
|
71
|
-
}));
|
|
72
|
-
|
|
73
|
-
const unique = layers
|
|
74
|
-
.filter((el, idx, arr) => el.table && arr.map((item) => item.table).indexOf(el.table) === idx);
|
|
75
|
-
|
|
76
|
-
const q = unique.map((el) => {
|
|
77
|
-
const where = id
|
|
78
|
-
? `${el.pk}::text='${id.replace(/'/g, "''")}'`
|
|
79
|
-
: `case
|
|
80
|
-
when ST_GeometryType(${el.geomColumn}) in ('ST_Polygon','ST_MultiPolygon')
|
|
81
|
-
then st_intersects(${el.geomColumn},st_buffer('${point.replace(/'/g, "''")}',${el.step}))
|
|
82
|
-
|
|
83
|
-
when ST_GeometryType(${el.geomColumn}) in ('ST_Line','ST_MultiLineString', 'ST_MultiPoint', 'ST_Point')
|
|
84
|
-
then st_distance(${el.geomColumn},'${point.replace(/'/g, "''")}') < ${el.step}
|
|
85
|
-
else false
|
|
86
|
-
end`;
|
|
87
|
-
return `select ${el.pk}::text as pk, '${el.layer}' as layer,
|
|
88
|
-
row_to_json(t) as data,
|
|
89
|
-
${id ? 'null' : `st_distance(${el.geomColumn},'${point.replace(/'/g, "''")}')`} as distance,
|
|
90
|
-
st_asgeojson(${el.geomColumn})::json as geom from (${el.optimizedSQL}) t
|
|
91
|
-
where ${where}`;
|
|
92
|
-
}).join(' union all ').concat(' order by distance');
|
|
93
|
-
|
|
94
|
-
if (sql === '1') return q;
|
|
95
|
-
|
|
96
|
-
const { rows: objects = [] } = await pg.query(q);
|
|
97
|
-
|
|
98
|
-
if (!objects.length) {
|
|
99
|
-
return reply.status(200).send(`object not found: ${id}`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const layerData = layers.find((el) => (el.id || el.name) === objects[0].layer) || {};
|
|
103
|
-
const rows = objects.slice(0, 1).map(el => ({ ...el.data, data: undefined }));
|
|
104
|
-
|
|
105
|
-
const { cls, htmls } = layerData;
|
|
106
|
-
await metaFormat({ rows, cls, htmls, sufix: false }, pg);
|
|
107
|
-
|
|
108
|
-
const resp = {
|
|
109
|
-
meta: {
|
|
110
|
-
...layerMetaColumns.reduce((acc, curr) => ({ ...acc, [curr]: layerData[curr] }), {}),
|
|
111
|
-
distance: objects[0].distance,
|
|
112
|
-
},
|
|
113
|
-
data: {
|
|
114
|
-
id: rows[0][layerData.pk],
|
|
115
|
-
...rows[0],
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
return reply.status(200).send(resp);
|
|
120
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { pgClients, getTemplate } from "@opengis/fastify-table/utils.js";
|
|
2
|
-
import { attachClassifiers } from '../../gis/registers/funcs/classifiers.js';
|
|
3
|
-
import formatDate from '@opengis/fastify-table/server/helpers/format/formatDate.js';
|
|
4
|
-
|
|
5
|
-
const pg = pgClients.client;
|
|
6
|
-
|
|
7
|
-
export default async function mapFormat(req, reply) {
|
|
8
|
-
const { query } = req;
|
|
9
|
-
const { layer, id, map } = query;
|
|
10
|
-
const time = Date.now();
|
|
11
|
-
|
|
12
|
-
if (!layer || !id) return reply.status(404).send('not enough params: layer,id,map is required');
|
|
13
|
-
|
|
14
|
-
let service = null;
|
|
15
|
-
|
|
16
|
-
if (map) {
|
|
17
|
-
const {
|
|
18
|
-
rows: [mapLayer],
|
|
19
|
-
} = await pg.query(
|
|
20
|
-
`select s.*
|
|
21
|
-
from gis.maps_layers ml
|
|
22
|
-
join gis.services s on s.service_id = ml.service_id
|
|
23
|
-
join gis.maps m on m.map_id = ml.map_id
|
|
24
|
-
where m.map_key = $1 and s.service_key = $2`,
|
|
25
|
-
[map, layer]
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
if (mapLayer) {
|
|
29
|
-
service = mapLayer;
|
|
30
|
-
}
|
|
31
|
-
} else {
|
|
32
|
-
const {
|
|
33
|
-
rows: [s],
|
|
34
|
-
} = await pg.query(`SELECT * FROM gis.services WHERE service_id = $1`, [layer]);
|
|
35
|
-
|
|
36
|
-
if (s) {
|
|
37
|
-
service = s;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let source_path, attributes, tpl;
|
|
42
|
-
if (service) {
|
|
43
|
-
({ source_path, attributes } = service);
|
|
44
|
-
} else {
|
|
45
|
-
// git
|
|
46
|
-
tpl = await getTemplate('map', map);
|
|
47
|
-
const matchedLayer = tpl?.layers?.find(l => l.id === layer || l.service === layer);
|
|
48
|
-
if (!matchedLayer || !matchedLayer.source_path || !matchedLayer.card) {
|
|
49
|
-
return reply.status(404).send('template not found');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
source_path = matchedLayer.source_path;
|
|
53
|
-
attributes = matchedLayer.card;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const columns = attributes;
|
|
57
|
-
if (!source_path) return reply.status(404).send('missing source_path');
|
|
58
|
-
|
|
59
|
-
const pk = pg.pk?.[source_path];
|
|
60
|
-
if (!pk) return reply.status(404).send('missing pk');
|
|
61
|
-
|
|
62
|
-
if (!columns) return reply.status(404).send('columns setting not found');
|
|
63
|
-
|
|
64
|
-
const columnNames = columns.map(col => col.name);
|
|
65
|
-
const excluded = ["created_by", "created_at", "updated_by", "geom", "id", "uid", "updated_at", "cdate", "editor_date", "editor_id"];
|
|
66
|
-
const filteredColumns = columnNames.filter(name => !excluded.includes(name));
|
|
67
|
-
|
|
68
|
-
const {
|
|
69
|
-
rows: [row]
|
|
70
|
-
} = await pg.query(
|
|
71
|
-
`SELECT ${pk} as "id", geom::json, ${filteredColumns.map(n => `"${n}"`).join(", ")} FROM ${source_path} WHERE ${pk} = $1`,
|
|
72
|
-
[id]
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
if (!row) return reply.status(404).send('object not found');
|
|
76
|
-
|
|
77
|
-
const classifiers = columns
|
|
78
|
-
.filter(col => col.data && ["select", "badge", "tags"].includes(col.format))
|
|
79
|
-
.map(col => ({ name: col.name, classifier: col.data }));
|
|
80
|
-
|
|
81
|
-
const fullRow = await attachClassifiers(row, classifiers);
|
|
82
|
-
const result = [];
|
|
83
|
-
for (const col of columns) {
|
|
84
|
-
if (excluded.includes(col.name)) continue;
|
|
85
|
-
if (col.hidden_card === true) continue;
|
|
86
|
-
|
|
87
|
-
const name = col.ua || col.name;
|
|
88
|
-
let value;
|
|
89
|
-
value = fullRow[`${col.name}_data`]?.text
|
|
90
|
-
|| fullRow[`${col.name}_text`]
|
|
91
|
-
|| fullRow[col.name]
|
|
92
|
-
|| '-';
|
|
93
|
-
|
|
94
|
-
if (col.format === 'date' && fullRow[col.name]) { value = formatDate(fullRow[col.name], { hash: { format: 'dd.mm.yy' } }); }
|
|
95
|
-
|
|
96
|
-
result.push(`<div class="grid grid-cols-1 gap-1 py-3 sm:grid-cols-3 sm:gap-4 even:bg-gray-50 text-[12px]">
|
|
97
|
-
<dt class="text-gray-900">${name}</dt>
|
|
98
|
-
<dd class="text-gray-700 sm:col-span-2">${value}</dd>
|
|
99
|
-
</div>`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const html = `<dl class="divide-y divide-gray-100 py-[5px]">${result.join('')}</dl>`;
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
time: Date.now() - time,
|
|
106
|
-
id,
|
|
107
|
-
rows: fullRow,
|
|
108
|
-
columns,
|
|
109
|
-
html
|
|
110
|
-
};
|
|
111
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { createHash } from 'node:crypto';
|
|
4
|
-
import { readFile, stat, mkdir, writeFile } from 'node:fs/promises';
|
|
5
|
-
|
|
6
|
-
import Sphericalmercator from '@mapbox/sphericalmercator';
|
|
7
|
-
|
|
8
|
-
import { getTemplate, pgClients, getFilterSQL, getMeta } from '@opengis/fastify-table/utils.js';
|
|
9
|
-
|
|
10
|
-
import rootFolder from '../../../plugins/mapnik/funcs/rootFolder.mjs';
|
|
11
|
-
|
|
12
|
-
const limit = 3000;
|
|
13
|
-
const mercator = new Sphericalmercator({ size: 256 });
|
|
14
|
-
const types = { point: 'ST_Point', polygon: 'ST_Polygon,ST_MultiPolygon' };
|
|
15
|
-
const systemColumns = ['uid', 'cdate', 'editor_id', 'editor_date', 'created_by', 'created_at', 'updated_by', 'updated_at'];
|
|
16
|
-
|
|
17
|
-
export default async function mapTiles({ pg = pgClients.client, params = {}, query = {}, unittest }, reply) {
|
|
18
|
-
const { slug, y, z } = params;
|
|
19
|
-
const { sql, nocache, filter, pointZoom, type, layers } = query;
|
|
20
|
-
const x = params.x?.split?.('.')?.[0] - 0;
|
|
21
|
-
|
|
22
|
-
if (!slug) {
|
|
23
|
-
return reply.status(400).send('not enough params: slug');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!x || !y || !z) {
|
|
27
|
-
return reply.status(400).send('not enough params: xyz');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const bbox = mercator.bbox(+y, +x, +z, false);
|
|
31
|
-
const bbox2d = `'BOX(${bbox[0]} ${bbox[1]},${bbox[2]} ${bbox[3]})'::box2d`;
|
|
32
|
-
|
|
33
|
-
const headers = {
|
|
34
|
-
'Content-Type': 'application/x-protobuf',
|
|
35
|
-
'Cache-Control': nocache || sql ? 'no-cache' : 'public, max-age=86400',
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const hash = [filter].filter((el) => el).join();
|
|
39
|
-
|
|
40
|
-
const filepath = path.join(
|
|
41
|
-
rootFolder,
|
|
42
|
-
`/map/vtile/${slug}/${hash ? `${createHash('md5').update(hash).digest('hex')}/` : ''}${z}/${x}/${y}.pbf`
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (existsSync(filepath) && z < 13 && !nocache && !sql && !unittest) {
|
|
46
|
-
const { birthtimeMs = Date.now() } = await stat(filepath);
|
|
47
|
-
const ageInMs = Date.now() - birthtimeMs;
|
|
48
|
-
if (ageInMs < 86400000) {
|
|
49
|
-
const buffer = await readFile(filepath);
|
|
50
|
-
return reply.status(200).headers(headers).send(buffer);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const loadTemplate = await getTemplate('map', slug);
|
|
55
|
-
|
|
56
|
-
if (!loadTemplate) {
|
|
57
|
-
return reply.status(404).send('map not found');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const index = loadTemplate?.find?.(el => el[0].split('.').shift() === 'index')?.[1];
|
|
61
|
-
|
|
62
|
-
const layers1 = !index
|
|
63
|
-
? loadTemplate?.layers
|
|
64
|
-
: loadTemplate?.filter?.(el => el[0].split('.').shift() !== 'index')?.map(el => ({ ...el[1], id: el[0].replace('.yml', '').replace('.json', '') }));
|
|
65
|
-
|
|
66
|
-
if (!layers1?.length) {
|
|
67
|
-
return reply.status(404).send('map layers not found');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!layers1.filter(el => el.source_path).length) {
|
|
71
|
-
return reply.status(404).send('map layers sources not provided');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
layers1.forEach(el => Object.assign(el, { name: el.name || el.id }));
|
|
75
|
-
|
|
76
|
-
const q = (await Promise.all(layers1.filter(el => el.name && el.source_path).filter(el => layers ? layers.includes(el.name) : true).map(async (layer) => {
|
|
77
|
-
const { source_path: source, id, name, style, geometry_type: gt, query: lquery, geometry_column: gCol } = layer;
|
|
78
|
-
const loadTable = await getTemplate('table', source);
|
|
79
|
-
|
|
80
|
-
const table = loadTable?.table || source;
|
|
81
|
-
const meta = await getMeta({ pg, table });
|
|
82
|
-
const { columns = [] } = meta || {};
|
|
83
|
-
const geom = gCol || meta?.geom || 'geom';
|
|
84
|
-
if (!columns?.length) return null;
|
|
85
|
-
|
|
86
|
-
const pk = pg.pk?.[table] || loadTable?.key;
|
|
87
|
-
const fData = filter ? await getFilterSQL({ pg, table: source, filter }) : {};
|
|
88
|
-
|
|
89
|
-
const geomCol = parseInt(z, 10) < parseInt(pointZoom || '0', 10) || (style?.centroid && gt === 'point')
|
|
90
|
-
? `ST_Centroid(${geom})`
|
|
91
|
-
: geom;
|
|
92
|
-
|
|
93
|
-
const columnsFiltered = columns
|
|
94
|
-
.filter(el => !['json', 'geometry'].includes(pg.pgType?.[el.dataTypeID]) && !systemColumns.includes(el.name));
|
|
95
|
-
|
|
96
|
-
const props = columnsFiltered.map(el => {
|
|
97
|
-
return el.type?.[0] === '_'
|
|
98
|
-
? `${el.name}[1] as ${el.name}`
|
|
99
|
-
: `${el.name}${['int4'].includes(el.type) ? '::text' : ''}`;
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
return `SELECT ST_AsMVT(q, '${(id || name).replace(/'/g, "''")}', 4096, 'geom','row') as tile
|
|
103
|
-
FROM (
|
|
104
|
-
SELECT /*substr(${pk},12)::int*/ /*${(y - 0 + x) * 10000} + row_number() over()*/
|
|
105
|
-
|
|
106
|
-
row_number() over() as row,
|
|
107
|
-
|
|
108
|
-
${style?.colorAttr ? `${style.colorAttr},` : ''} ${props?.length ? `${props.map(el => `"${el}"`).join(',')},` : ''}
|
|
109
|
-
|
|
110
|
-
${pk} as id,
|
|
111
|
-
ST_AsMVTGeom(st_transform(${geomCol},3857),ST_TileEnvelope(${z},${y},${x})::box2d,4096,256,true) geom
|
|
112
|
-
|
|
113
|
-
FROM (select * from ${table} where ${loadTable?.query || '1=1'} and ${fData?.q || 'true'} and ${geom} && ${bbox2d}
|
|
114
|
-
|
|
115
|
-
and ${geom} is not null and st_srid(${geom}) >0
|
|
116
|
-
|
|
117
|
-
${types[type] ? ` and ST_GeometryType(${geom}) = any ('{ ${types[type]} }') ` : ''}
|
|
118
|
-
|
|
119
|
-
and ${lquery || '1=1'}
|
|
120
|
-
|
|
121
|
-
${gt === 'polygon' ? `order by st_area(st_transform(${geom},3857)) desc` : ''}
|
|
122
|
-
|
|
123
|
-
limit ${limit})q
|
|
124
|
-
) q`;
|
|
125
|
-
}))).filter(el => el).join(' union all ');
|
|
126
|
-
|
|
127
|
-
if (sql === '1') return q;
|
|
128
|
-
if (sql === '2') return filepath.replace(/\\/g, '/');
|
|
129
|
-
|
|
130
|
-
const tile = await pg.query(q);
|
|
131
|
-
|
|
132
|
-
if (unittest && !tile.rows?.length) {
|
|
133
|
-
console.log(slug, q);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (sql === '3') return tile.rows.map((el) => el.tile);
|
|
137
|
-
|
|
138
|
-
if (sql === '4') return tile.rows.map((el) => el.tile);
|
|
139
|
-
|
|
140
|
-
const buffer = Buffer.concat(tile.rows.map((el) => Buffer.from(el.tile)));
|
|
141
|
-
|
|
142
|
-
if (!nocache) {
|
|
143
|
-
await mkdir(path.dirname(filepath), { recursive: true });
|
|
144
|
-
await writeFile(filepath, buffer, 'binary');
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return reply.status(200).headers(headers).send(buffer);
|
|
148
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { getTemplatePath, getTemplateSync } from "@opengis/fastify-table/utils.js";
|
|
2
|
-
|
|
3
|
-
const arr = getTemplatePath('map') || [];
|
|
4
|
-
|
|
5
|
-
const list = arr.map(el => {
|
|
6
|
-
const { name = el[0] } = getTemplateSync('map', el[0]);
|
|
7
|
-
return { name, slug: el[0] };
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
export default async function mapList(req, reply) {
|
|
11
|
-
if (!arr.length) {
|
|
12
|
-
return reply.status(200).send([]);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return reply.status(200).send(list);
|
|
16
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
|
|
5
|
-
async function downloadImage(url, file) {
|
|
6
|
-
const resp = await fetch(url);
|
|
7
|
-
if (resp.status !== 200) throw new Error(`${url} - not found`);
|
|
8
|
-
const blob = await resp.blob();
|
|
9
|
-
|
|
10
|
-
const arrayBuffer = await blob.arrayBuffer();
|
|
11
|
-
|
|
12
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
13
|
-
|
|
14
|
-
fs.writeFileSync(file, buffer);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const filename = fileURLToPath(import.meta.url);
|
|
18
|
-
const dirname = path.dirname(filename);
|
|
19
|
-
|
|
20
|
-
const fileIconDir = path.join(dirname, '../../../../log/marker-icon');
|
|
21
|
-
|
|
22
|
-
fs.mkdirSync(fileIconDir, { recursive: true });
|
|
23
|
-
|
|
24
|
-
export default async function markerIconApi(req, reply) {
|
|
25
|
-
const { params = {} } = req;
|
|
26
|
-
params.data = params['*'];
|
|
27
|
-
if (!params.data) {
|
|
28
|
-
return reply.status(400).send('not enough params: data');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const iconPath = path.join(fileIconDir, params?.data);
|
|
32
|
-
|
|
33
|
-
if (fs.existsSync(iconPath)) {
|
|
34
|
-
return fs.createReadStream(iconPath);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
await downloadImage(`https://data.softpro.ua/api-user/marker/${params.data}`, iconPath).catch(err => {
|
|
38
|
-
return reply.status(404).send('icon not found');
|
|
39
|
-
});
|
|
40
|
-
return fs.createReadStream(iconPath);
|
|
41
|
-
|
|
42
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import Sphericalmercator from '@mapbox/sphericalmercator';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
4
|
-
import { mkdir, writeFile, readFile } from 'node:fs/promises';
|
|
5
|
-
|
|
6
|
-
import { config, logger, pgClients } from '@opengis/fastify-table/utils.js';
|
|
7
|
-
|
|
8
|
-
import rootFolder from '../../../plugins/mapnik/funcs/rootFolder.mjs';
|
|
9
|
-
import rasterXML from '../../../plugins/mapnik/funcs/rasterXML.js';
|
|
10
|
-
import mapnik from '../../../plugins/mapnik/funcs/mapnik.js';
|
|
11
|
-
|
|
12
|
-
const { render, loadXML } = mapnik();
|
|
13
|
-
|
|
14
|
-
const mercator = new Sphericalmercator({ size: 256 });
|
|
15
|
-
|
|
16
|
-
const loaded = {};
|
|
17
|
-
const autoGenerate = {};
|
|
18
|
-
/**
|
|
19
|
-
* Формування растрового tile cartoCss
|
|
20
|
-
*
|
|
21
|
-
* @method GET
|
|
22
|
-
* @alias rtile
|
|
23
|
-
* @param {String} bbox - bbox
|
|
24
|
-
* @param {Number} height - висота по координатам
|
|
25
|
-
* @param {Number} width - ширина по координатам
|
|
26
|
-
* @param {String} data - стилізація
|
|
27
|
-
* @param {String} lang - мова
|
|
28
|
-
* @param {String} z - координата z
|
|
29
|
-
* @param {String} x - координата y
|
|
30
|
-
* @param {String} y - координата x
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
export default async function rtile({
|
|
34
|
-
pg = pgClients.client, params = {}, query = {}, user = {},
|
|
35
|
-
}, reply) {
|
|
36
|
-
const { id, z, y } = params;
|
|
37
|
-
const { debug, nocache } = query;
|
|
38
|
-
const db = pg.options?.database;
|
|
39
|
-
|
|
40
|
-
const x = params.x.split('.')[0] - 0;
|
|
41
|
-
|
|
42
|
-
if (!id) {
|
|
43
|
-
return reply.status(400).send('not enough params: id');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!x || !y || !z) {
|
|
47
|
-
return reply.status(400).send('not enough params: xyz');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const exists = pg.pk?.['gis.rasters']
|
|
51
|
-
? await pg.query('select raster_id from gis.rasters where raster_id=$1::text', [id])
|
|
52
|
-
.then(el => el.rows?.[0]?.raster_id)
|
|
53
|
-
: null;
|
|
54
|
-
|
|
55
|
-
if (!exists) {
|
|
56
|
-
return reply.status(404).send('raster not found');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const bbox = mercator.bbox(y, x, z, false, '900913');
|
|
60
|
-
const styleXmlPath = path.join(rootFolder, 'mapnik', `${db}_${id}.xml`).replace(/\\/g, '/');
|
|
61
|
-
|
|
62
|
-
if (debug === '1' && user?.uid) {
|
|
63
|
-
return `python3 test/debug.py tmp/${id}.xml ${bbox.join(',')} /data/softpro/work/1.png`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const filepath = path.join(
|
|
67
|
-
rootFolder,
|
|
68
|
-
`/rtile/${id}${z}/${x}/${y}.png`
|
|
69
|
-
).replace(/\\/g, '/');
|
|
70
|
-
|
|
71
|
-
if (debug === '2' && user?.uid) {
|
|
72
|
-
const sourcePath = await pg.query('SELECT source_path from gis.rasters where raster_id=$1', [id]).then(el => el.rows?.[0]?.source_path);
|
|
73
|
-
const fullPath = sourcePath ? path.posix.join(config.mapServerRoot || '', config.folder, '/map/raster/', sourcePath, (sourcePath?.toLowerCase?.()?.includes?.('.tif') ? '' : 'mosaic.vrt')) : null;
|
|
74
|
-
return { rootFolder, filepath, styleXmlPath, fullPath };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (existsSync(filepath) && !nocache && !debug) {
|
|
78
|
-
reply.headers({ 'Cache-Control': 'public, max-age=5184000', 'Content-Type': 'image/png', 'Cache-File': true });
|
|
79
|
-
return readFile(filepath);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
try {
|
|
83
|
-
if (!autoGenerate[id] || debug === '3') {
|
|
84
|
-
const resp = await rasterXML({ id, pg });
|
|
85
|
-
|
|
86
|
-
if (resp?.error) {
|
|
87
|
-
return reply.status(400).send(resp.error);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (debug === '3' && user?.uid) {
|
|
91
|
-
return resp;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
autoGenerate[id] = 1;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!loaded[id] || debug === '4') {
|
|
98
|
-
const xml = await readFile(styleXmlPath, 'utf-8');
|
|
99
|
-
|
|
100
|
-
if (debug === '4' && user?.uid) {
|
|
101
|
-
return xml;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
await loadXML({ name: id, xml, reload: true });
|
|
105
|
-
loaded[id] = 1;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const data = await render({
|
|
109
|
-
name: id,
|
|
110
|
-
width: 256,
|
|
111
|
-
height: 256,
|
|
112
|
-
bbox,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
if (debug === '5' && user?.uid) {
|
|
116
|
-
return { data, bbox, id, filepath };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (data.err) {
|
|
120
|
-
return data.err;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const buffer = Buffer.from(data.base64, 'base64');
|
|
124
|
-
|
|
125
|
-
await mkdir(path.dirname(filepath), { recursive: true });
|
|
126
|
-
await writeFile(filepath, buffer);
|
|
127
|
-
|
|
128
|
-
return reply.headers({ 'Content-Type': 'image/png' }).send(buffer);
|
|
129
|
-
} catch (err) {
|
|
130
|
-
logger.file('rtile/error', { error: err.toString(), stack: err.stack });
|
|
131
|
-
return reply.status(500).send('rtile error');
|
|
132
|
-
}
|
|
133
|
-
}
|