@dxf-tools/maplibre
v0.2.3
Published
MapLibre DXF overlay (DxfMapOverlay) with CRS/proj4 placement
Downloads
405
Maintainers
Readme
@dxf-tools/maplibre
MapLibre integration for DXF scenes: a CAD-accurate overlay (DxfMapOverlay) with optional CRS / proj4 placement.
Install
npm install @dxf-tools/core @dxf-tools/webgl @dxf-tools/maplibre maplibre-glPeers: maplibre-gl ^5.6, @dxf-tools/webgl ^0.1.
Overlay (recommended)
import { parseDxf, buildScene } from "@dxf-tools/core";
import { loadFontCatalog, styleFontsFromDoc } from "@dxf-tools/webgl";
import { DxfMapOverlay } from "@dxf-tools/maplibre";
import maplibregl from "maplibre-gl";
const map = new maplibregl.Map({ /* … */ });
const overlay = new DxfMapOverlay(map, { crs: "EPSG:2240" });
const buf = await file.arrayBuffer();
const doc = parseDxf(buf);
const fonts = await loadFontCatalog(styleFontsFromDoc(doc.tables.styles.values()));
const scene = buildScene(doc, { fonts, textMode: "glyphs" });
overlay.setScene(scene);
overlay.fit();Large survey coordinates are recentered in buildScene via scene.origin; the overlay applies that origin when projecting. Camera sync uses a 3-corner world→screen affine so CRS grid convergence / Web Mercator skew stay aligned with the basemap, and applies MapLibre’s raster pixel-grid snap (≤0.5 CSS px) so vectors match ortho/OSM tiles. The affine is recomputed and redrawn on every MapLibre render frame so the drawing stays locked during pan/zoom.
CRS helpers
import {
listCrsOptions,
createCrsProjector,
registerCrsDef,
crsLabel,
} from "@dxf-tools/maplibre";
for (const { value, label } of listCrsOptions()) {
// populate a <select>
}
overlay.setCrs("EPSG:6447", true);
// or a custom +proj= string / EPSG code
registerCrsDef("EPSG:9999", "+proj=…");Built-ins from listCrsOptions(): local (embed near [0°, 0°]), EPSG:4326, EPSG:3857, Georgia West EPSG:2240 / EPSG:6447, Florida West EPSG:6443, North Carolina EPSG:2264.
Layers
DxfMapOverlay forwards the same layer API as DxfViewer:
overlay.filterLayers({ query: "ROAD" });
overlay.setLayerVisibility("HIDDEN", false);
overlay.soloLayers(["SITE"]);
overlay.groupLayersByDelimiter();Live demo
Upload + CRS UI: Map overlay (or bun run dev → /map/).
License
PolyForm Noncommercial 1.0.0 — free for personal / noncommercial use. Commercial use requires a paid license (inquire).
