Skip to content

Commit 754cf84

Browse files
committed
refactor
1 parent 32c5a5d commit 754cf84

5 files changed

Lines changed: 196 additions & 186 deletions

File tree

dev/main.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ const state = {
7272
stats: '',
7373
};
7474

75-
const classificationColors: Record<string, string> = {};
75+
const classificationHexColors: Record<string, string> = {};
7676
for (const [code, rgb] of Object.entries(DEFAULT_CLASSIFICATION_COLORS)) {
77-
const label = CLASSIFICATION_LABELS[Number(code)] ?? `Class ${code}`;
78-
classificationColors[`${code}: ${label}`] = rgbToHex(...rgb);
77+
classificationHexColors[code] = rgbToHex(...rgb);
7978
}
8079

8180
// --- Map ---
@@ -109,9 +108,8 @@ function getClassificationColorsMap(): Record<
109108
[number, number, number]
110109
> {
111110
const result: Record<number, [number, number, number]> = {};
112-
for (const [key, hex] of Object.entries(classificationColors)) {
113-
const code = Number(key.split(':')[0]);
114-
result[code] = hexToRgb(hex);
111+
for (const [code, hex] of Object.entries(classificationHexColors)) {
112+
result[Number(code)] = hexToRgb(hex);
115113
}
116114
return result;
117115
}
@@ -216,8 +214,13 @@ edl
216214
});
217215

218216
const classificationFolder = gui.addFolder('Classification Colors');
219-
for (const key of Object.keys(classificationColors)) {
220-
classificationFolder.addColor(classificationColors, key).onChange(loadCopc);
217+
for (const code of Object.keys(classificationHexColors)) {
218+
const num = Number(code);
219+
const label = CLASSIFICATION_LABELS[num] ?? `Class ${code}`;
220+
classificationFolder
221+
.addColor(classificationHexColors, code)
222+
.name(`${code}: ${label}`)
223+
.onChange(loadCopc);
221224
}
222225
classificationFolder.show(state.colorMode === 'classification');
223226

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "maplibre-copc-layer",
33
"type": "module",
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/Kanahiro/maplibre-copc-layer.git"

src/constants.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const DEFAULT_CLASSIFICATION_COLORS: Record<number, [number, number, number]> = {
2+
0: [0.5, 0.5, 0.5], // Never Classified
3+
1: [0.7, 0.7, 0.7], // Unclassified
4+
2: [0.6, 0.4, 0.2], // Ground
5+
3: [0.5, 0.8, 0.5], // Low Vegetation
6+
4: [0.2, 0.7, 0.2], // Medium Vegetation
7+
5: [0.0, 0.4, 0.0], // High Vegetation
8+
6: [1.0, 0.2, 0.2], // Building
9+
7: [0.3, 0.3, 0.3], // Low Point (noise)
10+
8: [0.6, 0.3, 0.8], // Model Key-point
11+
9: [0.2, 0.4, 1.0], // Water
12+
10: [1.0, 0.6, 0.0], // Rail
13+
11: [0.9, 0.9, 0.3], // Road Surface
14+
12: [0.0, 0.8, 0.8], // Overlap
15+
17: [0.9, 0.5, 0.4], // Bridge Deck
16+
18: [0.5, 0.0, 0.0], // High Noise
17+
};

src/copclayer.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import pointsFragmentShader from './shaders/points.frag.glsl';
66
import edlVertexShader from './shaders/edl.vert.glsl';
77
import edlFragmentShader from './shaders/edl.frag.glsl';
88
import CopcWorker from './worker/index.ts?worker&inline';
9-
import lazPerfWasmUrl from '../vendor/laz-perf/js/src/laz-perf.wasm?url';
9+
import { DEFAULT_CLASSIFICATION_COLORS } from './constants';
1010

1111
const EARTH_CIRCUMFERENCE = 2 * Math.PI * 6378137.0;
1212
const DEG2RAD = Math.PI / 180;
@@ -36,7 +36,7 @@ type ResolvedOptions = Required<CopcLayerOptions>;
3636
const DEFAULT_OPTIONS: ResolvedOptions = {
3737
pointSize: 6,
3838
colorMode: 'rgb',
39-
classificationColors: {},
39+
classificationColors: { ...DEFAULT_CLASSIFICATION_COLORS },
4040
maxCacheSize: 100,
4141
sseThreshold: 8,
4242
depthTest: true,
@@ -314,8 +314,6 @@ export class CopcLayer implements maplibregl.CustomLayerInterface {
314314
options: {
315315
colorMode: this.options.colorMode,
316316
classificationColors: this.options.classificationColors,
317-
maxCacheSize: this.options.maxCacheSize,
318-
wasmPath: lazPerfWasmUrl,
319317
},
320318
});
321319

0 commit comments

Comments
 (0)