@opengis/gis 0.2.45 → 0.2.46

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 (159) hide show
  1. package/README.md +5 -5
  2. package/dist/index.css +1 -1
  3. package/dist/index.js +6238 -5599
  4. package/dist/index.umd.cjs +72 -52
  5. package/module/cls.json +6 -6
  6. package/module/gis/card/gis.metadata.table/index.yml +22 -22
  7. package/module/gis/card/gis.metadata.table/main_info.hbs +20 -20
  8. package/module/gis/card/gis.metadata.table/metadata_info.hbs +27 -27
  9. package/module/gis/card/gis.metadata.table/other.hbs +25 -25
  10. package/module/gis/card/gis.rasters.table/index.yml +11 -11
  11. package/module/gis/card/gis.rasters.table/main_info.hbs +27 -27
  12. package/module/gis/card/gis.registers.table/cls.hbs +36 -36
  13. package/module/gis/card/gis.registers.table/columns.hbs +89 -89
  14. package/module/gis/card/gis.registers.table/filters.hbs +80 -80
  15. package/module/gis/card/gis.registers.table/index.yml +23 -23
  16. package/module/gis/card/gis.registers.table/main_info.hbs +35 -35
  17. package/module/gis/card/gis.registers.table/source.hbs +45 -45
  18. package/module/gis/card/gis.services.table/attributes.hbs +91 -91
  19. package/module/gis/card/gis.services.table/filters.hbs +83 -83
  20. package/module/gis/card/gis.services.table/index.yml +25 -25
  21. package/module/gis/card/gis.services.table/main_info.hbs +27 -27
  22. package/module/gis/card/gis.services.table/source.hbs +25 -25
  23. package/module/gis/cls/bool.yes_no.json +12 -12
  24. package/module/gis/cls/encoding.json +14 -14
  25. package/module/gis/cls/geom_type.json +14 -14
  26. package/module/gis/cls/gis.column_type.json +34 -34
  27. package/module/gis/cls/gis.column_view_type.json +26 -26
  28. package/module/gis/cls/gis.filter_type.json +22 -22
  29. package/module/gis/cls/language.json +10 -10
  30. package/module/gis/cls/meta.service_type.json +42 -42
  31. package/module/gis/cls/ogc.service.json +21 -21
  32. package/module/gis/cls/service_type.json +42 -42
  33. package/module/gis/cls/source_type.json +10 -10
  34. package/module/gis/cls/standarts.json +6 -6
  35. package/module/gis/cls/topic_category.json +106 -106
  36. package/module/gis/cls/update_frequency.json +29 -29
  37. package/module/gis/cls/view.json +21 -21
  38. package/module/gis/form/gis.cartocss.form.json +45 -45
  39. package/module/gis/form/gis.group_list.form.json +17 -17
  40. package/module/gis/form/gis.maps.form.json +61 -61
  41. package/module/gis/form/gis.metadata.form.json +240 -240
  42. package/module/gis/form/gis.ogc_service.form.json +45 -45
  43. package/module/gis/form/gis.rasters.form.json +103 -103
  44. package/module/gis/form/gis.registers.form.json +124 -124
  45. package/module/gis/form/gis.registers_column.form.json +84 -84
  46. package/module/gis/form/gis.registers_filter.form.json +65 -65
  47. package/module/gis/form/gis.services.form.json +111 -111
  48. package/module/gis/form/gis.services_attributes.form.json +75 -75
  49. package/module/gis/form/gis.services_filter.form.json +65 -65
  50. package/module/gis/menu.json +43 -43
  51. package/module/gis/select/pg.columns.parent.sql +6 -6
  52. package/module/gis/select/pg.table_name.sql +17 -17
  53. package/module/gis/select/service_id.sql +1 -1
  54. package/module/gis/table/gis.cartocss.table.json +62 -62
  55. package/module/gis/table/gis.group_list.table.json +35 -35
  56. package/module/gis/table/gis.maps.table.json +108 -108
  57. package/module/gis/table/gis.metadata.table.json +70 -70
  58. package/module/gis/table/gis.ogc_service.table.json +98 -98
  59. package/module/gis/table/gis.rasters.table.json +101 -101
  60. package/module/gis/table/gis.registers.table.json +144 -144
  61. package/module/gis/table/gis.services.table.json +121 -121
  62. package/module/gis/table/site.gis.registers.table.json +88 -88
  63. package/module/gis/table/site.gis.services.table.json +106 -106
  64. package/module/gis/templates/ISO19136_2017_gml_template.xml +330 -330
  65. package/module/gis/tokens.yml +5 -5
  66. package/module/test/cls/bp_build_type.json +37 -37
  67. package/module/test/cls/doc_status.json +31 -31
  68. package/module/test/cls/ts.temp_status.json +18 -18
  69. package/module/test/cls/ts.temp_structure.ts_class.json +49 -49
  70. package/module/test/cls/ts.temp_type.json +9 -9
  71. package/module/test/layer/bp.json +59 -59
  72. package/module/test/layer/bp1.yml +33 -33
  73. package/module/test/layer/individual.yml +53 -53
  74. package/module/test/layer/ts.linking_passport.yml +55 -55
  75. package/module/test/layer/ts.temp_structure.yml +50 -50
  76. package/module/test/map/addr.yml +21 -21
  77. package/module/test/map/bp_myo.json +43 -43
  78. package/module/test/map/bpf.json +43 -43
  79. package/module/test/map/main.json +36 -36
  80. package/module/test/map/mbd.json +91 -91
  81. package/module/test/map/ts.json +52 -52
  82. package/module/test/select/address_id.json +2 -2
  83. package/module/test/select/address_id.sql +7 -7
  84. package/module/test/select/core.user_uid.sql +1 -1
  85. package/module/test/table/data_address.street.table.json +69 -69
  86. package/module/test/table/data_bp_myo.bp.table.json +122 -122
  87. package/package.json +75 -75
  88. package/plugin.js +45 -44
  89. package/server/migrations/maps.sql +30 -30
  90. package/server/migrations/ogc.sql +106 -106
  91. package/server/migrations/rasters.sql +263 -263
  92. package/server/migrations/services.sql +247 -247
  93. package/server/migrations/widgets.sql +20 -20
  94. package/server/plugins/crons.js +21 -21
  95. package/server/plugins/mapnik/funcs/mapnik.js +111 -106
  96. package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
  97. package/server/plugins/mapnik/map.proto +151 -0
  98. package/server/plugins/vite.js +74 -74
  99. package/server/routes/gis/cartocss/add.cartocss.js +152 -18
  100. package/server/routes/gis/cartocss/get.cartocss.js +12 -12
  101. package/server/routes/gis/dashboard.js +29 -29
  102. package/server/routes/gis/index.mjs +73 -73
  103. package/server/routes/gis/metadata/metadataXML.js +13 -13
  104. package/server/routes/gis/ogc/map.info.point.js +124 -124
  105. package/server/routes/gis/registers/add.registry.js +35 -35
  106. package/server/routes/gis/registers/del.registry.js +14 -14
  107. package/server/routes/gis/registers/funcs/classifiers.js +100 -100
  108. package/server/routes/gis/registers/funcs/columns.js +4 -4
  109. package/server/routes/gis/registers/funcs/content.type.js +9 -9
  110. package/server/routes/gis/registers/funcs/get.info.js +89 -89
  111. package/server/routes/gis/registers/funcs/handleRegistryRequest.js +145 -145
  112. package/server/routes/gis/registers/gis.export.js +148 -148
  113. package/server/routes/gis/registers/gis.registry.js +64 -64
  114. package/server/routes/gis/registers/gis.registry.list.js +59 -59
  115. package/server/routes/gis/registers/insert.columns.js +107 -107
  116. package/server/routes/gis/registers/insert.filters.js +110 -110
  117. package/server/routes/gis/registers/map.registry.js +79 -79
  118. package/server/routes/gis/services/add.service.js +64 -64
  119. package/server/routes/gis/services/del.service.js +12 -12
  120. package/server/routes/gis/services/get.layer.geom.js +27 -27
  121. package/server/routes/gis/services/get.services.col.js +33 -33
  122. package/server/routes/gis/services/get.services.js +84 -84
  123. package/server/routes/gis/services/legend.auto.js +77 -77
  124. package/server/routes/map/controllers/geojson.js +187 -187
  125. package/server/routes/map/controllers/jsonData.js +205 -205
  126. package/server/routes/map/controllers/layerList.js +60 -60
  127. package/server/routes/map/controllers/map.js +123 -123
  128. package/server/routes/map/controllers/mapCatalog.js +72 -72
  129. package/server/routes/map/controllers/mapCatalogAttribute.js +55 -55
  130. package/server/routes/map/controllers/mapFeatures.js +128 -128
  131. package/server/routes/map/controllers/mapFormat.js +83 -83
  132. package/server/routes/map/controllers/mapTiles.js +152 -152
  133. package/server/routes/map/controllers/maps.js +15 -15
  134. package/server/routes/map/controllers/marker_icon.js +43 -43
  135. package/server/routes/map/controllers/vtile.js +172 -172
  136. package/server/routes/map/index.mjs +142 -142
  137. package/server/routes/map/maps/add.map.js +43 -43
  138. package/server/routes/map/maps/del.map.js +18 -18
  139. package/server/routes/map/maps/get.map.js +80 -80
  140. package/server/routes/map/vtile1.js +170 -170
  141. package/server/routes/map/widgets/add.widget.js +38 -38
  142. package/server/routes/map/widgets/del.widget.js +22 -22
  143. package/server/routes/map/widgets/get.widget.js +40 -40
  144. package/server/routes/mapnik/controllers/createXML.js +61 -0
  145. package/server/routes/mapnik/controllers/rtile.js +86 -0
  146. package/server/routes/mapnik/controllers/uploadRaster.js +159 -0
  147. package/server/routes/mapnik/index.js +16 -0
  148. package/server/routes/root.mjs +3 -3
  149. package/utils.js +11 -11
  150. package/server/plugins/mapnik/funcs/createXML.js +0 -72
  151. package/server/plugins/mapnik/funcs/gdalWrapper.js +0 -72
  152. package/server/plugins/mapnik/funcs/map.proto +0 -241
  153. package/server/plugins/mapnik/funcs/rasterConfig.js +0 -11
  154. package/server/plugins/mapnik/funcs/rasterExists.js +0 -21
  155. package/server/plugins/mapnik/funcs/rasterInfo.js +0 -109
  156. package/server/plugins/mapnik/funcs/rasterVrt.js +0 -56
  157. package/server/plugins/mapnik/funcs/rasterXML.js +0 -65
  158. package/server/plugins/mapnik/utils/map.proto +0 -241
  159. package/server/routes/map/controllers/rtile.js +0 -134
@@ -1,172 +1,172 @@
1
- import path from 'node:path';
2
- import { existsSync } from 'node:fs';
3
- import { createHash } from 'node:crypto';
4
- import {
5
- readFile, stat, mkdir, writeFile,
6
- } from 'node:fs/promises';
7
-
8
- import Sphericalmercator from '@mapbox/sphericalmercator';
9
-
10
- import {
11
- getTemplate, pgClients, getFilterSQL, getMeta, yml2json, getColumnCLS, getSelect,
12
- } from '@opengis/fastify-table/utils.js';
13
-
14
- import rootFolder from '../../../plugins/mapnik/funcs/rootFolder.mjs';
15
-
16
- const limit = 3000;
17
- const mercator = new Sphericalmercator({ size: 256 });
18
- const types = { point: 'ST_Point', polygon: 'ST_Polygon,ST_MultiPolygon' };
19
- const systemColumns = ['uid', 'cdate', 'editor_id', 'editor_date', 'created_by', 'created_at', 'updated_by', 'updated_at'];
20
-
21
- export default async function vtile({
22
- pg = pgClients.client, params = {}, query = {}, unittest,
23
- }, reply) {
24
- const { id, y, z } = params;
25
- const {
26
- sql, nocache, filter, pointZoom, type, layers,
27
- } = query;
28
- const x = params.x?.split?.('.')?.[0] - 0;
29
-
30
- if (!id) {
31
- return reply.status(400).send('not enough params: id');
32
- }
33
-
34
- if (!x || !y || !z) {
35
- return reply.status(400).send('not enough params: xyz');
36
- }
37
-
38
- const bbox = mercator.bbox(+y, +x, +z, false);
39
- const bbox2d = `'BOX(${bbox[0]} ${bbox[1]},${bbox[2]} ${bbox[3]})'::box2d`;
40
-
41
- const headers = {
42
- 'Content-Type': 'application/x-protobuf',
43
- 'Cache-Control': nocache || sql ? 'no-cache' : 'public, max-age=86400',
44
- };
45
-
46
- const hash = [filter, layers].filter((el) => el).join();
47
-
48
- const filepath = path.join(
49
- rootFolder,
50
- `/vtile/${id}/${hash ? `${createHash('md5').update(hash).digest('hex')}/` : ''}${z}/${x}/${y}.vmt`,
51
- );
52
-
53
- if (existsSync(filepath) && z < 13 && !nocache && !sql && !unittest) {
54
- const { birthtimeMs = Date.now() } = await stat(filepath);
55
- const ageInMs = Date.now() - birthtimeMs;
56
- if (ageInMs < 86400000) {
57
- const buffer = await readFile(filepath);
58
- return reply.status(200).headers(headers).send(buffer);
59
- }
60
- }
61
-
62
- if (!pg.pk?.['gis.services']) {
63
- return reply.status(404).send('services table not found');
64
- }
65
-
66
- const data = await pg.query(
67
- 'select source_path as source, style, geom_type as gt, geometry_column as gc from gis.services where service_id=$1 and is_active and is_public',
68
- [id],
69
- ).then(el => el.rows?.[0]);
70
-
71
- if (!data) {
72
- return reply.status(404).send('service not found');
73
- }
74
-
75
- const { source, gt, gc } = data;
76
-
77
- const style = data.style ? yml2json(data.style) : {};
78
-
79
- if (!source) {
80
- return reply.status(400).send('invalid service source path');
81
- }
82
-
83
- const loadTable = await getTemplate('table', source);
84
-
85
- const table = loadTable?.table || source;
86
-
87
- if (!pg.pk?.[table]?.length) {
88
- return reply.status(404).send('layer table not found');
89
- }
90
-
91
- const cls = getColumnCLS(table);
92
-
93
- const meta = await getMeta({ pg, table });
94
- const { columns = [] } = meta || {};
95
-
96
- const geom = gc || meta?.geom || 'geom';
97
- const pk = pg.pk?.[table] || loadTable?.key;
98
- const fData = filter ? await getFilterSQL({ pg, table: source, filter }) : {};
99
-
100
- const geomCol = parseInt(z, 10) < parseInt(pointZoom || '0', 10) || (style?.centroid && gt === 'point')
101
- ? `ST_Centroid(${geom})`
102
- : geom;
103
-
104
- const columnsFiltered = columns
105
- .filter(el => !['json', 'geometry'].includes(pg.pgType?.[el.dataTypeID]) && !systemColumns.includes(el.name));
106
-
107
- const props = columnsFiltered.map(el => (el.type?.[0] === '_'
108
- ? `${el.name}[1] as ${el.name}`
109
- : `${el.name}${['int4'].includes(el.type) ? '::text' : ''}`));
110
-
111
- const propsColumns = props.length ? await Promise.all(props.map(async colname => {
112
- if (!cls?.[colname]) return `"${colname}"`;
113
- const { type: type2, data: data2 } = await pg.queryCache('select type, data from admin.cls where parent is null and name=$1 limit 1', { args: [cls[colname]], table: 'admin.cls' })
114
- .then(el => el.rows?.[0] || {}) || {};
115
-
116
- if (!type2 || (type2 === 'sql' && !data2)) {
117
- return `"${colname}"`;
118
- }
119
-
120
- if (type2 === 'json') {
121
- return `(select name from admin.cls where parent='${cls[colname]}' and code="${colname}"::text) as "${colname}"`;
122
- }
123
-
124
- return `(with c(id,text) as (select * from (${data2})q limit 1) select text from c where id::text="${colname}"::text) as "${colname}"`;
125
- })) : '';
126
-
127
- const q = `SELECT ST_AsMVT(q, '${id.replace(/'/g, "''")}', 4096, 'geom','row') as tile
128
- FROM (
129
- SELECT
130
-
131
- floor(random() * 100000 + 1)::int + row_number() over() as row,
132
-
133
- ${style?.colorAttr ? `${style.colorAttr},` : ''} ${propsColumns ? `${propsColumns.filter(Boolean).join('\n,') || ''},` : ''}
134
-
135
- ${pk} as id,
136
- ST_AsMVTGeom(st_transform(${style?.type === 'point' ? `st_pointonsurface(${geomCol})` : geomCol},3857),ST_TileEnvelope(${z},${y},${x})::box2d,4096,256,true) geom
137
-
138
- FROM (select * from ${table} where ${loadTable?.query || '1=1'} and ${fData?.q || 'true'} and ${geom} && ${bbox2d}
139
-
140
- and ${geom} is not null and st_srid(${geom}) >0
141
-
142
- ${types[type] ? ` and ST_GeometryType(${geom}) = any ('{ ${types[type]} }') ` : ''}
143
-
144
- and 1=1
145
-
146
- ${gt === 'polygon' ? `order by st_area(st_transform(${geom},3857)) desc` : ''}
147
-
148
- limit ${limit})q
149
- ) q`;
150
-
151
- if (sql === '1') return q;
152
- if (sql === '2') return filepath.replace(/\\/g, '/');
153
-
154
- const tile = await pg.query(q);
155
-
156
- if (unittest && !tile.rows?.length) {
157
- console.log(id, q);
158
- }
159
-
160
- if (sql === '3') return tile.rows.map((el) => el.tile);
161
-
162
- if (sql === '4') return tile.rows.map((el) => el.tile);
163
-
164
- const buffer = Buffer.concat(tile.rows.map((el) => Buffer.from(el.tile)));
165
-
166
- if (!nocache) {
167
- await mkdir(path.dirname(filepath), { recursive: true });
168
- await writeFile(filepath, buffer, 'binary');
169
- }
170
-
171
- return reply.status(200).headers(headers).send(buffer);
172
- }
1
+ import path from 'node:path';
2
+ import { existsSync } from 'node:fs';
3
+ import { createHash } from 'node:crypto';
4
+ import {
5
+ readFile, stat, mkdir, writeFile,
6
+ } from 'node:fs/promises';
7
+
8
+ import Sphericalmercator from '@mapbox/sphericalmercator';
9
+
10
+ import {
11
+ getTemplate, pgClients, getFilterSQL, getMeta, yml2json, getColumnCLS, getSelect,
12
+ } from '@opengis/fastify-table/utils.js';
13
+
14
+ import rootFolder from '../../../plugins/mapnik/funcs/rootFolder.mjs';
15
+
16
+ const limit = 3000;
17
+ const mercator = new Sphericalmercator({ size: 256 });
18
+ const types = { point: 'ST_Point', polygon: 'ST_Polygon,ST_MultiPolygon' };
19
+ const systemColumns = ['uid', 'cdate', 'editor_id', 'editor_date', 'created_by', 'created_at', 'updated_by', 'updated_at'];
20
+
21
+ export default async function vtile({
22
+ pg = pgClients.client, params = {}, query = {}, unittest,
23
+ }, reply) {
24
+ const { id, y, z } = params;
25
+ const {
26
+ sql, nocache, filter, pointZoom, type, layers,
27
+ } = query;
28
+ const x = params.x?.split?.('.')?.[0] - 0;
29
+
30
+ if (!id) {
31
+ return reply.status(400).send('not enough params: id');
32
+ }
33
+
34
+ if (!x || !y || !z) {
35
+ return reply.status(400).send('not enough params: xyz');
36
+ }
37
+
38
+ const bbox = mercator.bbox(+y, +x, +z, false);
39
+ const bbox2d = `'BOX(${bbox[0]} ${bbox[1]},${bbox[2]} ${bbox[3]})'::box2d`;
40
+
41
+ const headers = {
42
+ 'Content-Type': 'application/x-protobuf',
43
+ 'Cache-Control': nocache || sql ? 'no-cache' : 'public, max-age=86400',
44
+ };
45
+
46
+ const hash = [filter, layers].filter((el) => el).join();
47
+
48
+ const filepath = path.join(
49
+ rootFolder,
50
+ `/vtile/${id}/${hash ? `${createHash('md5').update(hash).digest('hex')}/` : ''}${z}/${x}/${y}.vmt`,
51
+ );
52
+
53
+ if (existsSync(filepath) && z < 13 && !nocache && !sql && !unittest) {
54
+ const { birthtimeMs = Date.now() } = await stat(filepath);
55
+ const ageInMs = Date.now() - birthtimeMs;
56
+ if (ageInMs < 86400000) {
57
+ const buffer = await readFile(filepath);
58
+ return reply.status(200).headers(headers).send(buffer);
59
+ }
60
+ }
61
+
62
+ if (!pg.pk?.['gis.services']) {
63
+ return reply.status(404).send('services table not found');
64
+ }
65
+
66
+ const data = await pg.query(
67
+ 'select source_path as source, style, geom_type as gt, geometry_column as gc from gis.services where service_id=$1 and is_active and is_public',
68
+ [id],
69
+ ).then(el => el.rows?.[0]);
70
+
71
+ if (!data) {
72
+ return reply.status(404).send('service not found');
73
+ }
74
+
75
+ const { source, gt, gc } = data;
76
+
77
+ const style = data.style ? yml2json(data.style) : {};
78
+
79
+ if (!source) {
80
+ return reply.status(400).send('invalid service source path');
81
+ }
82
+
83
+ const loadTable = await getTemplate('table', source);
84
+
85
+ const table = loadTable?.table || source;
86
+
87
+ if (!pg.pk?.[table]?.length) {
88
+ return reply.status(404).send('layer table not found');
89
+ }
90
+
91
+ const cls = getColumnCLS(table);
92
+
93
+ const meta = await getMeta({ pg, table });
94
+ const { columns = [] } = meta || {};
95
+
96
+ const geom = gc || meta?.geom || 'geom';
97
+ const pk = pg.pk?.[table] || loadTable?.key;
98
+ const fData = filter ? await getFilterSQL({ pg, table: source, filter }) : {};
99
+
100
+ const geomCol = parseInt(z, 10) < parseInt(pointZoom || '0', 10) || (style?.centroid && gt === 'point')
101
+ ? `ST_Centroid(${geom})`
102
+ : geom;
103
+
104
+ const columnsFiltered = columns
105
+ .filter(el => !['json', 'geometry'].includes(pg.pgType?.[el.dataTypeID]) && !systemColumns.includes(el.name));
106
+
107
+ const props = columnsFiltered.map(el => (el.type?.[0] === '_'
108
+ ? `${el.name}[1] as ${el.name}`
109
+ : `${el.name}${['int4'].includes(el.type) ? '::text' : ''}`));
110
+
111
+ const propsColumns = props.length ? await Promise.all(props.map(async colname => {
112
+ if (!cls?.[colname]) return `"${colname}"`;
113
+ const { type: type2, data: data2 } = await pg.queryCache('select type, data from admin.cls where parent is null and name=$1 limit 1', { args: [cls[colname]], table: 'admin.cls' })
114
+ .then(el => el.rows?.[0] || {}) || {};
115
+
116
+ if (!type2 || (type2 === 'sql' && !data2)) {
117
+ return `"${colname}"`;
118
+ }
119
+
120
+ if (type2 === 'json') {
121
+ return `(select name from admin.cls where parent='${cls[colname]}' and code="${colname}"::text) as "${colname}"`;
122
+ }
123
+
124
+ return `(with c(id,text) as (select * from (${data2})q limit 1) select text from c where id::text="${colname}"::text) as "${colname}"`;
125
+ })) : '';
126
+
127
+ const q = `SELECT ST_AsMVT(q, '${id.replace(/'/g, "''")}', 4096, 'geom','row') as tile
128
+ FROM (
129
+ SELECT
130
+
131
+ floor(random() * 100000 + 1)::int + row_number() over() as row,
132
+
133
+ ${style?.colorAttr ? `${style.colorAttr},` : ''} ${propsColumns ? `${propsColumns.filter(Boolean).join('\n,') || ''},` : ''}
134
+
135
+ ${pk} as id,
136
+ ST_AsMVTGeom(st_transform(${style?.type === 'point' ? `st_pointonsurface(${geomCol})` : geomCol},3857),ST_TileEnvelope(${z},${y},${x})::box2d,4096,256,true) geom
137
+
138
+ FROM (select * from ${table} where ${loadTable?.query || '1=1'} and ${fData?.q || 'true'} and ${geom} && ${bbox2d}
139
+
140
+ and ${geom} is not null and st_srid(${geom}) >0
141
+
142
+ ${types[type] ? ` and ST_GeometryType(${geom}) = any ('{ ${types[type]} }') ` : ''}
143
+
144
+ and 1=1
145
+
146
+ ${gt === 'polygon' ? `order by st_area(st_transform(${geom},3857)) desc` : ''}
147
+
148
+ limit ${limit})q
149
+ ) q`;
150
+
151
+ if (sql === '1') return q;
152
+ if (sql === '2') return filepath.replace(/\\/g, '/');
153
+
154
+ const tile = await pg.query(q);
155
+
156
+ if (unittest && !tile.rows?.length) {
157
+ console.log(id, q);
158
+ }
159
+
160
+ if (sql === '3') return tile.rows.map((el) => el.tile);
161
+
162
+ if (sql === '4') return tile.rows.map((el) => el.tile);
163
+
164
+ const buffer = Buffer.concat(tile.rows.map((el) => Buffer.from(el.tile)));
165
+
166
+ if (!nocache) {
167
+ await mkdir(path.dirname(filepath), { recursive: true });
168
+ await writeFile(filepath, buffer, 'binary');
169
+ }
170
+
171
+ return reply.status(200).headers(headers).send(buffer);
172
+ }
@@ -1,142 +1,142 @@
1
- import map from './controllers/map.js';
2
- import mapTiles from './controllers/mapTiles.js';
3
- import mapFeatures from './controllers/mapFeatures.js';
4
-
5
- import mapCatalog from './controllers/mapCatalog.js';
6
- import mapCatalogAttribute from './controllers/mapCatalogAttribute.js';
7
- import rtile from './controllers/rtile.js';
8
- import vtile from './controllers/vtile.js';
9
- import vtile1 from './vtile1.js';
10
- import geojson from './controllers/geojson.js';
11
- import jsonData from './controllers/jsonData.js';
12
- import layerList from './controllers/layerList.js';
13
-
14
- import mapFormat from './controllers/mapFormat.js';
15
- import maps from './controllers/maps.js';
16
- import markerIconApi from './controllers/marker_icon.js';
17
-
18
- import getMap from './maps/get.map.js';
19
- import addMap from './maps/add.map.js';
20
- import delMap from './maps/del.map.js';
21
-
22
- import getWidget from './widgets/get.widget.js';
23
- import addWidget from './widgets/add.widget.js';
24
- import delWidget from './widgets/del.widget.js';
25
-
26
- const schemaInfo = {
27
- type: 'object',
28
- properties: {
29
- publicParams: {
30
- slug: {
31
- type: 'string',
32
- },
33
- z: {
34
- type: 'number',
35
- },
36
- y: {
37
- type: 'number',
38
- },
39
- x: {
40
- type: 'string',
41
- pattern: '^\\d+\\.(pbf|vmt)$',
42
- },
43
- id: {
44
- type: 'string',
45
- },
46
- },
47
- },
48
- };
49
-
50
- const publicParams = { config: { policy: 'L0' }, schema: schemaInfo, package: 'gis' }; // * L0 === public
51
- const privilegedParams = { config: { policy: 'L1', role: 'admin' }, schema: schemaInfo, package: 'gis' }; // ? just auth or admin
52
-
53
- export default async function route(app) {
54
- if (!app.hasRoute({ method: 'GET', url: '/gis-map/:id?' })) {
55
- app.get('/gis-map/:id?', publicParams, getMap);
56
- }
57
- if (!app.hasRoute({ method: 'POST', url: '/gis-map/:id?' })) {
58
- app.post('/gis-map/:id?', privilegedParams, addMap);
59
- }
60
- if (!app.hasRoute({ method: 'PUT', url: '/gis-map/:id' })) {
61
- app.put('/gis-map/:id', privilegedParams, addMap);
62
- }
63
- if (!app.hasRoute({ method: 'DELETE', url: '/gis-map/:id' })) {
64
- app.delete('/gis-map/:id', privilegedParams, delMap);
65
- }
66
-
67
- if (!app.hasRoute({ method: 'GET', url: '/gis-widget/:map/:id?' })) {
68
- app.get('/gis-widget/:map/:id?', publicParams, getWidget);
69
- }
70
- if (!app.hasRoute({ method: 'POST', url: '/gis-widget/:map/:id?' })) {
71
- app.post('/gis-widget/:map/:id?', privilegedParams, addWidget);
72
- }
73
- if (!app.hasRoute({ method: 'PUT', url: '/gis-widget/:map/:id' })) {
74
- app.put('/gis-widget/:map/:id', privilegedParams, addWidget);
75
- }
76
- if (!app.hasRoute({ method: 'DELETE', url: '/gis-widget/:map/:id' })) {
77
- app.delete('/gis-widget/:map/:id', privilegedParams, delWidget);
78
- }
79
-
80
- if (!app.hasRoute({ method: 'GET', url: '/maps' })) {
81
- app.get('/maps', publicParams, maps);
82
- }
83
- if (!app.hasRoute({ method: 'GET', url: '/map/:slug' })) {
84
- app.get('/map/:slug', publicParams, map);
85
- }
86
- if (!app.hasRoute({ method: 'GET', url: '/map-tiles/:slug/:z/:y/:x' })) {
87
- app.get('/map-tiles/:slug/:z/:y/:x', publicParams, mapTiles);
88
- }
89
- if (!app.hasRoute({ method: 'GET', url: '/map-features/:slug/:id' })) {
90
- app.get('/map-features/:slug/:id', publicParams, mapFeatures);
91
- }
92
- if (!app.hasRoute({ method: 'GET', url: '/map-features-point/:slug' })) {
93
- app.get('/map-features-point/:slug', publicParams, mapFeatures);
94
- }
95
-
96
- if (!app.hasRoute({ method: 'GET', url: '/map-catalog' })) {
97
- app.get('/map-catalog', publicParams, mapCatalog);
98
- }
99
- if (!app.hasRoute({ method: 'GET', url: '/map-catalog/:service/:attr' })) {
100
- app.get('/map-catalog/:service/:attr', publicParams, mapCatalogAttribute);
101
- }
102
- if (!app.hasRoute({ method: 'GET', url: '/layer-rtile/:id/:z/:y/:x' })) {
103
- app.get('/layer-rtile/:id/:z/:y/:x', publicParams, rtile);
104
- }
105
- if (!app.hasRoute({ method: 'GET', url: '/layer-vtile/:id/:z/:y/:x' })) {
106
- app.get('/layer-vtile/:id/:z/:y/:x', publicParams, vtile);
107
- }
108
-
109
- if (!app.hasRoute({ method: 'GET', url: '/api/vtile/:layer/:lang/:z/:y/:x' })) {
110
- console.log('\x1b[34m%s\x1b[0m', 'add vtile from gis');
111
- app.get('/vtile/:layer/:lang/:z/:y/:x', publicParams, vtile1);
112
- }
113
-
114
- if (!app.hasRoute({ method: 'GET', url: '/api/geojson/:layer' })) {
115
- console.log('\x1b[34m%s\x1b[0m', 'add geojson from gis');
116
- app.get('/geojson/:layer', publicParams, geojson);
117
- }
118
-
119
- if (!app.hasRoute({ method: 'GET', url: '/api/json/:layer' })) {
120
- console.log('\x1b[34m%s\x1b[0m', 'add json from gis');
121
- app.get('/json/:layer', publicParams, jsonData);
122
- }
123
-
124
- if (!app.hasRoute({ method: 'GET', url: '/api/gis-layer-list' })) {
125
- console.log('\x1b[34m%s\x1b[0m', 'add gis-layer-list from gis');
126
- app.get('/gis-layer-list', publicParams, layerList);
127
- }
128
-
129
- if (!app.hasRoute({ method: 'GET', url: '/gis-icon/*' })) {
130
- app.get('/gis-icon/*', publicParams, markerIconApi);
131
- }
132
- if (!app.hasRoute({ method: 'GET', url: '/icon/*' })) {
133
- app.get('/icon/*', publicParams, markerIconApi);
134
- }
135
- if (!app.hasRoute({ method: 'GET', url: '/marker-icon/*' })) {
136
- app.get('/marker-icon/*', publicParams, markerIconApi);
137
- }
138
-
139
- if (!app.hasRoute({ method: 'GET', url: '/api/map-format' })) {
140
- app.get('/map-format', publicParams, mapFormat);
141
- }
142
- }
1
+ import map from './controllers/map.js';
2
+ import mapTiles from './controllers/mapTiles.js';
3
+ import mapFeatures from './controllers/mapFeatures.js';
4
+
5
+ import mapCatalog from './controllers/mapCatalog.js';
6
+ import mapCatalogAttribute from './controllers/mapCatalogAttribute.js';
7
+ // import rtile from './controllers/rtile.js';
8
+ import vtile from './controllers/vtile.js';
9
+ import vtile1 from './vtile1.js';
10
+ import geojson from './controllers/geojson.js';
11
+ import jsonData from './controllers/jsonData.js';
12
+ import layerList from './controllers/layerList.js';
13
+
14
+ import mapFormat from './controllers/mapFormat.js';
15
+ import maps from './controllers/maps.js';
16
+ import markerIconApi from './controllers/marker_icon.js';
17
+
18
+ import getMap from './maps/get.map.js';
19
+ import addMap from './maps/add.map.js';
20
+ import delMap from './maps/del.map.js';
21
+
22
+ import getWidget from './widgets/get.widget.js';
23
+ import addWidget from './widgets/add.widget.js';
24
+ import delWidget from './widgets/del.widget.js';
25
+
26
+ const schemaInfo = {
27
+ type: 'object',
28
+ properties: {
29
+ publicParams: {
30
+ slug: {
31
+ type: 'string',
32
+ },
33
+ z: {
34
+ type: 'number',
35
+ },
36
+ y: {
37
+ type: 'number',
38
+ },
39
+ x: {
40
+ type: 'string',
41
+ pattern: '^\\d+\\.(pbf|vmt)$',
42
+ },
43
+ id: {
44
+ type: 'string',
45
+ },
46
+ },
47
+ },
48
+ };
49
+
50
+ const publicParams = { config: { policy: 'L0' }, schema: schemaInfo, package: 'gis' }; // * L0 === public
51
+ const privilegedParams = { config: { policy: 'L1', role: 'admin' }, schema: schemaInfo, package: 'gis' }; // ? just auth or admin
52
+
53
+ export default async function route(app) {
54
+ if (!app.hasRoute({ method: 'GET', url: '/gis-map/:id?' })) {
55
+ app.get('/gis-map/:id?', publicParams, getMap);
56
+ }
57
+ if (!app.hasRoute({ method: 'POST', url: '/gis-map/:id?' })) {
58
+ app.post('/gis-map/:id?', privilegedParams, addMap);
59
+ }
60
+ if (!app.hasRoute({ method: 'PUT', url: '/gis-map/:id' })) {
61
+ app.put('/gis-map/:id', privilegedParams, addMap);
62
+ }
63
+ if (!app.hasRoute({ method: 'DELETE', url: '/gis-map/:id' })) {
64
+ app.delete('/gis-map/:id', privilegedParams, delMap);
65
+ }
66
+
67
+ if (!app.hasRoute({ method: 'GET', url: '/gis-widget/:map/:id?' })) {
68
+ app.get('/gis-widget/:map/:id?', publicParams, getWidget);
69
+ }
70
+ if (!app.hasRoute({ method: 'POST', url: '/gis-widget/:map/:id?' })) {
71
+ app.post('/gis-widget/:map/:id?', privilegedParams, addWidget);
72
+ }
73
+ if (!app.hasRoute({ method: 'PUT', url: '/gis-widget/:map/:id' })) {
74
+ app.put('/gis-widget/:map/:id', privilegedParams, addWidget);
75
+ }
76
+ if (!app.hasRoute({ method: 'DELETE', url: '/gis-widget/:map/:id' })) {
77
+ app.delete('/gis-widget/:map/:id', privilegedParams, delWidget);
78
+ }
79
+
80
+ if (!app.hasRoute({ method: 'GET', url: '/maps' })) {
81
+ app.get('/maps', publicParams, maps);
82
+ }
83
+ if (!app.hasRoute({ method: 'GET', url: '/map/:slug' })) {
84
+ app.get('/map/:slug', publicParams, map);
85
+ }
86
+ if (!app.hasRoute({ method: 'GET', url: '/map-tiles/:slug/:z/:y/:x' })) {
87
+ app.get('/map-tiles/:slug/:z/:y/:x', publicParams, mapTiles);
88
+ }
89
+ if (!app.hasRoute({ method: 'GET', url: '/map-features/:slug/:id' })) {
90
+ app.get('/map-features/:slug/:id', publicParams, mapFeatures);
91
+ }
92
+ if (!app.hasRoute({ method: 'GET', url: '/map-features-point/:slug' })) {
93
+ app.get('/map-features-point/:slug', publicParams, mapFeatures);
94
+ }
95
+
96
+ if (!app.hasRoute({ method: 'GET', url: '/map-catalog' })) {
97
+ app.get('/map-catalog', publicParams, mapCatalog);
98
+ }
99
+ if (!app.hasRoute({ method: 'GET', url: '/map-catalog/:service/:attr' })) {
100
+ app.get('/map-catalog/:service/:attr', publicParams, mapCatalogAttribute);
101
+ }
102
+ // if (!app.hasRoute({ method: 'GET', url: '/layer-rtile/:id/:z/:y/:x' })) {
103
+ // app.get('/layer-rtile/:id/:z/:y/:x', publicParams, rtile);
104
+ // }
105
+ if (!app.hasRoute({ method: 'GET', url: '/layer-vtile/:id/:z/:y/:x' })) {
106
+ app.get('/layer-vtile/:id/:z/:y/:x', publicParams, vtile);
107
+ }
108
+
109
+ if (!app.hasRoute({ method: 'GET', url: '/api/vtile/:layer/:lang/:z/:y/:x' })) {
110
+ console.log('\x1b[34m%s\x1b[0m', 'add vtile from gis');
111
+ app.get('/vtile/:layer/:lang/:z/:y/:x', publicParams, vtile1);
112
+ }
113
+
114
+ if (!app.hasRoute({ method: 'GET', url: '/api/geojson/:layer' })) {
115
+ console.log('\x1b[34m%s\x1b[0m', 'add geojson from gis');
116
+ app.get('/geojson/:layer', publicParams, geojson);
117
+ }
118
+
119
+ if (!app.hasRoute({ method: 'GET', url: '/api/json/:layer' })) {
120
+ console.log('\x1b[34m%s\x1b[0m', 'add json from gis');
121
+ app.get('/json/:layer', publicParams, jsonData);
122
+ }
123
+
124
+ if (!app.hasRoute({ method: 'GET', url: '/api/gis-layer-list' })) {
125
+ console.log('\x1b[34m%s\x1b[0m', 'add gis-layer-list from gis');
126
+ app.get('/gis-layer-list', publicParams, layerList);
127
+ }
128
+
129
+ if (!app.hasRoute({ method: 'GET', url: '/gis-icon/*' })) {
130
+ app.get('/gis-icon/*', publicParams, markerIconApi);
131
+ }
132
+ if (!app.hasRoute({ method: 'GET', url: '/icon/*' })) {
133
+ app.get('/icon/*', publicParams, markerIconApi);
134
+ }
135
+ if (!app.hasRoute({ method: 'GET', url: '/marker-icon/*' })) {
136
+ app.get('/marker-icon/*', publicParams, markerIconApi);
137
+ }
138
+
139
+ if (!app.hasRoute({ method: 'GET', url: '/api/map-format' })) {
140
+ app.get('/map-format', publicParams, mapFormat);
141
+ }
142
+ }