2.4 KiB
GeoJSON overlay rendering regression
The tactical calculations return geometry, but MapLibre's GeoJSON worker fails
with __publicField is not defined. HTML markers and vector basemap tiles still
render, so the UI appears functional while all GeoJSON overlays remain invisible.
Cause
Commit 0bf1382 changed Vite 8.0.1 to 6.4.3 (and the React plugin to 4.7.0).
The current optimized MapLibre 5.20.2 bundle imports __publicField outside the
functions that MapLibre serializes into its embedded worker. The GeoJSON indexing
code references that helper inside the worker, where it does not exist.
Changing geometry filters, opacity, layer order, or camera bounds cannot repair
this worker failure.
Fix
src/utils/maplibreWorker.ts loads the installed MapLibre 5 standalone CSP worker
using Vite's asset URL import and calls setWorkerUrl before React creates maps.
src/main.tsx imports this configured MapLibre instance. Other components share
the same underlying MapLibre module. No API or geometry calculation change is
required.
The ?url import is intentional for this self-contained MapLibre 5 worker: it
preserves the vendor file without transpilation. Revisit the worker entry point
if upgrading MapLibre to a new major version.
Verification (2026-09-24)
- Reproduced the missing overlays on the official tactical site, and confirmed its Isochrone API returned three valid Polygon features.
- A minimal map with an empty base style and a fixed line/polygon reproduced the
same failure: zero source/rendered features and
__publicField is not defined. - With the standalone worker, that same map visibly drew both geometries, with eight tile-level source/rendered feature entries and no worker error.
- Tested the modified tactical UI locally, proxying API requests to the official service: terrain overlays, the 10.9 km² / 14% viewshed, and colored Isochrone regions rendered. Temporary diagnostic geometry was removed afterward.
npm run buildsucceeds. The emitted standalone worker is byte-identical to the installed vendor worker.
Deployment
Deploy apps/web/src/main.tsx and apps/web/src/utils/maplibreWorker.ts together.
The observed official site serves Vite development modules; restart its web
service and reload the browser after deploying. For a production build, deploy
the complete dist output, including the emitted worker asset. The live site
has not been changed by this local fix.