diff --git a/README.md b/README.md
index 45bdf88..2f3db7b 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ Turn a **Google Maps link** into a **DXF map** with roads, rails, buildings, and
**Easiest:** Double-click **Start.bat**.
- If Node.js isn’t installed, the script will try to install it (Windows Package Manager) or open the Node.js download page. After installing, run **Start.bat** again.
-- If Node.js is installed: the app starts, your browser opens to the app. Keep the console window open while using it; close it to stop the server.
+- If Node.js is installed: the app starts in **one window**, your browser opens, and the optional Python ML server starts in the background if Python is installed. Keep the console window open while using it; close it to stop everything.
**Or from a terminal:**
@@ -67,7 +67,7 @@ Then open http://localhost:8080
| File / folder | Role |
|--------------------|------|
-| `Start.bat` | One-click run on Windows (installs Node if needed, then `npm start`) |
+| `Start.bat` | Only launcher you need: installs Node if needed, frees ports, starts the app + optional ML |
| `server.js` | Express server: serves `public/`, proxies Overpass and tile API |
| `public/index.html`| Single-page UI + canvas preview + all map/lot/edit logic (inline script) |
| `public/app.js` | Shared helpers: OSM→preview, DXF generation, OSM lot/concave-hull logic |
@@ -79,13 +79,7 @@ Then open http://localhost:8080
- **Generate drawing from imagery** — Vectorizes satellite imagery into the DXF (client-side edge detection).
- **Use server-side ML segmentation** — Sends the imagery to a small Python server that runs OpenCV Canny + contours and classifies buildings, trees, and lots. Export writes separate DXF layers: **IMAGERY_BUILDINGS**, **IMAGERY_TREES**, **IMAGERY_LOTS**.
- **To enable:** In a second terminal:
- ```bash
- cd ml_server
- pip install -r requirements.txt
- python segment_server.py
- ```
- The Python server runs on **http://127.0.0.1:3457**. The Node app proxies `/api/segment` to it. If the Python server is not running, the checkbox will show an error when you use it.
+ **To enable:** Double-click **Start.bat**. If Python is installed, the ML server starts automatically with the app (port 3457). If Python is missing, satellite tracing still works.
- **Snap imagery trace to OSM** — When enabled, trace points are snapped to nearby OSM buildings, roads, and landuse (within ~1.5 m). Use this to align the imagery trace with OSM where data exists.
diff --git a/Start.bat b/Start.bat
index 7126564..d04e13c 100644
--- a/Start.bat
+++ b/Start.bat
@@ -1,52 +1,65 @@
@echo off
+setlocal
title MAPS to DXF
cd /d "%~dp0"
where node >nul 2>&1
-if %errorlevel% neq 0 (
- echo Node.js not found. Installing via Windows Package Manager...
- winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements 2>nul
- if %errorlevel% neq 0 (
- echo.
- echo Could not install Node.js automatically. Opening download page...
- start https://nodejs.org/
- echo.
- echo After installing Node.js, close this window and double-click Start.bat again.
- pause
- exit /b 1
- )
- echo.
- echo Node.js installed. Please close this window, then double-click Start.bat again.
- pause
- exit /b 0
-)
+if errorlevel 1 goto INSTALL_NODE
+goto DEPS
-if not exist "node_modules" (
- echo Installing dependencies...
- call npm install
-) else if not exist "node_modules\multer" (
- echo Installing missing dependencies...
- call npm install
-)
-
-if exist "ml_server\segment_server.py" (
- where python >nul 2>&1
- if %errorlevel% equ 0 (
- start "MAPS to DXF - ML Server" cmd /k "call %~sdp0Start_ML_Server.bat"
- timeout /t 2 /nobreak >nul
- ) else (
- where py >nul 2>&1
- if %errorlevel% equ 0 (
- start "MAPS to DXF - ML Server" cmd /k "call %~sdp0Start_ML_Server.bat"
- timeout /t 2 /nobreak >nul
- )
- )
-)
+:INSTALL_NODE
+echo Node.js not found. Installing via Windows Package Manager...
+winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements
+if errorlevel 1 goto NODE_FAIL
+echo Node.js installed. Close this window, then double-click Start.bat again.
+pause
+exit /b 0
+:NODE_FAIL
+echo Could not install Node.js automatically. Opening download page...
+start https://nodejs.org/
+echo After installing Node.js, close this window and double-click Start.bat again.
+pause
+exit /b 1
+
+:DEPS
+if not exist "node_modules\express" goto NPM_INSTALL
+if not exist "node_modules\multer" goto NPM_INSTALL
+goto PORTS
+
+:NPM_INSTALL
+echo Installing dependencies...
+call npm install
+if errorlevel 1 goto NPM_FAIL
+goto PORTS
+
+:NPM_FAIL
+echo npm install failed.
+pause
+exit /b 1
+
+:PORTS
+echo Freeing ports 3456 and 3457 if a previous run is still open...
+powershell -NoProfile -Command "foreach ($p in 3456,3457) { Get-NetTCPConnection -LocalPort $p -State Listen -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue } }" >nul 2>&1
+
+set "PY="
+where python >nul 2>&1
+if not errorlevel 1 set "PY=python"
+if defined PY goto ML_DEPS
+where py >nul 2>&1
+if not errorlevel 1 set "PY=py"
+if not defined PY goto START_APP
+
+:ML_DEPS
+if not exist "ml_server\requirements.txt" goto START_APP
+echo Checking Python ML dependencies...
+"%PY%" -m pip install -r "ml_server\requirements.txt" -q
+
+:START_APP
echo Starting MAPS to DXF...
-for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":3456" ^| findstr "LISTENING"') do taskkill /PID %%a /F >nul 2>&1
-echo Browser will open. Keep this window open while using the app.
-if exist "ml_server\segment_server.py" echo (ML server started in the other window - enable "Use server-side ML segmentation" in the app.)
+echo Browser will open. Keep this window open.
+echo Close this window to stop the app.
+echo.
+node server.js
echo.
-call npm start
pause
diff --git a/Start_ML_Server.bat b/Start_ML_Server.bat
deleted file mode 100644
index 0ad4704..0000000
--- a/Start_ML_Server.bat
+++ /dev/null
@@ -1,40 +0,0 @@
-@echo off
-title MAPS to DXF - ML segmentation server
-cd /d "%~dp0"
-
-where python >nul 2>&1
-if %errorlevel% neq 0 (
- where py >nul 2>&1
- if %errorlevel% neq 0 (
- echo Python not found. Install Python from https://www.python.org/downloads/
- echo Then run this script again.
- pause
- exit /b 1
- )
- set PY=py
-) else (
- set PY=python
-)
-
-if not exist "ml_server" (
- echo ml_server folder not found.
- pause
- exit /b 1
-)
-
-cd ml_server
-echo Installing Python dependencies...
-"%PY%" -m pip install -r requirements.txt -q
-if %errorlevel% neq 0 (
- echo.
- echo Pip install failed. Try: pip install -r requirements.txt
- pause
- exit /b 1
-)
-
-echo.
-echo ML segmentation server starting on http://127.0.0.1:3457
-echo Keep this window open while using "Use server-side ML segmentation" in the app.
-echo.
-"%PY%" segment_server.py
-pause
diff --git a/ai_dna.md b/ai_dna.md
index 2437ef1..a001f84 100644
--- a/ai_dna.md
+++ b/ai_dna.md
@@ -26,7 +26,7 @@ Quick reference for AI and developers jumping back into this repo: purpose, stru
MAPS-to-DXF-standalone/
├── server.js # Express: static files, /api/overpass, /api/tile
├── package.json # express only
-├── Start.bat # Windows: install Node if missing, npm install, npm start
+├── Start.bat # Only Windows launcher: Node + app + optional ML server
├── README.md # User-facing run + workflow
├── ai_dna.md # This file — project DNA for AI/developers
└── public/
diff --git a/ml_server/README.md b/ml_server/README.md
index 68fbc80..3e2a09e 100644
--- a/ml_server/README.md
+++ b/ml_server/README.md
@@ -4,13 +4,15 @@ Run this server to enable **Use server-side ML segmentation** in the app. It tra
## Run
+Double-click **Start.bat** in the project root (starts the main app and this ML server together).
+
+Or from a terminal:
+
```bash
pip install -r requirements.txt
python segment_server.py
```
-Or double-click **Start_ML_Server.bat** from the project root.
-
Server listens on **http://127.0.0.1:3457**. The Node app proxies `/api/segment` to it.
## Backends
diff --git a/public/app.js b/public/app.js
index 19a19d3..e401621 100644
--- a/public/app.js
+++ b/public/app.js
@@ -3,6 +3,35 @@
* Supports Google Maps and Google Earth (Web) links. Google Earth view/altitude/distance
* is used to optimize the requested area (smaller = faster Overpass and imagery).
*/
+function isShortMapsUrl(input) {
+ return /^https?:\/\/(maps\.app\.goo\.gl|goo\.gl\/maps)\//i.test(String(input).trim());
+}
+
+function isGoogleMapsLink(input) {
+ const s = String(input).trim();
+ return isShortMapsUrl(s) || /^https?:\/\/(www\.)?(google\.[^/]+\/maps|maps\.google\.)/i.test(s);
+}
+
+function extractAddressFromMapsUrl(input) {
+ const s = String(input).trim();
+ const place = s.match(/google\.[^/]+\/maps\/place\/([^/@?#]+)/i);
+ if (place && place[1]) {
+ const decoded = decodeURIComponent(place[1].replace(/\+/g, ' ')).trim();
+ if (decoded && !/^-?\d+\.?\d*\s*,\s*-?\d+\.?\d*$/.test(decoded)) return decoded;
+ }
+ const search = s.match(/google\.[^/]+\/maps\/search\/([^/@?#]+)/i);
+ if (search && search[1]) {
+ const decoded = decodeURIComponent(search[1].replace(/\+/g, ' ')).trim();
+ if (decoded && !/^-?\d+\.?\d*\s*,\s*-?\d+\.?\d*$/.test(decoded)) return decoded;
+ }
+ const q = s.match(/[?&](?:q|query|daddr|saddr)=([^&]+)/i);
+ if (q && q[1]) {
+ const decoded = decodeURIComponent(q[1].replace(/\+/g, ' ')).trim();
+ if (decoded && !/^https?:/i.test(decoded) && !/^-?\d+\.?\d*\s*,\s*-?\d+\.?\d*$/.test(decoded)) return decoded;
+ }
+ return null;
+}
+
function extractCoordinates(url) {
const s = String(url).trim();
let lat;
@@ -13,19 +42,26 @@ function extractCoordinates(url) {
while ((pinMatch = placePinRegex.exec(s)) !== null) {
placePins.push({ lat: parseFloat(pinMatch[1]), lon: parseFloat(pinMatch[2]) });
}
- const coordRegex = /@(-?\d+\.?\d*),(-?\d+\.?\d*)/;
- const coordMatch = s.match(coordRegex);
+ const atMatch = s.match(/@(-?\d+\.?\d*),(-?\d+\.?\d*)/);
+ const qCoord = s.match(/[?&](?:q|ll|center|query)=(-?\d+\.?\d*)\s*,\s*(-?\d+\.?\d*)/i);
+ const dirCoord = s.match(/!8m2!3d(-?\d+\.?\d*)!4d(-?\d+\.?\d*)/);
if (placePins.length > 0) {
const pin = placePins[placePins.length - 1];
lat = pin.lat;
lon = pin.lon;
- } else if (coordMatch && coordMatch.length >= 3) {
- lat = parseFloat(coordMatch[1]);
- lon = parseFloat(coordMatch[2]);
+ } else if (dirCoord) {
+ lat = parseFloat(dirCoord[1]);
+ lon = parseFloat(dirCoord[2]);
+ } else if (atMatch && atMatch.length >= 3) {
+ lat = parseFloat(atMatch[1]);
+ lon = parseFloat(atMatch[2]);
+ } else if (qCoord && qCoord.length >= 3) {
+ lat = parseFloat(qCoord[1]);
+ lon = parseFloat(qCoord[2]);
} else {
return null;
}
- if (isNaN(lat) || isNaN(lon)) return null;
+ if (isNaN(lat) || isNaN(lon) || Math.abs(lat) > 90 || Math.abs(lon) > 180) return null;
let viewMeters;
const mapsZoomM = s.match(/@-?\d+\.?\d*,-?\d+\.?\d*,(\d+(?:\.\d*)?)\s*m\b/i);
@@ -99,9 +135,11 @@ function buildPreviewData(osmData, origin, layerOptions) {
});
const s = 8;
- out.push(['L', -s, 0, s, 0, 4]);
- out.push(['L', 0, -s, 0, s, 4]);
- out.push(['C', 0, 0, s / 1.5, 4]);
+ if (on('locationMarker')) {
+ out.push(['L', -s, 0, s, 0, 4]);
+ out.push(['L', 0, -s, 0, s, 4]);
+ out.push(['C', 0, 0, s / 1.5, 4]);
+ }
const PARKING_SPOT_HW = 1.25;
const PARKING_SPOT_HH = 2.5;
@@ -201,6 +239,9 @@ function generateHighDetailDXF(osmData, origin, layerOptions, clipBounds) {
const metersPerLat = 111132.92;
const metersPerLon = 111412.84 * Math.cos((origin.lat * Math.PI) / 180);
const clipMargin = 8;
+ if (!osmData || !Array.isArray(osmData.elements)) {
+ osmData = { elements: [] };
+ }
function inClip(x, y) {
if (!clipBounds) return true;
@@ -227,14 +268,15 @@ function generateHighDetailDXF(osmData, origin, layerOptions, clipBounds) {
}
});
- let dxf = '0\nSECTION\n2\nHEADER\n9\n$INSUNITS\n70\n6\n9\n$MEASUREMENT\n70\n1\n0\nENDSEC\n0\nSECTION\n2\nTABLES\n0\nTABLE\n2\nLTYPE\n70\n1\n';
- dxf += '0\nLTYPE\n2\nDASHED\n70\n0\n3\n_ _ _ _ _ _\n72\n65\n73\n2\n40\n2.0\n49\n1.25\n49\n-0.75\n0\nENDTAB\n0\nENDSEC\n';
+ let dxf = dxfR2000Preamble();
dxf += '0\nSECTION\n2\nENTITIES\n';
const s = 8;
- dxf += `0\nLINE\n8\nLOCATION_MARKER\n62\n4\n10\n-${s}\n20\n0\n11\n${s}\n21\n0\n`;
- dxf += `0\nLINE\n8\nLOCATION_MARKER\n62\n4\n10\n0\n20\n-${s}\n11\n0\n21\n${s}\n`;
- dxf += `0\nCIRCLE\n8\nLOCATION_MARKER\n62\n4\n10\n0\n20\n0\n40\n${s / 1.5}\n`;
+ if (on('locationMarker')) {
+ dxf += `0\nLINE\n8\nLOCATION_MARKER\n62\n4\n10\n-${s}\n20\n0\n11\n${s}\n21\n0\n`;
+ dxf += `0\nLINE\n8\nLOCATION_MARKER\n62\n4\n10\n0\n20\n-${s}\n11\n0\n21\n${s}\n`;
+ dxf += `0\nCIRCLE\n8\nLOCATION_MARKER\n62\n4\n10\n0\n20\n0\n40\n${s / 1.5}\n`;
+ }
const PARKING_HW = 1.25;
const PARKING_HH = 2.5;
@@ -402,10 +444,101 @@ function generateHighDetailDXF(osmData, origin, layerOptions, clipBounds) {
}
});
- dxf += '0\nENDSEC\n0\nEOF';
+ dxf += '0\nENDSEC\n' + dxfBaseObjectsSection() + '0\nEOF';
return dxf;
}
+/** Model-space BLOCK_RECORD handle; IMAGE entities must own to this, never 0. */
+const DXF_MODEL_SPACE_HANDLE = '1F';
+
+/**
+ * R2000 tables/blocks BricsCAD needs. Missing BLOCK_RECORD *MODEL_SPACE causes "Null object Id: (0)".
+ */
+function dxfR2000Preamble() {
+ const ms = DXF_MODEL_SPACE_HANDLE;
+ const ps = '1B';
+ return [
+ '0', 'SECTION', '2', 'HEADER',
+ '9', '$ACADVER', '1', 'AC1015',
+ '9', '$HANDSEED', '5', 'FFFF',
+ '9', '$INSUNITS', '70', '6',
+ '9', '$MEASUREMENT', '70', '1',
+ '0', 'ENDSEC',
+ '0', 'SECTION', '2', 'TABLES',
+ '0', 'TABLE', '2', 'VPORT', '5', '8', '100', 'AcDbSymbolTable', '70', '1',
+ '0', 'VPORT', '5', '29', '330', '8', '100', 'AcDbSymbolTableRecord', '100', 'AcDbViewportTableRecord',
+ '2', '*ACTIVE', '70', '0',
+ '10', '0.0', '20', '0.0', '11', '1.0', '21', '1.0',
+ '12', '0.0', '22', '0.0', '13', '0.0', '23', '0.0',
+ '14', '0.5', '24', '0.5', '15', '0.5', '25', '0.5',
+ '16', '0.0', '26', '0.0', '36', '1.0',
+ '17', '0.0', '27', '0.0', '37', '0.0',
+ '40', '297.0', '41', '1.6', '42', '50.0', '43', '0.0', '44', '0.0',
+ '50', '0.0', '51', '0.0', '71', '0', '72', '100', '73', '1', '74', '3',
+ '75', '0', '76', '0', '77', '0', '78', '0',
+ '0', 'ENDTAB',
+ '0', 'TABLE', '2', 'LTYPE', '5', '5', '100', 'AcDbSymbolTable', '70', '4',
+ '0', 'LTYPE', '5', '6', '330', '5', '100', 'AcDbSymbolTableRecord', '100', 'AcDbLinetypeTableRecord',
+ '2', 'BYBLOCK', '70', '0', '3', '', '72', '65', '73', '0', '40', '0.0',
+ '0', 'LTYPE', '5', '7', '330', '5', '100', 'AcDbSymbolTableRecord', '100', 'AcDbLinetypeTableRecord',
+ '2', 'BYLAYER', '70', '0', '3', '', '72', '65', '73', '0', '40', '0.0',
+ '0', 'LTYPE', '5', '9', '330', '5', '100', 'AcDbSymbolTableRecord', '100', 'AcDbLinetypeTableRecord',
+ '2', 'CONTINUOUS', '70', '0', '3', 'Solid line', '72', '65', '73', '0', '40', '0.0',
+ '0', 'LTYPE', '5', 'A', '330', '5', '100', 'AcDbSymbolTableRecord', '100', 'AcDbLinetypeTableRecord',
+ '2', 'DASHED', '70', '0', '3', '_ _ _ _ _ _', '72', '65', '73', '2', '40', '2.0', '49', '1.25', '49', '-0.75',
+ '0', 'ENDTAB',
+ '0', 'TABLE', '2', 'LAYER', '5', '2', '100', 'AcDbSymbolTable', '70', '1',
+ '0', 'LAYER', '5', '10', '330', '2', '100', 'AcDbSymbolTableRecord', '100', 'AcDbLayerTableRecord',
+ '2', '0', '70', '0', '62', '7', '6', 'CONTINUOUS',
+ '0', 'ENDTAB',
+ '0', 'TABLE', '2', 'STYLE', '5', '3', '100', 'AcDbSymbolTable', '70', '1',
+ '0', 'STYLE', '5', '11', '330', '3', '100', 'AcDbSymbolTableRecord', '100', 'AcDbTextStyleTableRecord',
+ '2', 'STANDARD', '70', '0', '40', '0.0', '41', '1.0', '50', '0.0', '71', '0', '42', '2.5', '3', 'txt', '4', '',
+ '0', 'ENDTAB',
+ '0', 'TABLE', '2', 'VIEW', '5', '4', '100', 'AcDbSymbolTable', '70', '0',
+ '0', 'ENDTAB',
+ '0', 'TABLE', '2', 'UCS', '5', '32', '100', 'AcDbSymbolTable', '70', '0',
+ '0', 'ENDTAB',
+ '0', 'TABLE', '2', 'APPID', '5', '12', '100', 'AcDbSymbolTable', '70', '1',
+ '0', 'APPID', '5', '13', '330', '12', '100', 'AcDbSymbolTableRecord', '100', 'AcDbRegAppTableRecord',
+ '2', 'ACAD', '70', '0',
+ '0', 'ENDTAB',
+ '0', 'TABLE', '2', 'DIMSTYLE', '5', '14', '100', 'AcDbSymbolTable', '70', '1',
+ '0', 'DIMSTYLE', '105', '15', '330', '14', '100', 'AcDbSymbolTableRecord', '100', 'AcDbDimStyleTableRecord',
+ '2', 'STANDARD', '70', '0',
+ '0', 'ENDTAB',
+ '0', 'TABLE', '2', 'BLOCK_RECORD', '5', '1', '100', 'AcDbSymbolTable', '70', '2',
+ '0', 'BLOCK_RECORD', '5', ms, '330', '1', '100', 'AcDbSymbolTableRecord', '100', 'AcDbBlockTableRecord',
+ '2', '*MODEL_SPACE',
+ '0', 'BLOCK_RECORD', '5', ps, '330', '1', '100', 'AcDbSymbolTableRecord', '100', 'AcDbBlockTableRecord',
+ '2', '*PAPER_SPACE',
+ '0', 'ENDTAB',
+ '0', 'ENDSEC',
+ '0', 'SECTION', '2', 'BLOCKS',
+ '0', 'BLOCK', '5', '20', '330', ms, '100', 'AcDbEntity', '8', '0', '100', 'AcDbBlockBegin',
+ '2', '*MODEL_SPACE', '70', '0', '10', '0.0', '20', '0.0', '30', '0.0', '3', '*MODEL_SPACE', '1', '',
+ '0', 'ENDBLK', '5', '21', '330', ms, '100', 'AcDbEntity', '8', '0', '100', 'AcDbBlockEnd',
+ '0', 'BLOCK', '5', '22', '330', ps, '100', 'AcDbEntity', '8', '0', '100', 'AcDbBlockBegin',
+ '2', '*PAPER_SPACE', '70', '0', '10', '0.0', '20', '0.0', '30', '0.0', '3', '*PAPER_SPACE', '1', '',
+ '0', 'ENDBLK', '5', '23', '330', ps, '100', 'AcDbEntity', '8', '0', '100', 'AcDbBlockEnd',
+ '0', 'ENDSEC'
+ ].join('\n') + '\n';
+}
+
+const DXF_ENTITIES_CLOSE = '0\nENDSEC\n0\nSECTION\n2\nOBJECTS\n';
+
+function dxfBaseObjectsSection() {
+ return '0\nSECTION\n2\nOBJECTS\n' +
+ '0\nDICTIONARY\n5\nC\n330\n0\n100\nAcDbDictionary\n281\n1\n3\nACAD_GROUP\n350\nD\n' +
+ '0\nDICTIONARY\n5\nD\n330\nC\n100\nAcDbDictionary\n281\n1\n' +
+ '0\nENDSEC\n';
+}
+
+function insertDxfEntities(dxfContent, block) {
+ if (!block) return dxfContent;
+ return dxfContent.replace(DXF_ENTITIES_CLOSE, block + DXF_ENTITIES_CLOSE);
+}
+
/**
* Convex hull (Graham scan). Returns hull points in CCW order.
*/
@@ -640,7 +773,7 @@ function appendLotsToDXF(dxfContent, lots) {
block += `0\nLINE\n8\nLOTS\n62\n40\n10\n${a.x}\n20\n${a.y}\n11\n${b.x}\n21\n${b.y}\n`;
}
});
- return dxfContent.replace('0\nENDSEC\n0\nEOF', block + '0\nENDSEC\n0\nEOF');
+ return insertDxfEntities(dxfContent, block);
}
/**
@@ -848,7 +981,7 @@ function appendImageryTraceToDXF(dxfContent, polylines, minSegmentMeters, minLen
block += `0\nLINE\n8\n${layer}\n62\n7\n10\n${a.x}\n20\n${a.y}\n11\n${b.x}\n21\n${b.y}\n`;
}
});
- return dxfContent.replace('0\nENDSEC\n0\nEOF', block + '0\nENDSEC\n0\nEOF');
+ return insertDxfEntities(dxfContent, block);
}
/**
@@ -889,22 +1022,26 @@ function generateWorldFilePgw(minX, minY, maxX, maxY, widthPx, heightPx, rowZero
}
/**
- * Append satellite imagery reference to DXF so CAD shows the image as background.
- * Also adds a visible bounding box (rectangle) on layer IMAGE_BOUNDS so the image extent is visible in CAD.
- * imageFilename: e.g. "satellite.png" (same folder as DXF).
- * minX, minY, maxX, maxY: extent in drawing units (meters from origin). Image is placed to fill this rect.
- * widthPx, heightPx: image size in pixels.
+ * Append a georeferenced IMAGE already attached in the DXF (AutoCAD/BricsCAD IMAGE).
+ * PNG must sit next to the DXF using imageFilename. Insertion is SW corner; size fills the selected extent.
+ * 1 drawing unit = 1 meter ($INSUNITS=6). U/V are meters per pixel so CAD scale matches the selection.
*/
function appendSatelliteImageToDXF(dxfContent, imageFilename, minX, minY, maxX, maxY, widthPx, heightPx) {
- const handle = '1F0';
const w = maxX - minX;
const h = maxY - minY;
+ if (!(widthPx > 0) || !(heightPx > 0) || !(w > 0) || !(h > 0)) return dxfContent;
const uPerPx = w / widthPx;
const vPerPx = h / heightPx;
+ const clipU = widthPx - 0.5;
+ const clipV = heightPx - 0.5;
+ const imageHandle = 'A4';
+ const defHandle = 'A2';
+ const reactorHandle = 'A3';
+ const imageDictHandle = 'A1';
+ const safeName = String(imageFilename || 'satellite.png').replace(/[\r\n]/g, '');
const scaleNote =
`0\nTEXT\n8\nIMAGE_SCALE\n62\n3\n10\n${minX}\n20\n${minY - Math.max(3, h * 0.02)}\n40\n${Math.max(2, Math.min(w, h) * 0.03)}\n1\n` +
`Satellite ${w.toFixed(1)}m x ${h.toFixed(1)}m | ${uPerPx.toFixed(4)} m/px | INSUNITS=meters\n`;
- /* Visible bounding box in CAD: four LINE entities (color 4 = cyan) so user sees the image extent */
const layer = 'IMAGE_BOUNDS';
const color = '4';
const boxLines =
@@ -913,12 +1050,30 @@ function appendSatelliteImageToDXF(dxfContent, imageFilename, minX, minY, maxX,
`0\nLINE\n8\n${layer}\n62\n${color}\n10\n${maxX}\n20\n${maxY}\n30\n0\n11\n${minX}\n21\n${maxY}\n31\n0\n` +
`0\nLINE\n8\n${layer}\n62\n${color}\n10\n${minX}\n20\n${maxY}\n30\n0\n11\n${minX}\n21\n${minY}\n31\n0\n`;
const imageEntity =
- `0\nIMAGE\n8\nSATELLITE_IMAGERY\n10\n${minX}\n20\n${minY}\n30\n0\n` +
+ `0\nIMAGE\n5\n${imageHandle}\n330\n${DXF_MODEL_SPACE_HANDLE}\n100\nAcDbEntity\n8\nSATELLITE_IMAGERY\n100\nAcDbRasterImage\n90\n0\n` +
+ `10\n${minX}\n20\n${minY}\n30\n0\n` +
`11\n${uPerPx}\n21\n0\n31\n0\n12\n0\n22\n${vPerPx}\n32\n0\n` +
- `13\n${widthPx}\n23\n${heightPx}\n340\n${handle}\n`;
+ `13\n${widthPx}\n23\n${heightPx}\n340\n${defHandle}\n70\n7\n280\n0\n281\n50\n282\n50\n283\n0\n360\n${reactorHandle}\n` +
+ `71\n1\n91\n2\n14\n-0.5\n24\n-0.5\n14\n${clipU}\n24\n${clipV}\n`;
+ const classes =
+ `0\nSECTION\n2\nCLASSES\n` +
+ `0\nCLASS\n1\nIMAGE\n2\nAcDbRasterImage\n3\nISM\n90\n127\n91\n0\n280\n0\n281\n1\n` +
+ `0\nCLASS\n1\nIMAGEDEF\n2\nAcDbRasterImageDef\n3\nISM\n90\n0\n91\n0\n280\n0\n281\n0\n` +
+ `0\nCLASS\n1\nIMAGEDEF_REACTOR\n2\nAcDbRasterImageDefReactor\n3\nISM\n90\n0\n91\n0\n280\n0\n281\n0\n` +
+ `0\nENDSEC\n`;
const objectsSection =
`0\nSECTION\n2\nOBJECTS\n` +
- `0\nIMAGEDEF\n90\n${handle}\n1\n${imageFilename}\n13\n${widthPx}\n23\n${heightPx}\n` +
- `0\nENDSEC\n0\nEOF`;
- return dxfContent.replace('0\nENDSEC\n0\nEOF', boxLines + scaleNote + imageEntity + '0\nENDSEC\n' + objectsSection);
+ `0\nDICTIONARY\n5\nC\n330\n0\n100\nAcDbDictionary\n281\n1\n3\nACAD_GROUP\n350\nD\n3\nACAD_IMAGE_DICT\n350\n${imageDictHandle}\n` +
+ `0\nDICTIONARY\n5\nD\n330\nC\n100\nAcDbDictionary\n281\n1\n` +
+ `0\nDICTIONARY\n5\n${imageDictHandle}\n330\nC\n100\nAcDbDictionary\n281\n1\n3\nSATELLITE\n350\n${defHandle}\n` +
+ `0\nIMAGEDEF\n5\n${defHandle}\n330\n${imageDictHandle}\n100\nAcDbRasterImageDef\n90\n0\n1\n${safeName}\n` +
+ `10\n${widthPx}\n20\n${heightPx}\n280\n1\n281\n0\n11\n${uPerPx}\n21\n${vPerPx}\n` +
+ `0\nIMAGEDEF_REACTOR\n5\n${reactorHandle}\n330\n${imageHandle}\n100\nAcDbRasterImageDefReactor\n90\n2\n330\n${imageHandle}\n` +
+ `0\nENDSEC\n`;
+ let out = dxfContent;
+ if (out.indexOf('\n2\nCLASSES\n') === -1) {
+ out = out.replace('0\nENDSEC\n0\nSECTION\n2\nTABLES\n', '0\nENDSEC\n' + classes + '0\nSECTION\n2\nTABLES\n');
+ }
+ out = insertDxfEntities(out, boxLines + scaleNote + imageEntity);
+ return out.replace(dxfBaseObjectsSection(), objectsSection);
}
diff --git a/public/index.html b/public/index.html
index 323cb31..f589140 100644
--- a/public/index.html
+++ b/public/index.html
@@ -153,10 +153,10 @@
MAPS to DXF
-
Enter an address or place name, or paste a link: Google Earthhttps://earth.google.com/web/search/ (search URL), or Google Maps / Earth view URL. Load preview, then export DXF.
+
Paste a Google Maps pin URL for the exact building (best). Typed addresses use OpenStreetMap, not Google — they can land on the street or town. Satellite is Esri/USGS, not Google imagery.