83 lines
3.2 KiB
JavaScript
83 lines
3.2 KiB
JavaScript
'use strict';
|
|
|
|
// The compiler's layer registry is the single source of truth for published
|
|
// GeoJSON files and the Blender-facing manifest. Keep rendering details limited
|
|
// to material slot names; the host owns the actual material definitions.
|
|
const LAYER_REGISTRY = Object.freeze([
|
|
{ key: 'roadSurface', source: 'road_surface', role: 'surface', materialLayer: 'road_surface' },
|
|
{ key: 'edgeLines', source: 'edge_lines', role: 'marking', materialLayer: 'lane_separators' },
|
|
{
|
|
key: 'intersectionSurface',
|
|
source: 'intersection_surface',
|
|
role: 'surface',
|
|
materialLayer: 'intersection_surface',
|
|
},
|
|
{ key: 'sidewalkSurface', source: 'sidewalk_surface', role: 'surface', materialLayer: 'sidewalks' },
|
|
{
|
|
key: 'laneSeparators',
|
|
source: 'lane_separators',
|
|
role: 'marking',
|
|
materialLayer: 'lane_separators',
|
|
splitBy: {
|
|
prop: 'color',
|
|
cases: [
|
|
{ match: 'yellow', material: 'native_lane_separator_yellow' },
|
|
{ default: true, material: 'lane_separators' },
|
|
],
|
|
},
|
|
},
|
|
{
|
|
key: 'centerLines',
|
|
source: 'center_lines',
|
|
role: 'marking',
|
|
materialLayer: 'center_lines',
|
|
splitBy: {
|
|
prop: 'color',
|
|
cases: [
|
|
{ match: 'white', material: 'native_center_line_white' },
|
|
{ default: true, material: 'center_lines' },
|
|
],
|
|
},
|
|
},
|
|
{ key: 'directionArrows', source: 'direction_arrows', role: 'marking', materialLayer: 'lane_arrows_webscale' },
|
|
{ key: 'turnArrows', source: 'turn_arrows', role: 'marking', materialLayer: 'lane_arrows_webscale' },
|
|
{ key: 'crosswalks', source: 'crosswalks', role: 'marking', materialLayer: 'crosswalks' },
|
|
{ key: 'vehicleStopLines', source: 'vehicle_stop_lines', role: 'marking', materialLayer: 'vehicle_stop_lines' },
|
|
{ key: 'laneCenterlines', source: 'lane_centerlines', role: 'semantic' },
|
|
{ key: 'connectors', source: 'connectors', role: 'semantic' },
|
|
]);
|
|
|
|
function manifestForArea(areaId) {
|
|
return {
|
|
contract: 'native-road-package/v1.1',
|
|
areaId,
|
|
layers: LAYER_REGISTRY.map(({ source, role, materialLayer, splitBy }) => ({
|
|
source,
|
|
role,
|
|
...(materialLayer ? { materialLayer } : {}),
|
|
...(splitBy ? { splitBy } : {}),
|
|
})),
|
|
};
|
|
}
|
|
|
|
function validatePublishedLayers(directory, manifest) {
|
|
const declared = new Set();
|
|
for (const layer of manifest.layers) {
|
|
if (!layer || typeof layer.source !== 'string' || declared.has(layer.source))
|
|
throw new Error('Manifest has duplicate or invalid source.');
|
|
declared.add(layer.source);
|
|
const file = require('path').join(directory, 'layers', `${layer.source}.geojson`);
|
|
if (!require('fs').existsSync(file)) throw new Error(`Manifest source is missing: ${layer.source}`);
|
|
}
|
|
const files = require('fs').existsSync(require('path').join(directory, 'layers'))
|
|
? require('fs')
|
|
.readdirSync(require('path').join(directory, 'layers'))
|
|
.filter((name) => name.endsWith('.geojson'))
|
|
.map((name) => name.slice(0, -8))
|
|
: [];
|
|
const extras = files.filter((source) => !declared.has(source));
|
|
if (extras.length) throw new Error(`Unmanifested GeoJSON source: ${extras.join(', ')}`);
|
|
}
|
|
|
|
module.exports = { LAYER_REGISTRY, manifestForArea, validatePublishedLayers };
|