@opengis/gis 0.2.2 → 0.2.3
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/dist/index.css +1 -1
- package/dist/index.js +3282 -3234
- package/dist/index.umd.cjs +51 -36
- package/module/test/layer/individual.yml +54 -0
- package/package.json +1 -1
- package/plugin.js +4 -2
- package/server/routes/gis/services/get.services.col.js +19 -18
- package/server/routes/gis/services/get.services.js +60 -55
- package/server/routes/map/controllers/layerList.js +42 -32
- package/server/routes/map/controllers/mapFormat.js +76 -116
- package/server/routes/map/vtile1.js +76 -81
|
@@ -1,94 +1,89 @@
|
|
|
1
1
|
const headers = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
'Content-Type': 'application/x-protobuf',
|
|
3
|
+
'Cache-Control': 'no-cache',
|
|
4
4
|
};
|
|
5
5
|
import Sphericalmercator from '@mapbox/sphericalmercator';
|
|
6
|
+
|
|
6
7
|
const mercator = new Sphericalmercator({ size: 256 });
|
|
7
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
getColumnCLS, getTemplate, getMeta, getFilterSQL, getSelect,
|
|
10
|
+
} from '@opengis/fastify-table/utils.js';
|
|
8
11
|
import yaml from 'js-yaml';
|
|
9
12
|
|
|
10
13
|
const propsCache = {};
|
|
11
14
|
|
|
12
|
-
export default async function vtile({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return `(select "${fields[1].name}" from (${clsdata.sql})s${idx} where "${fields[0].name}"="${key}" limit 1) as "${key}_text","${key}"::text`
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return `"${key}"::text`;
|
|
70
|
-
}));
|
|
71
|
-
if (!propsCache[layer]) { propsCache[layer] = propsWithCls; }
|
|
72
|
-
|
|
73
|
-
const geomCol = (style?.type === 'point' ? `ST_Centroid(${geom})` : null)
|
|
15
|
+
export default async function vtile({
|
|
16
|
+
params = {}, query, pg, user,
|
|
17
|
+
}, reply) {
|
|
18
|
+
const { y, z } = params;
|
|
19
|
+
const x = params.x.split('.')[0] - 0;
|
|
20
|
+
|
|
21
|
+
// layer
|
|
22
|
+
const [map, layer] = params.layer.includes(':') ? params.layer.split(':') : [null, params.layer];
|
|
23
|
+
|
|
24
|
+
// service
|
|
25
|
+
const data = await getTemplate('layer', layer) || await pg.query(`select * from gis.services where is_active and ${!user?.uid ? 'is_public' : '1=1'} and service_id=$1`, [layer]).then(el => el.rows?.[0]);
|
|
26
|
+
|
|
27
|
+
const geom = data?.geometry_column || 'geom';
|
|
28
|
+
const table = data?.source_path;
|
|
29
|
+
const style = typeof data?.style === 'object' ? data?.style : yaml.load(data?.style);
|
|
30
|
+
const filterList = data?.filters;
|
|
31
|
+
const layerQuery = data?.query;
|
|
32
|
+
|
|
33
|
+
// bbox
|
|
34
|
+
const bbox = mercator.bbox(+y, +x, +z, false/* , '900913' */);
|
|
35
|
+
const bbox2d = `'BOX(${bbox[0]} ${bbox[1]},${bbox[2]} ${bbox[3]})'::box2d`;
|
|
36
|
+
|
|
37
|
+
const filterData = query.filter ? await getFilterSQL({
|
|
38
|
+
filter: query.filter, table, filterList,
|
|
39
|
+
}) : {};
|
|
40
|
+
|
|
41
|
+
// meta
|
|
42
|
+
const metaTable = await getMeta({ pg, table });
|
|
43
|
+
if (metaTable.error) { return metaTable; }
|
|
44
|
+
const { pk: pkey, columns } = metaTable;
|
|
45
|
+
|
|
46
|
+
// props
|
|
47
|
+
const props = !query.all ? data.popup || [] : columns.filter(el => !['json', 'geometry'].includes(pg.pgType[el.dataTypeID]) && !['uid', 'cdate', 'editor_id', 'editor_date'].includes(el.name));
|
|
48
|
+
const cache = layer + (query.all ? '-all' : '');
|
|
49
|
+
const propsWithCls = propsCache[cache] ?? await Promise.all(props.map(async (col, idx) => {
|
|
50
|
+
const key = col.name;
|
|
51
|
+
const select = data.popup?.find(el => el.name === key);
|
|
52
|
+
// console.log(select);
|
|
53
|
+
const clsData = select?.data || col.data;
|
|
54
|
+
const cls = clsData ? await getSelect(clsData).then(el => ({ name: clsData, type: el.arr ? 'cls' : 'select', sql: el.sql })) : null;
|
|
55
|
+
const { name, type, sql } = cls || getColumnCLS(table, col.data || key) || {};
|
|
56
|
+
// console.log({ name, type, sql });
|
|
57
|
+
if (name && type === 'cls') {
|
|
58
|
+
return `(select name from admin.cls where parent='${name}' and code::text=${key}::text limit 1) as "${key}_text","${key}"::text`;
|
|
59
|
+
}
|
|
60
|
+
if (type === 'select' && sql) {
|
|
61
|
+
const { fields = [] } = await pg.query(`${sql} limit 0`);
|
|
62
|
+
return `(select "${fields[1].name}" from (${sql})s${idx} where "${fields[0].name}"::text="${key}"::text limit 1) as "${key}_text","${key}"::text`;
|
|
63
|
+
}
|
|
64
|
+
return `"${key}"::text`;
|
|
65
|
+
}));
|
|
66
|
+
propsCache[cache] = propsCache[cache] || propsWithCls;
|
|
67
|
+
|
|
68
|
+
const geomCol = (style?.type === 'point' ? `ST_Centroid(${geom})` : null)
|
|
74
69
|
|| (parseInt(z, 10) < parseInt(query.pointZoom || style?.pointZoom || style?.iconZoom || '0', 10) ? `ST_Centroid(${geom})` : geom);
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
const koef = {
|
|
72
|
+
10: 0.1, 11: 0.05, 12: 0.005, 13: 0.001, 14: 0.001, 15: 0.0005,
|
|
73
|
+
}[z] || 0.0005;
|
|
79
74
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
const { type } = query;
|
|
76
|
+
const types = { point: 'ST_Point' /* ,ST_MultiPoint */, polygon: 'ST_Polygon,ST_MultiPolygon' };
|
|
77
|
+
const sql = ((query.clusterZoom - z) > 2
|
|
78
|
+
? `SELECT ST_AsMVT(q, '${layer}', 4096, 'geom','row') as tile
|
|
84
79
|
FROM (
|
|
85
80
|
SELECT floor(random() * 100000 + 1)::int + row_number() over() as row, point_count, ST_AsMVTGeom(st_transform(geom,3857),ST_TileEnvelope(${z},${y},${x})::box2d,4096,256,false) geom
|
|
86
81
|
FROM (
|
|
87
82
|
SELECT st_centroid(st_union(geom)) as geom, count(*) as point_count
|
|
88
83
|
FROM ${table} where ${layerQuery || 'true'} and ${filterData?.q || 'true'} and ${geom} && ${bbox2d} ) j
|
|
89
|
-
)q
|
|
90
|
-
|
|
91
|
-
|
|
84
|
+
)q` : null
|
|
85
|
+
) || ((query.clusterZoom - z) > 0
|
|
86
|
+
? `SELECT ST_AsMVT(q, '${layer}', 4096, 'geom','row') as tile
|
|
92
87
|
FROM (
|
|
93
88
|
SELECT floor(random() * 100000 + 1)::int +row_number() over() as row, count(*) as point_count, ST_AsMVTGeom(st_transform(st_centroid(ST_Union(geom)),3857),ST_TileEnvelope(${z},${y},${x})::box2d,4096,256,false) geom
|
|
94
89
|
FROM (
|
|
@@ -99,7 +94,7 @@ export default async function vtile({ params = {}, query, pg, user }, reply) {
|
|
|
99
94
|
ORDER BY 1 DESC
|
|
100
95
|
)q`
|
|
101
96
|
|
|
102
|
-
|
|
97
|
+
: `SELECT ST_AsMVT(q, '${layer}', 4096, 'geom','row') as tile
|
|
103
98
|
FROM (
|
|
104
99
|
SELECT
|
|
105
100
|
|
|
@@ -125,8 +120,8 @@ export default async function vtile({ params = {}, query, pg, user }, reply) {
|
|
|
125
120
|
limit 3000)q
|
|
126
121
|
) q`);
|
|
127
122
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
123
|
+
if (query.sql === '1') { return sql; }
|
|
124
|
+
const tile = await pg.query(sql);
|
|
125
|
+
const buffer = Buffer.concat(tile.rows.map((el) => Buffer.from(el.tile)));
|
|
126
|
+
return reply.headers(headers).send(buffer);
|
|
127
|
+
}
|