@opengis/gis 0.2.176 → 0.2.177

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 (160) hide show
  1. package/README.md +181 -181
  2. package/dist/{CardIcon-c1Q2M3wQ.js → CardIcon-CMRD1LLh.js} +1 -1
  3. package/dist/{EntityTablePage-B5gpkH4S.js → EntityTablePage-XNNCltAN.js} +2 -2
  4. package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-DnGSvmMU.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BqUjKTDY.js} +1 -1
  5. package/dist/{HeaderActions.vue_vue_type_script_setup_true_lang-C2B61JP6.js → HeaderActions.vue_vue_type_script_setup_true_lang-BXQ3hKwa.js} +1 -1
  6. package/dist/{MapSettings-6-Xru5Q8.js → MapSettings-P3h-vHn3.js} +2 -2
  7. package/dist/{RastersTablePage-CXNOcTy-.js → RastersTablePage-DnhGZLiH.js} +2 -2
  8. package/dist/{cartocss-BFVqWvfP.js → cartocss-BkrOeQg4.js} +6 -6
  9. package/dist/{import-utils-uxk4LdUJ.js → import-utils-BCATsbB5.js} +1 -1
  10. package/dist/{index-CahlV-Xs.js → index-cUagVqgA.js} +39 -39
  11. package/dist/index.css +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/index.umd.cjs +5 -5
  14. package/dist/{raster-CEi56f0P.js → raster-CP0tUp3j.js} +3 -3
  15. package/dist/{register-NFAGBNa3.js → register-Cr-uQcby.js} +3 -3
  16. package/dist/{service-BYspag8U.js → service-DwJaKrOd.js} +6 -6
  17. package/dist/{vs-datatable-CHcBr6zy.js → vs-datatable-B9WoVk-b.js} +2 -2
  18. package/module/gis/cls/service_type.json +42 -42
  19. package/module/gis/form/gis.registers.form.json +127 -127
  20. package/module/test/map/addr.json +302 -302
  21. package/module/test/map/addr1.yml +23 -23
  22. package/module/test/select/address.str_id.sql +3 -3
  23. package/package.json +77 -77
  24. package/plugin.js +64 -64
  25. package/server/migrations/array_intersect.sql +13 -13
  26. package/server/migrations/cartocss.sql +27 -27
  27. package/server/migrations/group_list.sql +74 -74
  28. package/server/migrations/maps.sql +30 -30
  29. package/server/migrations/metadata.sql +415 -415
  30. package/server/migrations/ogc.sql +106 -106
  31. package/server/migrations/rasters.sql +265 -265
  32. package/server/migrations/services.sql +247 -247
  33. package/server/migrations/services_users_rel.sql +22 -22
  34. package/server/migrations/widgets.sql +20 -20
  35. package/server/plugins/crons.js +21 -21
  36. package/server/plugins/mapnik/funcs/checkRasterFile.js +107 -107
  37. package/server/plugins/mapnik/funcs/mapnik.js +151 -151
  38. package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
  39. package/server/plugins/mapnik/map.proto +437 -437
  40. package/server/plugins/vite.js +74 -74
  41. package/server/routes/cartocss/cartocss.route.js +31 -31
  42. package/server/routes/cartocss/cartocss.route.test.js +78 -78
  43. package/server/routes/cartocss/cartocss.schema.js +73 -73
  44. package/server/routes/cartocss/functions/add.cartocss.js +39 -39
  45. package/server/routes/cartocss/functions/get.cartocss.js +57 -57
  46. package/server/routes/gis/functions/checkXML.js +107 -107
  47. package/server/routes/gis/functions/dashboard.js +24 -24
  48. package/server/routes/gis/gis.route.js +26 -26
  49. package/server/routes/gis/gis.route.test.js +33 -33
  50. package/server/routes/map/functions/clearTiles.js +35 -35
  51. package/server/routes/map/functions/geojson.js +187 -187
  52. package/server/routes/map/functions/gis.convert.js +65 -65
  53. package/server/routes/map/functions/gis.icon.js +220 -220
  54. package/server/routes/map/functions/jsonData.js +206 -206
  55. package/server/routes/map/functions/layerList.js +102 -102
  56. package/server/routes/map/functions/map.js +122 -122
  57. package/server/routes/map/functions/mapCatalog.js +72 -72
  58. package/server/routes/map/functions/mapCatalogAttribute.js +53 -53
  59. package/server/routes/map/functions/mapFeatures.js +133 -133
  60. package/server/routes/map/functions/mapFormat.js +232 -232
  61. package/server/routes/map/functions/mapTiles.js +162 -162
  62. package/server/routes/map/functions/maps.js +15 -15
  63. package/server/routes/map/functions/marker_icon.js +43 -43
  64. package/server/routes/map/functions/parseGeoFile.js +85 -85
  65. package/server/routes/map/functions/pointHeight.js +51 -51
  66. package/server/routes/map/functions/vtile.js +174 -174
  67. package/server/routes/map/functions/vtile1.js +185 -185
  68. package/server/routes/map/map.route.js +280 -280
  69. package/server/routes/map/map.route.test.js +503 -503
  70. package/server/routes/map/map.schema.js +356 -356
  71. package/server/routes/map/pin/circle1.svg +76 -76
  72. package/server/routes/map/pin/circle2.svg +18 -18
  73. package/server/routes/map/pin/none.svg +12 -12
  74. package/server/routes/map/pin/pin.svg +14 -14
  75. package/server/routes/map/pin/pin1.svg +16 -16
  76. package/server/routes/map/pin/pin2.svg +7 -7
  77. package/server/routes/map/pin/pin3.svg +34 -34
  78. package/server/routes/map/pin/pin4.svg +14 -14
  79. package/server/routes/map/pin/pin5.svg +7 -7
  80. package/server/routes/map/pin/pin6.svg +12 -12
  81. package/server/routes/map/pin/pin7.svg +12 -12
  82. package/server/routes/mapnik/functions/cartoBounds.js +32 -32
  83. package/server/routes/mapnik/functions/clearTiles.js +103 -103
  84. package/server/routes/mapnik/functions/convertBoundToTile.js +27 -27
  85. package/server/routes/mapnik/functions/createXml.js +76 -76
  86. package/server/routes/mapnik/functions/createXmlMulti.js +72 -72
  87. package/server/routes/mapnik/functions/fileSearch.js +35 -35
  88. package/server/routes/mapnik/functions/fileStat.js +28 -28
  89. package/server/routes/mapnik/functions/pretile.js +138 -138
  90. package/server/routes/mapnik/functions/rasterInfo.js +66 -66
  91. package/server/routes/mapnik/functions/readDir.js +22 -22
  92. package/server/routes/mapnik/functions/rtile.js +164 -164
  93. package/server/routes/mapnik/functions/uploadRaster.js +152 -152
  94. package/server/routes/mapnik/functions/uploadXML.js +140 -140
  95. package/server/routes/mapnik/mapnik.route.js +102 -102
  96. package/server/routes/mapnik/mapnik.route.test.js +370 -370
  97. package/server/routes/mapnik/mapnik.schema.mjs +195 -195
  98. package/server/routes/mapnik.prefixless/functions/mapnikLogger.js +31 -31
  99. package/server/routes/mapnik.prefixless/functions/mapnikStat.js +21 -21
  100. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.js +20 -20
  101. package/server/routes/mapnik.prefixless/mapnik.prefixless.route.test.js +91 -91
  102. package/server/routes/mapnik.prefixless/mapnik.prefixless.schema.mjs +27 -27
  103. package/server/routes/maps/functions/add.map.js +42 -42
  104. package/server/routes/maps/functions/del.map.js +17 -17
  105. package/server/routes/maps/functions/get.map.js +119 -119
  106. package/server/routes/maps/maps.route.js +58 -58
  107. package/server/routes/maps/maps.route.test.js +231 -231
  108. package/server/routes/maps/maps.schema.js +9 -9
  109. package/server/routes/metadata/functions/editMetadata.js +35 -35
  110. package/server/routes/metadata/functions/metadataXML.js +19 -19
  111. package/server/routes/metadata/metadata.route.js +26 -26
  112. package/server/routes/metadata/metadata.route.test.js +46 -46
  113. package/server/routes/metadata/metadata.schema.js +53 -53
  114. package/server/routes/ogc/functions/map.info.point.js +117 -117
  115. package/server/routes/ogc/ogc.route.js +21 -21
  116. package/server/routes/ogc/ogc.route.test.js +53 -53
  117. package/server/routes/ogc/ogc.schema.js +16 -16
  118. package/server/routes/permissions/functions/catalog.permissions.edit.js +20 -20
  119. package/server/routes/permissions/functions/catalog.permissions.js +12 -12
  120. package/server/routes/permissions/functions/get.permissions.js +59 -59
  121. package/server/routes/permissions/functions/gis.catalog.js +80 -80
  122. package/server/routes/permissions/permissions.route.js +35 -35
  123. package/server/routes/permissions/permissions.route.test.js +35 -35
  124. package/server/routes/permissions/permissions.schema.js +43 -43
  125. package/server/routes/registers/functions/add.registry.js +37 -37
  126. package/server/routes/registers/functions/classifiers.js +100 -100
  127. package/server/routes/registers/functions/columns.js +3 -3
  128. package/server/routes/registers/functions/content.type.js +9 -9
  129. package/server/routes/registers/functions/del.registry.js +14 -14
  130. package/server/routes/registers/functions/get.info.js +93 -93
  131. package/server/routes/registers/functions/getTableColumnMeta.js +131 -0
  132. package/server/routes/registers/functions/gis.export.js +159 -159
  133. package/server/routes/registers/functions/gis.registry.js +71 -71
  134. package/server/routes/registers/functions/gis.registry.list.js +61 -61
  135. package/server/routes/registers/functions/gis.suggest.js +284 -0
  136. package/server/routes/registers/functions/handleRegistryRequest.js +167 -147
  137. package/server/routes/registers/functions/map.registry.js +87 -87
  138. package/server/routes/registers/registers.route.js +91 -80
  139. package/server/routes/registers/registers.route.test.js +144 -144
  140. package/server/routes/registers/registers.schema.js +270 -246
  141. package/server/routes/root.mjs +3 -3
  142. package/server/routes/services/functions/add.service.js +62 -62
  143. package/server/routes/services/functions/create.route.js +93 -93
  144. package/server/routes/services/functions/del.service.js +12 -12
  145. package/server/routes/services/functions/get.layer.geom.js +27 -27
  146. package/server/routes/services/functions/get.service.users.js +76 -76
  147. package/server/routes/services/functions/get.services.col.js +34 -34
  148. package/server/routes/services/functions/get.services.js +89 -89
  149. package/server/routes/services/functions/legend.auto.js +77 -77
  150. package/server/routes/services/services.route.js +76 -76
  151. package/server/routes/services/services.route.test.js +167 -167
  152. package/server/routes/services/services.schema.js +285 -278
  153. package/server/routes/widgets/functions/add.widget.js +38 -38
  154. package/server/routes/widgets/functions/del.widget.js +17 -17
  155. package/server/routes/widgets/functions/get.widget.js +41 -41
  156. package/server/routes/widgets/widgets.route.js +61 -61
  157. package/server/routes/widgets/widgets.route.test.js +144 -144
  158. package/server/routes/widgets/widgets.schema.js +24 -24
  159. package/server/shared/listFiles.js +14 -14
  160. package/utils.js +13 -13
@@ -1,220 +1,220 @@
1
- import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
-
5
- import * as solidIcons from '@fortawesome/free-solid-svg-icons';
6
- import sharp from 'sharp';
7
- import { BadRequestError, NotFoundError } from '@opengis/fastify-table/errors.js';
8
-
9
- const iconFilenamePattern = /^([a-z][a-z0-9]*)-(s|m|l|xl)-(fa|ar)-([a-z0-9-]+)\+([a-f0-9]{3,8})\.(png|svg)$/i;
10
- const validColorLengths = new Set([3, 4, 6, 8]);
11
-
12
- const iconSizeByCode = {
13
- s: 24,
14
- m: 32,
15
- l: 48,
16
- xl: 64,
17
- };
18
-
19
- const contentTypeByFormat = {
20
- png: 'image/png',
21
- svg: 'image/svg+xml',
22
- };
23
-
24
- // Templates with a transparent or white center can safely recolor their background.
25
- const pinConfig = {
26
- pin: { x: 98, y: 99, iconSize: 110 },
27
- pin1: { x: 237, y: 205, iconSize: 200 },
28
- pin2: {
29
- x: 195, y: 185, iconSize: 210, recolorBackground: true,
30
- },
31
- pin3: {
32
- x: 197, y: 205, iconSize: 215, recolorBackground: true,
33
- },
34
- pin4: {
35
- x: 265, y: 230, iconSize: 250, recolorBackground: true,
36
- },
37
- pin5: {
38
- x: 205, y: 203, iconSize: 245, recolorBackground: true,
39
- },
40
- pin6: {
41
- x: 220, y: 215, iconSize: 281, recolorBackground: true,
42
- },
43
- pin7: {
44
- x: 220, y: 215, iconSize: 281, recolorBackground: true,
45
- },
46
- circle1: { x: 321, y: 308, iconSize: 260 },
47
- circle2: { x: 251, y: 248, iconSize: 300 },
48
- none: { x: 250, y: 250, iconSize: 300 },
49
- };
50
-
51
- const dirname = path.dirname(fileURLToPath(import.meta.url));
52
- const pinDirectory = path.join(dirname, '../pin');
53
- const iconDirectory = path.join(process.cwd(), 'log', 'icon');
54
- const iconDirectoryReady = mkdir(iconDirectory, { recursive: true });
55
-
56
- function parseIconFilename(filename) {
57
- const match = iconFilenamePattern.exec(filename);
58
- if (!match) return null;
59
-
60
- const [, pinName, sizeCode, iconType, iconValue, hexColor, format] = match;
61
- if (!validColorLengths.has(hexColor.length)) return null;
62
-
63
- return {
64
- filename: filename.toLowerCase(),
65
- pinName: pinName.toLowerCase(),
66
- size: iconSizeByCode[sizeCode.toLowerCase()],
67
- iconType: iconType.toLowerCase(),
68
- iconValue: iconType.toLowerCase() === 'fa'
69
- ? iconValue.toLowerCase()
70
- : iconValue.toUpperCase(),
71
- color: `#${hexColor}`,
72
- format: format.toLowerCase(),
73
- };
74
- }
75
-
76
- function findIcon(iconName) {
77
- const exportName = `fa${iconName.replace(/(^|-)([a-z0-9])/g, (_, __, char) => char.toUpperCase())}`;
78
- const exportedIcon = solidIcons[exportName];
79
-
80
- if (exportedIcon?.prefix === 'fas') return exportedIcon;
81
-
82
- return Object.values(solidIcons).find(icon => (
83
- icon?.prefix === 'fas' && icon.iconName === iconName
84
- ));
85
- }
86
-
87
- async function readFileIfExists(filePath, encoding) {
88
- try {
89
- return await readFile(filePath, encoding);
90
- }
91
- catch (error) {
92
- if (error.code !== 'ENOENT') throw error;
93
- return null;
94
- }
95
- }
96
-
97
- function getSvgAttribute(svg, attribute, fallback) {
98
- const match = new RegExp(`\\b${attribute}="([0-9.]+)"`, 'i').exec(svg);
99
- return match ? Number(match[1]) : fallback;
100
- }
101
-
102
- function getPinPlacement(pinName, width, height) {
103
- return pinConfig[pinName] || {
104
- x: width / 2,
105
- y: height / 2,
106
- iconSize: Math.min(width, height) * 0.55,
107
- };
108
- }
109
-
110
- function createFontAwesomeSvg(icon, placement, color) {
111
- const [width, height, , , pathData] = icon.icon;
112
- const paths = Array.isArray(pathData) ? pathData : [pathData];
113
- const x = placement.x - placement.iconSize / 2;
114
- const y = placement.y - placement.iconSize / 2;
115
-
116
- return `<svg data-gis-icon-layer="foreground" x="${x}" y="${y}" width="${placement.iconSize}" height="${placement.iconSize}" viewBox="0 0 ${width} ${height}" fill="${color}">
117
- ${paths.map(iconPath => `<path d="${iconPath}"/>`).join('')}
118
- </svg>`;
119
- }
120
-
121
- function createSymbolSvg(symbol, placement, color) {
122
- const fontSize = Math.round(placement.iconSize * 0.75);
123
-
124
- return `<text data-gis-icon-layer="foreground" x="${placement.x}" y="${placement.y}" fill="${color}" font-family="Arial, sans-serif" font-size="${fontSize}" font-weight="700" text-anchor="middle" dominant-baseline="middle">${symbol}</text>`;
125
- }
126
-
127
- function createForegroundSvg(options, placement) {
128
- if (options.iconType === 'ar') {
129
- return createSymbolSvg(options.iconValue, placement, options.color);
130
- }
131
-
132
- const icon = findIcon(options.iconValue);
133
- return icon ? createFontAwesomeSvg(icon, placement, options.color) : null;
134
- }
135
-
136
- function setSvgViewport(svg, size, width, height) {
137
- return svg.replace(/<svg\b([^>]*)>/i, (_, attributes) => {
138
- const rootAttributes = attributes
139
- .replace(/\swidth="[^"]*"/i, '')
140
- .replace(/\sheight="[^"]*"/i, '')
141
- .replace(/\sviewBox="[^"]*"/i, '');
142
-
143
- return `<svg${rootAttributes} width="${size}" height="${size}" viewBox="0 0 ${width} ${height}">`;
144
- });
145
- }
146
-
147
- async function createPinSvg({
148
- pinName,
149
- size,
150
- color,
151
- ...iconOptions
152
- }) {
153
- const templatePath = path.join(pinDirectory, `${pinName}.svg`);
154
- const template = await readFileIfExists(templatePath, 'utf8');
155
- if (!template) return null;
156
-
157
- const width = getSvgAttribute(template, 'width', 512);
158
- const height = getSvgAttribute(template, 'height', 512);
159
- const placement = getPinPlacement(pinName, width, height);
160
- const coloredTemplate = placement.recolorBackground
161
- ? template.replace(/#ff0000/gi, color)
162
- : template;
163
- const svg = setSvgViewport(coloredTemplate, size, width, height);
164
- const foreground = createForegroundSvg({ ...iconOptions, color }, placement);
165
- if (!foreground) return null;
166
-
167
- return svg.replace(/<\/svg>\s*$/, `${foreground}</svg>`);
168
- }
169
-
170
- async function createIcon(options) {
171
- const svg = await createPinSvg({
172
- ...options,
173
- });
174
- if (!svg) return null;
175
- if (options.format === 'svg') return Buffer.from(svg);
176
-
177
- return sharp(Buffer.from(svg)).png().toBuffer();
178
- }
179
-
180
- async function getIcon(options, nocache = false) {
181
- await iconDirectoryReady;
182
-
183
- const iconPath = path.join(iconDirectory, options.filename);
184
- if (!nocache) {
185
- const cachedIcon = await readFileIfExists(iconPath);
186
- if (cachedIcon) return cachedIcon;
187
- }
188
-
189
- const icon = await createIcon(options);
190
- if (!icon) return null;
191
-
192
- await writeFile(iconPath, icon);
193
- return icon;
194
- }
195
-
196
- export default async function gisIconApi({ name, nocache }) {
197
- if (!name) {
198
- throw BadRequestError('not enough params: name');
199
- }
200
-
201
- const options = parseIconFilename(name);
202
-
203
- if (!options) {
204
- throw BadRequestError('invalid icon name');
205
- }
206
-
207
- const image = await getIcon(options, nocache);
208
-
209
- if (!image) {
210
- throw NotFoundError('icon not found');
211
- }
212
-
213
- return {
214
- headers: {
215
- 'Content-Type': contentTypeByFormat[options.format],
216
- 'Cache-Control': nocache ? 'no-cache' : 'public, max-age=31536000, immutable'
217
- },
218
- data: image
219
- }
220
- }
1
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ import * as solidIcons from '@fortawesome/free-solid-svg-icons';
6
+ import sharp from 'sharp';
7
+ import { BadRequestError, NotFoundError } from '@opengis/fastify-table/errors.js';
8
+
9
+ const iconFilenamePattern = /^([a-z][a-z0-9]*)-(s|m|l|xl)-(fa|ar)-([a-z0-9-]+)\+([a-f0-9]{3,8})\.(png|svg)$/i;
10
+ const validColorLengths = new Set([3, 4, 6, 8]);
11
+
12
+ const iconSizeByCode = {
13
+ s: 24,
14
+ m: 32,
15
+ l: 48,
16
+ xl: 64,
17
+ };
18
+
19
+ const contentTypeByFormat = {
20
+ png: 'image/png',
21
+ svg: 'image/svg+xml',
22
+ };
23
+
24
+ // Templates with a transparent or white center can safely recolor their background.
25
+ const pinConfig = {
26
+ pin: { x: 98, y: 99, iconSize: 110 },
27
+ pin1: { x: 237, y: 205, iconSize: 200 },
28
+ pin2: {
29
+ x: 195, y: 185, iconSize: 210, recolorBackground: true,
30
+ },
31
+ pin3: {
32
+ x: 197, y: 205, iconSize: 215, recolorBackground: true,
33
+ },
34
+ pin4: {
35
+ x: 265, y: 230, iconSize: 250, recolorBackground: true,
36
+ },
37
+ pin5: {
38
+ x: 205, y: 203, iconSize: 245, recolorBackground: true,
39
+ },
40
+ pin6: {
41
+ x: 220, y: 215, iconSize: 281, recolorBackground: true,
42
+ },
43
+ pin7: {
44
+ x: 220, y: 215, iconSize: 281, recolorBackground: true,
45
+ },
46
+ circle1: { x: 321, y: 308, iconSize: 260 },
47
+ circle2: { x: 251, y: 248, iconSize: 300 },
48
+ none: { x: 250, y: 250, iconSize: 300 },
49
+ };
50
+
51
+ const dirname = path.dirname(fileURLToPath(import.meta.url));
52
+ const pinDirectory = path.join(dirname, '../pin');
53
+ const iconDirectory = path.join(process.cwd(), 'log', 'icon');
54
+ const iconDirectoryReady = mkdir(iconDirectory, { recursive: true });
55
+
56
+ function parseIconFilename(filename) {
57
+ const match = iconFilenamePattern.exec(filename);
58
+ if (!match) return null;
59
+
60
+ const [, pinName, sizeCode, iconType, iconValue, hexColor, format] = match;
61
+ if (!validColorLengths.has(hexColor.length)) return null;
62
+
63
+ return {
64
+ filename: filename.toLowerCase(),
65
+ pinName: pinName.toLowerCase(),
66
+ size: iconSizeByCode[sizeCode.toLowerCase()],
67
+ iconType: iconType.toLowerCase(),
68
+ iconValue: iconType.toLowerCase() === 'fa'
69
+ ? iconValue.toLowerCase()
70
+ : iconValue.toUpperCase(),
71
+ color: `#${hexColor}`,
72
+ format: format.toLowerCase(),
73
+ };
74
+ }
75
+
76
+ function findIcon(iconName) {
77
+ const exportName = `fa${iconName.replace(/(^|-)([a-z0-9])/g, (_, __, char) => char.toUpperCase())}`;
78
+ const exportedIcon = solidIcons[exportName];
79
+
80
+ if (exportedIcon?.prefix === 'fas') return exportedIcon;
81
+
82
+ return Object.values(solidIcons).find(icon => (
83
+ icon?.prefix === 'fas' && icon.iconName === iconName
84
+ ));
85
+ }
86
+
87
+ async function readFileIfExists(filePath, encoding) {
88
+ try {
89
+ return await readFile(filePath, encoding);
90
+ }
91
+ catch (error) {
92
+ if (error.code !== 'ENOENT') throw error;
93
+ return null;
94
+ }
95
+ }
96
+
97
+ function getSvgAttribute(svg, attribute, fallback) {
98
+ const match = new RegExp(`\\b${attribute}="([0-9.]+)"`, 'i').exec(svg);
99
+ return match ? Number(match[1]) : fallback;
100
+ }
101
+
102
+ function getPinPlacement(pinName, width, height) {
103
+ return pinConfig[pinName] || {
104
+ x: width / 2,
105
+ y: height / 2,
106
+ iconSize: Math.min(width, height) * 0.55,
107
+ };
108
+ }
109
+
110
+ function createFontAwesomeSvg(icon, placement, color) {
111
+ const [width, height, , , pathData] = icon.icon;
112
+ const paths = Array.isArray(pathData) ? pathData : [pathData];
113
+ const x = placement.x - placement.iconSize / 2;
114
+ const y = placement.y - placement.iconSize / 2;
115
+
116
+ return `<svg data-gis-icon-layer="foreground" x="${x}" y="${y}" width="${placement.iconSize}" height="${placement.iconSize}" viewBox="0 0 ${width} ${height}" fill="${color}">
117
+ ${paths.map(iconPath => `<path d="${iconPath}"/>`).join('')}
118
+ </svg>`;
119
+ }
120
+
121
+ function createSymbolSvg(symbol, placement, color) {
122
+ const fontSize = Math.round(placement.iconSize * 0.75);
123
+
124
+ return `<text data-gis-icon-layer="foreground" x="${placement.x}" y="${placement.y}" fill="${color}" font-family="Arial, sans-serif" font-size="${fontSize}" font-weight="700" text-anchor="middle" dominant-baseline="middle">${symbol}</text>`;
125
+ }
126
+
127
+ function createForegroundSvg(options, placement) {
128
+ if (options.iconType === 'ar') {
129
+ return createSymbolSvg(options.iconValue, placement, options.color);
130
+ }
131
+
132
+ const icon = findIcon(options.iconValue);
133
+ return icon ? createFontAwesomeSvg(icon, placement, options.color) : null;
134
+ }
135
+
136
+ function setSvgViewport(svg, size, width, height) {
137
+ return svg.replace(/<svg\b([^>]*)>/i, (_, attributes) => {
138
+ const rootAttributes = attributes
139
+ .replace(/\swidth="[^"]*"/i, '')
140
+ .replace(/\sheight="[^"]*"/i, '')
141
+ .replace(/\sviewBox="[^"]*"/i, '');
142
+
143
+ return `<svg${rootAttributes} width="${size}" height="${size}" viewBox="0 0 ${width} ${height}">`;
144
+ });
145
+ }
146
+
147
+ async function createPinSvg({
148
+ pinName,
149
+ size,
150
+ color,
151
+ ...iconOptions
152
+ }) {
153
+ const templatePath = path.join(pinDirectory, `${pinName}.svg`);
154
+ const template = await readFileIfExists(templatePath, 'utf8');
155
+ if (!template) return null;
156
+
157
+ const width = getSvgAttribute(template, 'width', 512);
158
+ const height = getSvgAttribute(template, 'height', 512);
159
+ const placement = getPinPlacement(pinName, width, height);
160
+ const coloredTemplate = placement.recolorBackground
161
+ ? template.replace(/#ff0000/gi, color)
162
+ : template;
163
+ const svg = setSvgViewport(coloredTemplate, size, width, height);
164
+ const foreground = createForegroundSvg({ ...iconOptions, color }, placement);
165
+ if (!foreground) return null;
166
+
167
+ return svg.replace(/<\/svg>\s*$/, `${foreground}</svg>`);
168
+ }
169
+
170
+ async function createIcon(options) {
171
+ const svg = await createPinSvg({
172
+ ...options,
173
+ });
174
+ if (!svg) return null;
175
+ if (options.format === 'svg') return Buffer.from(svg);
176
+
177
+ return sharp(Buffer.from(svg)).png().toBuffer();
178
+ }
179
+
180
+ async function getIcon(options, nocache = false) {
181
+ await iconDirectoryReady;
182
+
183
+ const iconPath = path.join(iconDirectory, options.filename);
184
+ if (!nocache) {
185
+ const cachedIcon = await readFileIfExists(iconPath);
186
+ if (cachedIcon) return cachedIcon;
187
+ }
188
+
189
+ const icon = await createIcon(options);
190
+ if (!icon) return null;
191
+
192
+ await writeFile(iconPath, icon);
193
+ return icon;
194
+ }
195
+
196
+ export default async function gisIconApi({ name, nocache }) {
197
+ if (!name) {
198
+ throw BadRequestError('not enough params: name');
199
+ }
200
+
201
+ const options = parseIconFilename(name);
202
+
203
+ if (!options) {
204
+ throw BadRequestError('invalid icon name');
205
+ }
206
+
207
+ const image = await getIcon(options, nocache);
208
+
209
+ if (!image) {
210
+ throw NotFoundError('icon not found');
211
+ }
212
+
213
+ return {
214
+ headers: {
215
+ 'Content-Type': contentTypeByFormat[options.format],
216
+ 'Cache-Control': nocache ? 'no-cache' : 'public, max-age=31536000, immutable'
217
+ },
218
+ data: image
219
+ }
220
+ }