Map pages
Every purpose of plan v4 ends in a map page: one PDF page, or a few, that someone else can read with no account. The water map, the contour map, the site map, the earthwork map, the zone map and the sight line map are each a short description handed to one function, not a renderer of their own (plan v4 items 452 to 454). The code is apps/web/src/lib/pdf/map-page.ts, map-scale.ts and map-page-words.ts, and the frame on the screen map is apps/web/src/components/map/print-frame-layer.tsx.
The printable map and the cut and fill report of plan v3 are made with the same page builder, page-builder.ts, and don't use these blocks. Adding them changed nothing on those two: existing-pdfs-golden.test.ts holds each one's text in order, page sizes, drawn paths and images and a hash of its page content to a golden file written before the blocks were added. Their labels are among those the owner has said to leave (labels-and-cautions.md), and the source line and the one sentence don't go on them until item 535 does that.
Drain a field's map page, the "Drainage map" in purposes.ts, is that printable map as it stands, not a page built from these blocks. A drainage design keeps its status, its preliminary label and its conflicts exactly as they are (plan v4 item 534), and the printable map is the page that already carries them, so rebuilding it would only risk the words the drainage specs hold. Its Review step leads with Download PDF map once there's a design (main-action.ts, "print-map"), which asks the Share and print section to make it (printable-map-request.ts), and the walks end there. drainage-map-page.test.ts holds that it carries the map, its key, the layout's acres and pipes, its source line and its labels, each once.
The blocks
A page has these, top to bottom:
- Title: the page's title, such as "Contour map", and one line under it with the answer and its number, such as "Contour lines are 1 ft apart. Bold lines mark every 5 ft."
- Map: the ground at its scale. A picture of the screen map, captured to exactly the frame's bounds, fills the map's rectangle; vectors (contours, a profile's path, an outline) are drawn over it in longitude and latitude, clipped to the rectangle, and points (
points, such as a sight line's two ends) as dots with a white edge. A north arrow sits at the top right, and the base map's attribution, when there is a picture, at the bottom right. - Key: each entry's mark (a fill with its pattern, a line, a point or a ramp with its two ends) and its words. Entries that don't fit the band go on a further page under "Map key, continued".
- Tables: a title, a header row and rows. A table that doesn't fit the band goes to a further page, and one taller than a page is split by rows, the rest under "title, continued".
- Profile: ground height in feet against distance in feet, from the engine's meters. Further series can be drawn on the same axes (
over), such as what stands on the ground and a line of sight, with one point marked (point), such as the first thing in the way; the span takes them all in. A stretch with no ground is left open and said once under the chart, "No ground for 164 ft of this line". Marked stretches, such as those steeper than a grade, are drawn heavier in amber. - Scale: the bar, with the scale printed beside it ("1 in = 50 ft"), then how it was chosen when it was fitted, the coordinate system, the height reference, the paper and the day.
- Source: the source line and the one sentence of
lib/terrain/source-line.ts, each on one line, at the foot of the last page, and nowhere else.
Page one holds the title, the map and a band under it with the key, the tables and profiles that fit, and the scale. Whatever doesn't fit goes on further pages in the order given, each headed with the page's title and its number, and each page that goes on says "Continues on page 2." at its foot. The map's rectangle depends only on the paper and its orientation (mapPageLayout), so the frame a scale will print is known before the page is made.
Paper is letter (8.5 by 11 in) or tabloid (11 by 17 in), portrait or landscape, with half an inch of margin all round.
The source line and the sentence, once
Rule 6 of the voice: every map page ends with one source line and one sentence, once each. The description has no field for either. Both are filled from the terrain's record (MapPageTerrain.provenance, the worker's provenance row): the source key gives who flew it and what it was made from (lidar for the USGS 1 m DEMs, point clouds and MnTopo; elevation data for the 1/3 arc-second mosaic and NOAA's DEMs, which mix methods; your own elevation file for an upload), the first and last collection dates give the flight's years, and resolution_m gives the cell size. What the record leaves out reads "flight year not recorded" or "cell size not recorded", never a guess.
buildMapPagePdf collects every line of words it writes and runs exitNoticeProblems over them before saving. A page whose own words carry a second sentence about verifying on the ground, in a title or a table, is refused with MapPageNoticeError. map-page.test.ts builds pages from the blocks with the source block left out and drawn twice, and exitNoticeProblems fails both.
The coordinate system ("NAD83(2011) / UTM 15N, EPSG 6344", from the project's grid) and the height reference ("NAVD88, shown in feet", since the worker stores every surface in NAVD88 meters; an upload with no height reference declared says none was recorded) sit by the scale.
Scales, and where they come from
A map page is fitted to its area, or set to a stated scale.
- The scales offered are the divisions of a civil engineer's triangular scale, whose six faces are marked 10, 20, 30, 40, 50 and 60 parts to the inch, each read at any power of ten: 1 in = 10 ft up to 1 in = 60,000 ft (
ENGINEER_SCALES_FT_PER_IN). A map at 1 in = 50 ft is read with the 50 face, and one at 1 in = 400 ft with the 40 face. That is the whole reason for the list: each can be read with that rule. No standard is cited for which scale a map must use, because none was read that says. - Fit, the default, takes the closest-in listed scale at which the area, with 5% room on every side, lies inside the map's rectangle, and the page says "Chosen to fit the area" under the scale. An area too large for every listed scale gets the exact scale that holds it, rounded up to a whole hundred feet. So a map too large for one readable page at a stated scale is fitted, and says the scale it used.
- A stated scale is kept whether or not the area fits; the frame on the screen shows what it will hold, and the page says "The area runs past the map at this scale" when it doesn't.
- The offer for an area (
readableScalesFor) is the fitting scale, the three closer in and the two farther out. - The bar is whole inches of paper (4, 3, 2 or 1, or half an inch), the longest that fits beside the scale's words, so the ground it stands for is a round number of the scale's own feet.
Ground distance, not the screen's
The screen map is Web Mercator, where a map meter is longer than a ground meter by 1 / cos(latitude): about 1.47 at 47 degrees north. Nothing on a map page is measured on the screen. A frame is laid out in ground meters around its center: the map's rectangle in inches, times the scale in feet, times 0.3048. It is turned into longitude and latitude with the GRS 1980 ellipsoid's radii of curvature at the center, M in the meridian and N cos(latitude) along the parallel (Snyder, J. P., Map Projections: A Working Manual, USGS Professional Paper 1395, 1987, which gives both radii), which is the ellipsoid of NAD83(2011) and the project grids. Points are placed on the page by the same radii, so a length on the page, times the scale, is its ground length.
The picture of the screen map is captured to the frame's bounds and drawn to fill the rectangle. Web Mercator is conformal, so at the frame's latitude its picture has the frame's shape; across the frame the Mercator stretch varies by about the frame's height over the earth's radius, times tan(latitude), which is under 0.01% for a field at 1 in = 50 ft.
The tolerance of a measured length
map-page.test.ts draws a line 400 ft east to west and one 300 ft north to south at 47 degrees north on a letter page at 1 in = 50 ft, reads their coordinates back out of the PDF, and turns the drawn length into feet at the scale. Both come within 0.1% of their ground lengths worked independently by Vincenty's inverse formula on the ellipsoid (Vincenty, T., "Direct and inverse solutions of geodesics on the ellipsoid with application of nested equations", Survey Review 23 (176), 1975). The same line on tabloid at 1 in = 20 ft holds too, and the bar's drawn length is its labeled ground length at the scale.
Why 0.1%: the method is good to far better over a field-sized frame, and the room is for rounding in the numbers written into the file. A larger frame drifts more at its edges, because a flat page can't hold one scale everywhere on a round earth: printFrame reports the drift of the east-west scale at the top edge (edgeScaleDrift), under 0.01% at 1 in = 50 ft and about 0.2% at 1 in = 6,000 ft on tabloid portrait. The tolerance is for the file. A printer that scales the page, or one set to "fit to page", adds its own error, often a percent or more, which is why the scale is also printed as a bar.
How a purpose describes its page
A purpose fills in a MapPageDescription and hands it to buildMapPagePdf, which returns the PDF's bytes. In its last step it first calls planMapPage(description) for the scale and frame, mounts <PrintFrameLayer> with the same center, scale, paper and orientation so the frame shows on the map, captures the screen map to plan.frame.bounds, and builds the page with that picture as map.image.
const description: MapPageDescription = {
paper: "letter",
orientation: "landscape",
title: "Contour map",
subtitle: "Contour lines are 1 ft apart. Bold lines mark every 5 ft.",
map: {
area: { west: -96.802, south: 46.999, east: -96.798, north: 47.001 },
scale: { kind: "stated", feetPerInch: 50 }, // or omit for fit
image: capturedPng, // of planMapPage(description).frame.bounds
baseMapAttribution: attribution,
lines: contours.map((c) => ({ coordinates: c, color: "#6b4f2a" })),
},
key: [
{
label: "Contour, every 1 ft",
swatch: { kind: "line", color: "#6b4f2a" },
},
],
tables: [
{
title: "Heights",
columns: [{ label: "Where" }, { label: "Height", align: "right" }],
rows: [["Highest", "1,012.4 ft"]],
},
],
terrain: { provenance: terrainProvenance, crsEpsg: project.crs_epsg },
};
const pdf = await buildMapPagePdf(description);
A label on the map is "on" its place by default, centered and left out where that crosses the map's edge (index lines' labels are placed clear of it already). A label "right" of a mark, as a high or low point's, goes right of it, or left, above or below where right would cross the edge, and where none fits, inside the map beside the mark; only a mark off the map, or a label wider than the map, goes without (placeMapLabel, map-label-edge.test.ts).
The words a purpose passes (title, subtitle, key labels, table cells) follow the voice, and its file goes on PLAN_V4_COPY_FILES or PLAN_V4_SCREEN_FILES in lib/ui/panel-voice.ts.
The site map (plan v4 item 476)
lib/terrain/site-map-page.ts describes Check a building site's page: the site's outline, the contours (lib/terrain/site-contours.ts, below), the slope bands and the low spots and water paths in the captured picture with their key lines read from the screen's key, the highest and lowest ground with the arrow between them, the outline of the largest piece under the slope chosen, the tallest thing standing where it is mapped, and, only when a pad is placed, the pad and its driveway with their figures, the driveway's profile with its steep stretches marked, and the pad's hours of sun on four days, all in the words the pad's card uses. Its subtitle is the step's one sentence. The tables come bands first, so they print on page one; what doesn't fit goes on page two, and a long sentence is split into rows of at most 56 characters so each cell prints whole (site-map-page.test.ts reads every row back from the PDF).
Contours, kept small to share. siteContours(grid, window, fromGrid, intervalFt?) traces built ground's cells in a window with traceContourLines and gives lines in longitude and latitude at the finest of the worker's intervals (0.5, 1, 2, 5, 10 ft) that keeps the relief to 20 lines or fewer. An interval that would need more than MOST_CONTOUR_LEVELS (2,000) levels, which contourLevels would cut from the top, is stepped up to the next coarser of those five, and where none fits the page draws no contours and names no interval (siteContourIntervalThatFits, review finding F2, 2026-12-02). The contour map's page (PR 54) traces the same way; when the two meet, its page and this one should share one function for "lines over a window of built ground, in longitude and latitude, at a chosen or starting interval", and one for reading key lines from the screen's key, which the water map's page also has (pageKeyFromScreen).
Capturing the screen map
The sight line's page (plan v4 item 495) was the first to put a picture of the screen map on a map page. What it had to work out, for the pages after it, is in apps/web/src/lib/pdf/map-frame-capture.ts, captureMapFrame:
- The picture must be of the frame, not of the screen.
captureMapCanvas, which the printable map uses, takes the whole canvas as it stands. A map page stretches its picture to fill a rectangle of fixed ground size, so a picture of any other ground would print at the wrong scale. The picture is taken ofplanMapPage(description).frame.bounds, and the description handed tobuildMapPagePdfmust have the samepaper,orientationandmap.area(andscaleandcenter, when set), or the picture and the vectors drawn over it won't agree. Work out the plan once and use it for the frame on the map, the capture and the page. - The camera moves, then comes back. It is moved with
cameraForBounds(bounds, { padding: 8, bearing: 0, pitch: 0 })andjumpTo, flat and north up, since the page is north up and a tilted map has no rectangle to cut. It waits for the map'sidle(or four seconds), and is put back where it was afterwards, whatever happens. - The cut is made inside a render frame. The map is made without
preserveDrawingBuffer, so its canvas can be read only during arenderevent. The frame's corners come frommap.projectin CSS pixels; the canvas has more pixels than that on a high-density screen, so they are scaled by the canvas's width over its container's (frameCropRect) and rounded outward. The cut is drawn onto a canvas of its own and saved as a PNG. - The frame's outline is hidden while the picture is taken.
PrintFrameLayer's two layers (PRINT_FRAME_CASING,PRINT_FRAME_LINE) lie exactly on the frame's edge, so they would print as a dashed line round the picture. They are hidden for the capture and shown again after. - The quick look is never in the picture. Nothing printed, saved or downloaded may come from the quick look (plan v4 item 517), and it keeps drawing around built ground wherever the view reaches past it. Both captures,
captureMapFrameandcaptureMapCanvas, go throughhideForCaptureinmap-capture.ts, which hides every layer whose id startsquick-look-relief-, and the map page's dashed frame (print-frame-, so "Save a picture" on a Map page step and the printable map never hold it), along with the layers a caller names, and shows them again after.capture-paths.test.tstakes each capture with a quick look on the map and fails any other file that reads the map's canvas. - When it can't be taken, the page still is. With no map, a frame that doesn't fit on the screen even zoomed out (
frameFits), or a canvas the browser won't read, it gives an empty string, which the description passes asimage: null: the map block says there is no picture and draws the vectors on a plain ground. - What the screen draws is in the picture. The tool's own line and marks are in it, and the page draws its vectors again on top, so they line up with the ground in the picture. Markers that are page elements rather than map layers, such as the sight line's draggable ends, aren't in the canvas and so aren't in the picture; the page draws the points itself.
The zone map page
Zone a field's page (plan v4 item 490, apps/web/src/lib/terrain/zone-map-page.ts) is the second made from a screen capture, and the first whose tables could run wide. It frames the field's outline, prints the zones' sentence as its subtitle, keys each zone in its color and pattern (zoneLook) with the field ("The field"), and draws each zone's outline and the field's over the picture. A table cell prints one line, and a zone's name, a person's name for it and three values of twelve characters don't fit one row on a letter page, so the page prints three short tables: Zones and acres (each zone, the ground with no data, then the field, rounded as the step's table and the Shapefile are so they add up to the field), Zone names and Zone values, each only when something was entered. A soil zone's name can run to sixty characters, so the tables give its map unit symbol, and the key gives the symbol beside the soil's name. Past six soils two zones can share a pattern (soil-zone-labels.ts), so the page sets them apart as the screen map does: each soil zone is labeled with its symbol on the page's map, inside each of its pieces (zonePageMapLabels, the same points as the screen's labels), and where two map units share a symbol, as they can across two soil surveys, the zone's number follows it ("Ba, 2"), on the map, in the key and in the tables alike (soilZoneLabels). The screen's own labels are hidden while the picture is taken, so each prints once. zone-map-page-soils.test.ts reads a page with eight soils, two sharing a symbol: each label its own, on the map inside its zone, beside its soil's name in the key and alone in the tables, and every label, key entry and table cell printed whole on one line. A soil's name long enough to wrap in the key prints over two lines there, its label first. The last table, titled with the line that the zones are grouped by the shape of the land (or, for soil zones, by the soil map's lines), says what they were made from and with what settings. zone-map-page.test.ts reads the PDF back and checks every cell prints whole and that the printed acres add up to the field's.
map-frame-capture.test.ts tests the crop's arithmetic and that the camera and the outline are put back. The picture itself has been seen only in a browser test that checks a PDF downloads; nobody has yet read a printed page against the screen.