import/parseBaseMap
Decodes a base_map.bin binary buffer and restores it as editor GeoJSON state.
parseBaseMap
ts
async function parseBaseMap(buffer: Uint8Array): Promise<ParsedMapState>Parameters
| Name | Type | Description |
|---|---|---|
buffer | Uint8Array | Raw bytes of a base_map.bin file |
Returns
ts
interface ParsedMapState {
project: ProjectConfig
lanes: LaneFeature[]
junctions: JunctionFeature[]
signals: SignalFeature[]
stopSigns: StopSignFeature[]
crosswalks: CrosswalkFeature[]
clearAreas: ClearAreaFeature[]
speedBumps: SpeedBumpFeature[]
parkingSpaces: ParkingSpaceFeature[]
roads: RoadDefinition[]
}Steps
decodeMap(buffer)— binary →ApolloMapJS object- Extract
originLat/originLonfrommap.header.projection.proj setGlobalProjection(originLat, originLon)- For each
ApolloLane:- Convert
central_curvePointENU → WGS84LineString - Estimate width from
left_sample+right_sampleaverages - Extract boundary types from
left_boundary.boundary_type[0].types[0] - Restore topology IDs from
predecessor_id,successor_id, etc.
- Convert
- For each polygon element (junction, crosswalk, clear area, parking space):
- Convert
polygon.point[]PointENU → WGS84Polygon
- Convert
- For each line element (stop sign, speed bump):
- Convert
stop_line[0]orposition[0]curve → WGS84LineString
- Convert
- For each signal:
- Convert stop line → WGS84
LineString - Derive position from stop line midpoint
- Convert stop line → WGS84
Example
ts
const buffer = new Uint8Array(await file.arrayBuffer())
const parsed = await parseBaseMap(buffer)
useMapStore.getState().setProject(parsed.project)
useMapStore.getState().loadState({
lanes: Object.fromEntries(parsed.lanes.map((l) => [l.id, l])),
// ...
})parseProjString (internal)
ts
function parseProjString(projStr: string): { lat: number; lon: number } | nullExtracts +lat_0 and +lon_0 values from a proj4 string using regex. Returns null if the string is absent or malformed.
Width estimation
ts
const widthSamples = lane.leftSample.map((s, i) => {
const rightS = lane.rightSample[i]
return s.width + (rightS?.width ?? s.width)
})
const width = mean(widthSamples) || 3.75This produces a single uniform width value, which is acceptable for lanes with approximately constant width.
Header bytes decoding
Proto Header fields version, date, district, and vendor are bytes type. The bytesToString() helper decodes them from base64 (protobufjs toObject output) or Uint8Array back to UTF-8 strings.
Known limitations
overlap_idarrays are not restored (recomputed on next export)- Signal
subsignalgeometry is not restored zcoordinates are discarded (editor is 2D)