@opengis/gis 0.2.21 → 0.2.23
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 +4179 -4082
- package/dist/index.umd.cjs +43 -43
- package/module/gis/form/gis.cartocss.form.json +46 -0
- package/module/gis/table/gis.cartocss.table.json +61 -0
- package/module/gis/table/gis.rasters.table.json +1 -1
- package/package.json +3 -3
- package/server/routes/gis/index.mjs +23 -20
- package/server/routes/gis/registers/funcs/handleRegistryRequest.js +13 -2
- package/server/routes/gis/registers/gis.registry.js +35 -3
- package/server/routes/map/controllers/geojson.js +187 -0
- package/server/routes/map/controllers/jsonData.js +205 -0
- package/server/routes/map/index.mjs +15 -2
- package/server/routes/map/vtile1.js +4 -4
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": {
|
|
3
|
+
"name": {
|
|
4
|
+
"ua": "Назва",
|
|
5
|
+
"col": 12,
|
|
6
|
+
"type": "Text",
|
|
7
|
+
"validators": [
|
|
8
|
+
"required"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"group_id": {
|
|
12
|
+
"type": "Autocomplete",
|
|
13
|
+
"data": "gis.group_list",
|
|
14
|
+
"col": 6,
|
|
15
|
+
"ua": "Група"
|
|
16
|
+
},
|
|
17
|
+
"cartocss_key": {
|
|
18
|
+
"ua": "Унікальний ключ",
|
|
19
|
+
"col": 6,
|
|
20
|
+
"type": "Text",
|
|
21
|
+
"validators": [
|
|
22
|
+
"required"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
"description": {
|
|
26
|
+
"ua": "Опис",
|
|
27
|
+
"col": 12,
|
|
28
|
+
"type": "TextArea",
|
|
29
|
+
"validators": [
|
|
30
|
+
"required"
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
"is_public": {
|
|
34
|
+
"ua": "Чи є карта публічною?",
|
|
35
|
+
"col": 6,
|
|
36
|
+
"type": "Switcher",
|
|
37
|
+
"data": "yes_no"
|
|
38
|
+
},
|
|
39
|
+
"enabled": {
|
|
40
|
+
"ua": "Чи включена карта?",
|
|
41
|
+
"col": 6,
|
|
42
|
+
"type": "Switcher",
|
|
43
|
+
"data": "yes_no"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"key": "cartocss_id",
|
|
3
|
+
"table": "gis.cartocss",
|
|
4
|
+
"form": "gis.cartocss.form",
|
|
5
|
+
"meta": {
|
|
6
|
+
"title": "name",
|
|
7
|
+
"search": "name,description"
|
|
8
|
+
},
|
|
9
|
+
"card": true,
|
|
10
|
+
"order": "created_at desc",
|
|
11
|
+
"columns": [
|
|
12
|
+
{
|
|
13
|
+
"ua": "Назва",
|
|
14
|
+
"name": "name",
|
|
15
|
+
"format": "text"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"ua": "Опис",
|
|
19
|
+
"name": "description",
|
|
20
|
+
"format": "text"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"ua": "Група",
|
|
24
|
+
"name": "group_id",
|
|
25
|
+
"data": "gis.group_list",
|
|
26
|
+
"format": "select"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"ua": "On/Off",
|
|
30
|
+
"name": "enabled",
|
|
31
|
+
"data": "yes_no",
|
|
32
|
+
"format": "badge"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"ua": "Чи публічний",
|
|
36
|
+
"name": "is_public",
|
|
37
|
+
"data": "yes_no",
|
|
38
|
+
"format": "badge"
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"filterList": [
|
|
42
|
+
{
|
|
43
|
+
"ua": "Група",
|
|
44
|
+
"name": "group_id",
|
|
45
|
+
"data": "gis.group_list",
|
|
46
|
+
"type": "Check"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"ua": "On/Off",
|
|
50
|
+
"name": "enabled",
|
|
51
|
+
"data": "yes_no",
|
|
52
|
+
"type": "Check"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"ua": "Чи публічний",
|
|
56
|
+
"name": "is_public",
|
|
57
|
+
"data": "yes_no",
|
|
58
|
+
"type": "Check"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/gis",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Softpro",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@opengis/core": "^0.0.23",
|
|
49
|
-
"@opengis/fastify-table": "^2.0.
|
|
49
|
+
"@opengis/fastify-table": "^2.0.116",
|
|
50
50
|
"@opengis/filter": "^0.1.25",
|
|
51
51
|
"@opengis/form": "^0.0.91",
|
|
52
52
|
"@opengis/table": "^0.0.27",
|
|
@@ -66,4 +66,4 @@
|
|
|
66
66
|
"vue-router": "4.5.1",
|
|
67
67
|
"vuedraggable": "^4.1.0"
|
|
68
68
|
}
|
|
69
|
-
}
|
|
69
|
+
}
|
|
@@ -30,32 +30,35 @@ const mapInfoPointSchema = {
|
|
|
30
30
|
},
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
const params = { config: { package: 'gis' } };
|
|
34
|
+
const publicParams = { config: { policy: 'L0', package: 'gis' } };
|
|
35
|
+
|
|
33
36
|
async function route(app) {
|
|
34
|
-
app.put('/insert-columns/:token', insertColumns);
|
|
35
|
-
app.put('/insert-filters/:token', insertFilters);
|
|
36
|
-
app.get('/gis-registry/:slug',
|
|
37
|
-
app.get('/gis-registry/:slug/:objectId',
|
|
38
|
-
app.get('/gis-registry',
|
|
39
|
-
app.post('/gis-registry',
|
|
40
|
-
app.put('/gis-registry/:slug',
|
|
41
|
-
app.delete('/gis-registry/:slug',
|
|
42
|
-
app.get('/map-registry/:slug/:id',
|
|
37
|
+
app.put('/insert-columns/:token', params, insertColumns);
|
|
38
|
+
app.put('/insert-filters/:token', params, insertFilters);
|
|
39
|
+
app.get('/gis-registry/:slug', publicParams, gisRegistry);
|
|
40
|
+
app.get('/gis-registry/:slug/:objectId', publicParams, gisRegistry);
|
|
41
|
+
app.get('/gis-registry', publicParams, gisRegistryList);
|
|
42
|
+
app.post('/gis-registry', publicParams, addGisRegistry);
|
|
43
|
+
app.put('/gis-registry/:slug', publicParams, addGisRegistry);
|
|
44
|
+
app.delete('/gis-registry/:slug', publicParams, deleteGisRegistry);
|
|
45
|
+
app.get('/map-registry/:slug/:id', publicParams, mapRegistry);
|
|
43
46
|
|
|
44
|
-
app.get('/xml/:id',
|
|
47
|
+
app.get('/xml/:id', publicParams, metadataXML);
|
|
45
48
|
|
|
46
|
-
app.get('/get-layer-geom/:id',
|
|
49
|
+
app.get('/get-layer-geom/:id', publicParams, getLayerGeom);
|
|
47
50
|
|
|
48
|
-
app.get('/gis-export/:type/:slug',
|
|
51
|
+
app.get('/gis-export/:type/:slug', publicParams, gisExport);
|
|
49
52
|
|
|
50
|
-
app.get('/gis-service/:id?',
|
|
51
|
-
app.get('/gis-service/:id/:col',
|
|
52
|
-
app.post('/gis-service/:id?',
|
|
53
|
-
app.put('/gis-service/:id',
|
|
54
|
-
app.delete('/gis-service/:id',
|
|
55
|
-
app.get('/legend-auto/:id',
|
|
53
|
+
app.get('/gis-service/:id?', publicParams, getServices);
|
|
54
|
+
app.get('/gis-service/:id/:col', publicParams, getServicesCol);
|
|
55
|
+
app.post('/gis-service/:id?', publicParams, addService);
|
|
56
|
+
app.put('/gis-service/:id', publicParams, addService);
|
|
57
|
+
app.delete('/gis-service/:id', publicParams, deleteService);
|
|
58
|
+
app.get('/legend-auto/:id', publicParams, legendAuto);
|
|
56
59
|
|
|
57
|
-
app.get('/map-info-point', {
|
|
60
|
+
app.get('/map-info-point', { ...publicParams, schema: mapInfoPointSchema }, mapInfoPoint);
|
|
58
61
|
|
|
59
|
-
app.get('/dashboard',
|
|
62
|
+
app.get('/dashboard', publicParams, getDashboard);
|
|
60
63
|
}
|
|
61
64
|
export default route;
|
|
@@ -12,8 +12,8 @@ const columnType = {
|
|
|
12
12
|
'timestamp with time zone': 'date',
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
export async function handleRegistryRequest({ settings, query, object_id, offset = 0, limit = 16, page = 1, pg, sql }) {
|
|
16
|
-
const { name, table_name, description, card, columns, filters, query: whereQuery, order, pk, register_id,
|
|
15
|
+
export async function handleRegistryRequest({ settings, query, object_id, is_downloadable, register_key, is_map, is_register, service_id, is_files, offset = 0, limit = 16, page = 1, pg, sql }) {
|
|
16
|
+
const { name, table_name, description, card, columns, filters, query: whereQuery, order, pk, register_id, view } = settings;
|
|
17
17
|
const parsedColumns = Array.isArray(columns) ? columns : JSON.parse(columns);
|
|
18
18
|
const filtersParsed = Array.isArray(filters) ? filters : JSON.parse(filters);
|
|
19
19
|
const activeFilters = (filtersParsed || []).filter((f) => f.disabled !== true).map(el => ({ ...el, id: el.name || el.id, type: el.type, api: '/api/suggest/' + table_name + ':' + el.name + (el.data ? `?sel=${el.data}` : '') }));
|
|
@@ -52,9 +52,14 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
|
|
|
52
52
|
card,
|
|
53
53
|
d: 1,
|
|
54
54
|
columns: visibleColumns,
|
|
55
|
+
is_downloadable,
|
|
56
|
+
register_key,
|
|
55
57
|
register_id,
|
|
58
|
+
service_id,
|
|
56
59
|
name,
|
|
57
60
|
is_files,
|
|
61
|
+
is_map,
|
|
62
|
+
is_register,
|
|
58
63
|
};
|
|
59
64
|
}
|
|
60
65
|
|
|
@@ -106,15 +111,21 @@ export async function handleRegistryRequest({ settings, query, object_id, offset
|
|
|
106
111
|
name,
|
|
107
112
|
card,
|
|
108
113
|
table_name,
|
|
114
|
+
register_key,
|
|
109
115
|
description,
|
|
110
116
|
rows,
|
|
111
117
|
total,
|
|
118
|
+
service_id,
|
|
112
119
|
columns: visibleColumns,
|
|
113
120
|
filters: activeFilters,
|
|
114
121
|
fields,
|
|
115
122
|
limit,
|
|
116
123
|
page,
|
|
117
124
|
view,
|
|
125
|
+
is_downloadable,
|
|
126
|
+
is_map,
|
|
127
|
+
is_register,
|
|
128
|
+
is_files,
|
|
118
129
|
config: {
|
|
119
130
|
listConfig
|
|
120
131
|
}
|
|
@@ -20,19 +20,51 @@ export default async function gisRegistry({
|
|
|
20
20
|
const {
|
|
21
21
|
rows: [registry],
|
|
22
22
|
} = await pg.query(
|
|
23
|
-
`SELECT register_id, name, description, card, table_name,
|
|
23
|
+
`SELECT register_id, name, description, card, table_name,
|
|
24
|
+
columns, filters, query, "order", pk, register_key,
|
|
25
|
+
is_files, view, is_downloadable, is_map, is_register, service_id
|
|
24
26
|
FROM gis.registers
|
|
25
27
|
WHERE $1 in (register_key,register_id)`,
|
|
26
28
|
[slug]
|
|
27
29
|
);
|
|
28
30
|
|
|
29
31
|
if (registry) {
|
|
30
|
-
return handleRegistryRequest({
|
|
32
|
+
return handleRegistryRequest({
|
|
33
|
+
settings: registry,
|
|
34
|
+
query,
|
|
35
|
+
is_downloadable: registry.is_downloadable,
|
|
36
|
+
register_key: registry.register_key,
|
|
37
|
+
object_id: objectId,
|
|
38
|
+
is_map: registry.is_map,
|
|
39
|
+
is_register: registry.is_register,
|
|
40
|
+
is_files: registry.is_files,
|
|
41
|
+
service_id: registry.service_id,
|
|
42
|
+
offset,
|
|
43
|
+
limit,
|
|
44
|
+
page: query.page,
|
|
45
|
+
pg,
|
|
46
|
+
sql
|
|
47
|
+
});
|
|
31
48
|
}
|
|
32
49
|
|
|
33
50
|
const registryTemplate = await getTemplate('registry', slug);
|
|
34
51
|
//if (!registryTemplate) return reply.code(404).send({ message: 'Template not found', status: 404 });
|
|
35
52
|
if (!registryTemplate) throw new Error('Template not found');
|
|
36
53
|
|
|
37
|
-
return handleRegistryRequest({
|
|
54
|
+
return handleRegistryRequest({
|
|
55
|
+
settings: registryTemplate,
|
|
56
|
+
query,
|
|
57
|
+
object_id: objectId,
|
|
58
|
+
register_key: registry.register_key,
|
|
59
|
+
is_downloadable: registry?.is_downloadable || registryTemplate?.is_downloadable,
|
|
60
|
+
is_map: registryTemplate.is_map,
|
|
61
|
+
is_register: registryTemplate.is_register,
|
|
62
|
+
is_files: registryTemplate.is_files,
|
|
63
|
+
service_id: registryTemplate.service_id,
|
|
64
|
+
offset,
|
|
65
|
+
limit,
|
|
66
|
+
page: query.page,
|
|
67
|
+
pg,
|
|
68
|
+
sql
|
|
69
|
+
});
|
|
38
70
|
}
|
|
@@ -0,0 +1,187 @@
|
|
|
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 {
|
|
9
|
+
pgClients, getMeta,
|
|
10
|
+
} from '@opengis/fastify-table/utils.js';
|
|
11
|
+
|
|
12
|
+
import rootFolder from '../../../plugins/mapnik/funcs/rootFolder.mjs';
|
|
13
|
+
|
|
14
|
+
const systemColumns = ['uid', 'cdate', 'editor_id', 'editor_date', 'created_by', 'created_at', 'updated_by', 'updated_at'];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Повертає GeoJSON для сервісу на основі налаштувань з gis.services
|
|
18
|
+
*
|
|
19
|
+
* @method GET
|
|
20
|
+
* @param {string} params.layer - service_id
|
|
21
|
+
* @param {string} query.sql - повернути SQL запит замість даних
|
|
22
|
+
* @param {boolean} query.nocache - не використовувати кеш
|
|
23
|
+
*/
|
|
24
|
+
export default async function geojson({
|
|
25
|
+
pg = pgClients.client, params = {}, query = {}, unittest,
|
|
26
|
+
}, reply) {
|
|
27
|
+
const { layer } = params;
|
|
28
|
+
const { sql, nocache, srid, type, extent } = query;
|
|
29
|
+
|
|
30
|
+
if (!layer) {
|
|
31
|
+
return reply.status(400).send('not enough params: layer (service_id)');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const serviceId = layer.replace('.json', '');
|
|
35
|
+
|
|
36
|
+
if (!pg.pk?.['gis.services']) {
|
|
37
|
+
return reply.status(404).send('services table not found');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const service = await pg.query(
|
|
41
|
+
`select
|
|
42
|
+
source_path,
|
|
43
|
+
query,
|
|
44
|
+
geometry_column,
|
|
45
|
+
attributes,
|
|
46
|
+
srid,
|
|
47
|
+
is_public,
|
|
48
|
+
is_active,
|
|
49
|
+
geom_type
|
|
50
|
+
from gis.services
|
|
51
|
+
where service_id = $1 and is_active = true and is_public = true`,
|
|
52
|
+
[serviceId],
|
|
53
|
+
).then(el => el.rows?.[0]);
|
|
54
|
+
|
|
55
|
+
if (!service) {
|
|
56
|
+
return reply.status(404).send('service not found or not available');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const {
|
|
60
|
+
source_path: source,
|
|
61
|
+
query: serviceQuery,
|
|
62
|
+
geometry_column: gc,
|
|
63
|
+
attributes,
|
|
64
|
+
srid: serviceSrid,
|
|
65
|
+
geom_type: geomType,
|
|
66
|
+
} = service;
|
|
67
|
+
|
|
68
|
+
if (!source) {
|
|
69
|
+
return reply.status(400).send('invalid service source path');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const table = source;
|
|
73
|
+
|
|
74
|
+
if (!pg.pk?.[table]?.length) {
|
|
75
|
+
return reply.status(404).send('layer table not found');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const meta = await getMeta({ pg, table });
|
|
79
|
+
const { columns = [] } = meta || {};
|
|
80
|
+
|
|
81
|
+
const geom = gc || meta?.geom || 'geom';
|
|
82
|
+
const pk = pg.pk?.[table] || columns[0]?.name;
|
|
83
|
+
|
|
84
|
+
let attributeColumns = [];
|
|
85
|
+
if (attributes && Array.isArray(attributes)) {
|
|
86
|
+
attributeColumns = attributes
|
|
87
|
+
.filter(attr => attr.name && !systemColumns.includes(attr.name))
|
|
88
|
+
.map(attr => attr.name);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const columnsFiltered = attributeColumns.length > 0
|
|
92
|
+
? columns.filter(col => attributeColumns.includes(col.name) && !systemColumns.includes(col.name))
|
|
93
|
+
: [];
|
|
94
|
+
|
|
95
|
+
const props = columnsFiltered.map(el =>
|
|
96
|
+
`"${el.name}"${['int4'].includes(el.type) ? '::text' : ''}`
|
|
97
|
+
).join(', ');
|
|
98
|
+
|
|
99
|
+
const geometryType = (geomType || 'point').toLowerCase();
|
|
100
|
+
const limit = geometryType === 'point' ? 40000 : 2500;
|
|
101
|
+
const cacheHash = createHash('md5')
|
|
102
|
+
.update([serviceId, serviceQuery, srid, type, extent].filter(el => el).join('-'))
|
|
103
|
+
.digest('hex');
|
|
104
|
+
|
|
105
|
+
const today = new Date().toISOString().split('T')[0];
|
|
106
|
+
const filepath = path.join(
|
|
107
|
+
rootFolder,
|
|
108
|
+
`/geojson/${serviceId}/${today}/${cacheHash}.json`,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (existsSync(filepath) && !nocache && !sql && !unittest) {
|
|
112
|
+
const { birthtimeMs = Date.now() } = await stat(filepath);
|
|
113
|
+
const ageInMs = Date.now() - birthtimeMs;
|
|
114
|
+
if (ageInMs < 86400000) {
|
|
115
|
+
const content = await readFile(filepath, 'utf8');
|
|
116
|
+
return reply
|
|
117
|
+
.status(200)
|
|
118
|
+
.header('Content-Type', 'application/json')
|
|
119
|
+
.header('Cache-Control', 'public, max-age=86400')
|
|
120
|
+
.send(content);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const targetSrid = srid || serviceSrid || 4326;
|
|
125
|
+
const useCentroid = type === 'centroid';
|
|
126
|
+
|
|
127
|
+
let geomExpression = geom;
|
|
128
|
+
|
|
129
|
+
if (useCentroid) {
|
|
130
|
+
geomExpression = `st_centroid(${geomExpression})`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (targetSrid !== 4326) {
|
|
134
|
+
geomExpression = `st_transform(${geomExpression}, 4326)`;
|
|
135
|
+
} else if (serviceSrid && serviceSrid !== 4326) {
|
|
136
|
+
geomExpression = `st_transform(${geomExpression}, 4326)`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const quotedTable = table.split('.').map(el => `"${el}"`).join('.');
|
|
140
|
+
const quotedGeom = `"${geom}"`;
|
|
141
|
+
|
|
142
|
+
const geomFinal = `st_force2d(${geomExpression.replace(new RegExp(`(\\b)${geom}(\\b)`, 'g'), `$1${quotedGeom}$2`)})`;
|
|
143
|
+
const q = `
|
|
144
|
+
SELECT 'FeatureCollection' As type,
|
|
145
|
+
json_agg(f) As features
|
|
146
|
+
FROM (
|
|
147
|
+
SELECT 'Feature' As type,
|
|
148
|
+
row_number() over() as id,
|
|
149
|
+
st_asgeojson(${geomFinal}, 6, 0)::json as geometry,
|
|
150
|
+
(select row_to_json(tc) from (
|
|
151
|
+
select "${pk}" as id ${props ? ', ' + props : ''}
|
|
152
|
+
) tc) as properties
|
|
153
|
+
FROM ${quotedTable}
|
|
154
|
+
WHERE ${serviceQuery || '1=1'}
|
|
155
|
+
AND ${quotedGeom} is not null
|
|
156
|
+
AND st_srid(${quotedGeom}) > 0
|
|
157
|
+
${extent ? `AND ${quotedGeom} && 'BOX(${extent.split(',').reduce((p, el, i) => p + el + (i % 2 ? ',' : ' '), '')})'::box2d` : ''}
|
|
158
|
+
LIMIT ${limit}
|
|
159
|
+
) f
|
|
160
|
+
`;
|
|
161
|
+
|
|
162
|
+
if (sql === '1') return q;
|
|
163
|
+
if (sql === '2') return filepath.replace(/\\/g, '/');
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
const result = await pg.query(q);
|
|
167
|
+
const geojsonData = result.rows[0] || { type: 'FeatureCollection', features: [] };
|
|
168
|
+
|
|
169
|
+
geojsonData.service_id = serviceId;
|
|
170
|
+
geojsonData.count = geojsonData.features?.length || 0;
|
|
171
|
+
|
|
172
|
+
const jsonString = JSON.stringify(geojsonData);
|
|
173
|
+
|
|
174
|
+
if (!nocache && !unittest) {
|
|
175
|
+
await mkdir(path.dirname(filepath), { recursive: true });
|
|
176
|
+
await writeFile(filepath, jsonString, 'utf8');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return reply
|
|
180
|
+
.status(200)
|
|
181
|
+
.header('Content-Type', 'application/json')
|
|
182
|
+
.header('Cache-Control', nocache ? 'no-cache' : 'public, max-age=86400')
|
|
183
|
+
.send(jsonString);
|
|
184
|
+
} catch (err) {
|
|
185
|
+
return reply.status(500).send({ error: err.message });
|
|
186
|
+
}
|
|
187
|
+
}
|