@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.
- package/README.md +181 -181
- package/dist/{CardIcon-c1Q2M3wQ.js → CardIcon-CMRD1LLh.js} +1 -1
- package/dist/{EntityTablePage-B5gpkH4S.js → EntityTablePage-XNNCltAN.js} +2 -2
- package/dist/{ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-DnGSvmMU.js → ExtentOutlineLayer.vue_vue_type_script_setup_true_lang-BqUjKTDY.js} +1 -1
- package/dist/{HeaderActions.vue_vue_type_script_setup_true_lang-C2B61JP6.js → HeaderActions.vue_vue_type_script_setup_true_lang-BXQ3hKwa.js} +1 -1
- package/dist/{MapSettings-6-Xru5Q8.js → MapSettings-P3h-vHn3.js} +2 -2
- package/dist/{RastersTablePage-CXNOcTy-.js → RastersTablePage-DnhGZLiH.js} +2 -2
- package/dist/{cartocss-BFVqWvfP.js → cartocss-BkrOeQg4.js} +6 -6
- package/dist/{import-utils-uxk4LdUJ.js → import-utils-BCATsbB5.js} +1 -1
- package/dist/{index-CahlV-Xs.js → index-cUagVqgA.js} +39 -39
- package/dist/index.css +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.cjs +5 -5
- package/dist/{raster-CEi56f0P.js → raster-CP0tUp3j.js} +3 -3
- package/dist/{register-NFAGBNa3.js → register-Cr-uQcby.js} +3 -3
- package/dist/{service-BYspag8U.js → service-DwJaKrOd.js} +6 -6
- package/dist/{vs-datatable-CHcBr6zy.js → vs-datatable-B9WoVk-b.js} +2 -2
- package/module/gis/cls/service_type.json +42 -42
- package/module/gis/form/gis.registers.form.json +127 -127
- package/module/test/map/addr.json +302 -302
- package/module/test/map/addr1.yml +23 -23
- package/module/test/select/address.str_id.sql +3 -3
- package/package.json +77 -77
- package/plugin.js +64 -64
- package/server/migrations/array_intersect.sql +13 -13
- package/server/migrations/cartocss.sql +27 -27
- package/server/migrations/group_list.sql +74 -74
- package/server/migrations/maps.sql +30 -30
- package/server/migrations/metadata.sql +415 -415
- package/server/migrations/ogc.sql +106 -106
- package/server/migrations/rasters.sql +265 -265
- package/server/migrations/services.sql +247 -247
- package/server/migrations/services_users_rel.sql +22 -22
- package/server/migrations/widgets.sql +20 -20
- package/server/plugins/crons.js +21 -21
- package/server/plugins/mapnik/funcs/checkRasterFile.js +107 -107
- package/server/plugins/mapnik/funcs/mapnik.js +151 -151
- package/server/plugins/mapnik/funcs/rootFolder.mjs +8 -8
- package/server/plugins/mapnik/map.proto +437 -437
- package/server/plugins/vite.js +74 -74
- package/server/routes/cartocss/cartocss.route.js +31 -31
- package/server/routes/cartocss/cartocss.route.test.js +78 -78
- package/server/routes/cartocss/cartocss.schema.js +73 -73
- package/server/routes/cartocss/functions/add.cartocss.js +39 -39
- package/server/routes/cartocss/functions/get.cartocss.js +57 -57
- package/server/routes/gis/functions/checkXML.js +107 -107
- package/server/routes/gis/functions/dashboard.js +24 -24
- package/server/routes/gis/gis.route.js +26 -26
- package/server/routes/gis/gis.route.test.js +33 -33
- package/server/routes/map/functions/clearTiles.js +35 -35
- package/server/routes/map/functions/geojson.js +187 -187
- package/server/routes/map/functions/gis.convert.js +65 -65
- package/server/routes/map/functions/gis.icon.js +220 -220
- package/server/routes/map/functions/jsonData.js +206 -206
- package/server/routes/map/functions/layerList.js +102 -102
- package/server/routes/map/functions/map.js +122 -122
- package/server/routes/map/functions/mapCatalog.js +72 -72
- package/server/routes/map/functions/mapCatalogAttribute.js +53 -53
- package/server/routes/map/functions/mapFeatures.js +133 -133
- package/server/routes/map/functions/mapFormat.js +232 -232
- package/server/routes/map/functions/mapTiles.js +162 -162
- package/server/routes/map/functions/maps.js +15 -15
- package/server/routes/map/functions/marker_icon.js +43 -43
- package/server/routes/map/functions/parseGeoFile.js +85 -85
- package/server/routes/map/functions/pointHeight.js +51 -51
- package/server/routes/map/functions/vtile.js +174 -174
- package/server/routes/map/functions/vtile1.js +185 -185
- package/server/routes/map/map.route.js +280 -280
- package/server/routes/map/map.route.test.js +503 -503
- package/server/routes/map/map.schema.js +356 -356
- package/server/routes/map/pin/circle1.svg +76 -76
- package/server/routes/map/pin/circle2.svg +18 -18
- package/server/routes/map/pin/none.svg +12 -12
- package/server/routes/map/pin/pin.svg +14 -14
- package/server/routes/map/pin/pin1.svg +16 -16
- package/server/routes/map/pin/pin2.svg +7 -7
- package/server/routes/map/pin/pin3.svg +34 -34
- package/server/routes/map/pin/pin4.svg +14 -14
- package/server/routes/map/pin/pin5.svg +7 -7
- package/server/routes/map/pin/pin6.svg +12 -12
- package/server/routes/map/pin/pin7.svg +12 -12
- package/server/routes/mapnik/functions/cartoBounds.js +32 -32
- package/server/routes/mapnik/functions/clearTiles.js +103 -103
- package/server/routes/mapnik/functions/convertBoundToTile.js +27 -27
- package/server/routes/mapnik/functions/createXml.js +76 -76
- package/server/routes/mapnik/functions/createXmlMulti.js +72 -72
- package/server/routes/mapnik/functions/fileSearch.js +35 -35
- package/server/routes/mapnik/functions/fileStat.js +28 -28
- package/server/routes/mapnik/functions/pretile.js +138 -138
- package/server/routes/mapnik/functions/rasterInfo.js +66 -66
- package/server/routes/mapnik/functions/readDir.js +22 -22
- package/server/routes/mapnik/functions/rtile.js +164 -164
- package/server/routes/mapnik/functions/uploadRaster.js +152 -152
- package/server/routes/mapnik/functions/uploadXML.js +140 -140
- package/server/routes/mapnik/mapnik.route.js +102 -102
- package/server/routes/mapnik/mapnik.route.test.js +370 -370
- package/server/routes/mapnik/mapnik.schema.mjs +195 -195
- package/server/routes/mapnik.prefixless/functions/mapnikLogger.js +31 -31
- package/server/routes/mapnik.prefixless/functions/mapnikStat.js +21 -21
- package/server/routes/mapnik.prefixless/mapnik.prefixless.route.js +20 -20
- package/server/routes/mapnik.prefixless/mapnik.prefixless.route.test.js +91 -91
- package/server/routes/mapnik.prefixless/mapnik.prefixless.schema.mjs +27 -27
- package/server/routes/maps/functions/add.map.js +42 -42
- package/server/routes/maps/functions/del.map.js +17 -17
- package/server/routes/maps/functions/get.map.js +119 -119
- package/server/routes/maps/maps.route.js +58 -58
- package/server/routes/maps/maps.route.test.js +231 -231
- package/server/routes/maps/maps.schema.js +9 -9
- package/server/routes/metadata/functions/editMetadata.js +35 -35
- package/server/routes/metadata/functions/metadataXML.js +19 -19
- package/server/routes/metadata/metadata.route.js +26 -26
- package/server/routes/metadata/metadata.route.test.js +46 -46
- package/server/routes/metadata/metadata.schema.js +53 -53
- package/server/routes/ogc/functions/map.info.point.js +117 -117
- package/server/routes/ogc/ogc.route.js +21 -21
- package/server/routes/ogc/ogc.route.test.js +53 -53
- package/server/routes/ogc/ogc.schema.js +16 -16
- package/server/routes/permissions/functions/catalog.permissions.edit.js +20 -20
- package/server/routes/permissions/functions/catalog.permissions.js +12 -12
- package/server/routes/permissions/functions/get.permissions.js +59 -59
- package/server/routes/permissions/functions/gis.catalog.js +80 -80
- package/server/routes/permissions/permissions.route.js +35 -35
- package/server/routes/permissions/permissions.route.test.js +35 -35
- package/server/routes/permissions/permissions.schema.js +43 -43
- package/server/routes/registers/functions/add.registry.js +37 -37
- package/server/routes/registers/functions/classifiers.js +100 -100
- package/server/routes/registers/functions/columns.js +3 -3
- package/server/routes/registers/functions/content.type.js +9 -9
- package/server/routes/registers/functions/del.registry.js +14 -14
- package/server/routes/registers/functions/get.info.js +93 -93
- package/server/routes/registers/functions/getTableColumnMeta.js +131 -0
- package/server/routes/registers/functions/gis.export.js +159 -159
- package/server/routes/registers/functions/gis.registry.js +71 -71
- package/server/routes/registers/functions/gis.registry.list.js +61 -61
- package/server/routes/registers/functions/gis.suggest.js +284 -0
- package/server/routes/registers/functions/handleRegistryRequest.js +167 -147
- package/server/routes/registers/functions/map.registry.js +87 -87
- package/server/routes/registers/registers.route.js +91 -80
- package/server/routes/registers/registers.route.test.js +144 -144
- package/server/routes/registers/registers.schema.js +270 -246
- package/server/routes/root.mjs +3 -3
- package/server/routes/services/functions/add.service.js +62 -62
- package/server/routes/services/functions/create.route.js +93 -93
- package/server/routes/services/functions/del.service.js +12 -12
- package/server/routes/services/functions/get.layer.geom.js +27 -27
- package/server/routes/services/functions/get.service.users.js +76 -76
- package/server/routes/services/functions/get.services.col.js +34 -34
- package/server/routes/services/functions/get.services.js +89 -89
- package/server/routes/services/functions/legend.auto.js +77 -77
- package/server/routes/services/services.route.js +76 -76
- package/server/routes/services/services.route.test.js +167 -167
- package/server/routes/services/services.schema.js +285 -278
- package/server/routes/widgets/functions/add.widget.js +38 -38
- package/server/routes/widgets/functions/del.widget.js +17 -17
- package/server/routes/widgets/functions/get.widget.js +41 -41
- package/server/routes/widgets/widgets.route.js +61 -61
- package/server/routes/widgets/widgets.route.test.js +144 -144
- package/server/routes/widgets/widgets.schema.js +24 -24
- package/server/shared/listFiles.js +14 -14
- 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
|
+
}
|