Give satellite imagery, terrain data, buildings, streetview photos to your LLM
Add planning time warnings
Belluxx78d49bcd2486
diff --git a/src/capture.py b/src/capture.pyindex baf275b..0c3b58a 100644--- a/src/capture.py+++ b/src/capture.py@@ -12,7 +12,7 @@ from PIL import Imagefrom . import mesh, satellite, streetview, terrainfrom .common import WORKERS, MissingImagery, contained, fetch, now, number, open_image, positive, write_bytes, write_json-from .geo import MERCATOR_RADIUS, bounds, collection, coordinate, feature, grid, pixel, tile_ring, tiles+from .geo import MERCATOR_RADIUS, RADIUS, bounds, collection, coordinate, distance, feature, grid, pixel, tile_ring, tilesSOURCES = ("streetview", "satellite", "osm", "terrain", "mesh")FORMAT_VERSION = 5@@ -25,10 +25,11 @@ DEFAULT_OPTIONS = dict(# Average sequential request timings, just to give an idea to the user, not preciseREQUEST_SECONDS = dict(metadata=0.17, photo=0.46, sphere_tile=0.27, satellite_tile=0.25, terrain_tile=1.39,- mesh_node=0.34)+ mesh_node=0.34, coverage_tile=0.25, mesh_bulk=0.45)# Options choosing how many requests of each kind run in parallel.REQUEST_WORKERS = dict(sphere_tile="streetview_workers", satellite_tile="satellite_workers",- terrain_tile="terrain_workers", mesh_node="mesh_workers")+ terrain_tile="terrain_workers", mesh_node="mesh_workers", coverage_tile="streetview_workers",+ mesh_bulk="mesh_workers")SPHERE_TILES = (1, 2, 8, 32, 128, 512)OSM_EXPORT_SECONDS = 10@@ -161,17 +162,45 @@ def estimate(run):else:counts["terrain_tiles"] = requests["terrain_tile"] = remainingoptions = run["options"]-- def workers(kind):- # Requests run one at a time when the user asks for pauses between them.- return 1 if options["delay"] or kind not in REQUEST_WORKERS else options[REQUEST_WORKERS[kind]]-- seconds = sum(count * REQUEST_SECONDS[kind] / workers(kind) for kind, count in requests.items())+ seconds = sum(count * REQUEST_SECONDS[kind] / workers(options, kind) for kind, count in requests.items())seconds += counts["osm_maps"] * OSM_EXPORT_SECONDSseconds += max(0, sum(requests.values()) - 1) * options["delay"]return dict(counts, seconds=math.ceil(seconds))+def workers(options, kind):+ # Requests run one at a time when the user asks for pauses between them.+ return 1 if options["delay"] or kind not in REQUEST_WORKERS else options[REQUEST_WORKERS[kind]]+++def planning(area, options):+ """Rough seconds that planning Street View and 3D mesh spends on requests, by mode.++ Street View lists panoramas in every zoom-17 tile. 3D mesh lists octree nodes four levels at a+ time, one level after another, from the nodes meeting the area; nodes at level n are about+ 2πR / 2^n wide, and measured counts run about twice that footprint as nodes stack up over terrain+ and buildings. Excludes reading roads and the first download of a regional OSM file.+ """+ result = {}+ if "streetview" in options["include"]:+ g = grid(area, 17)+ count = g["rows"] * g["columns"]+ result["streetview"] = count * (REQUEST_SECONDS["coverage_tile"] / workers(options, "coverage_tile")+ + options["delay"])+ if "mesh" in options["include"]:+ south, west, north, east = area+ middle = (south + north) / 2+ width, height = distance((middle, west), (middle, east)), distance((south, west), (north, west))+ seconds = 0+ for level in range(0, options["mesh_level"], 4):+ size = 2 * math.pi * RADIUS / 2**level+ count = 1 if level == 0 else 2 * (width / size + 1) * (height / size + 1)+ seconds += math.ceil(count / workers(options, "mesh_bulk")) * REQUEST_SECONDS["mesh_bulk"]+ seconds += count * options["delay"]+ result["mesh"] = seconds+ return {mode: math.ceil(seconds) for mode, seconds in result.items()}++def resolution(area, zoom, tile_size=256):"""Approximate ground meters per pixel at the middle of the area."""latitude = math.radians((area[0] + area[2]) / 2)diff --git a/src/dashboard.py b/src/dashboard.pyindex 80f2a98..60003a0 100644--- a/src/dashboard.py+++ b/src/dashboard.py@@ -340,6 +340,7 @@ class Dashboard:stage = dict(mode=mode, grid=grid(area, options[f"{mode}_zoom"]), results=[])result[mode] = dict(imagery(area, stage, 512 if mode == "terrain" else 256),seconds=capture.estimate(dict(stages=[stage], options=options))["seconds"])+ result["planning"] = capture.planning(area, options)return resultcase "POST", ["api", "plan"]:return self.plan(body)diff --git a/src/web/app.js b/src/web/app.jsindex 3fb1009..753b0b6 100644--- a/src/web/app.js+++ b/src/web/app.js@@ -31,7 +31,20 @@ const ICONS = {sides: '<circle cx="12" cy="12" r="2"/><path d="M8 12H3m3-3-3 3 3 3M16 12h5m-3-3 3 3-3 3"/>',sphere: '<circle cx="12" cy="12" r="9"/><ellipse cx="12" cy="12" rx="9" ry="3.5"/><ellipse cx="12" cy="12" rx="3.5" ry="9"/>',pencil: '<path d="M4 20l1.2-4.2L16.5 4.5l3 3L8.2 18.8zM14.5 6.5l3 3"/>',+ bolt: '<path d="M13.5 2 5 13.5h6.5L10.5 22 19 10.5h-6.5z"/>',+ clock: '<circle cx="12" cy="12" r="9"/><path d="M12 6.5V12l3.5 2.5"/>',+ turtle: '<path d="M2.5 16a7.5 7 0 0 1 15 0zM5.5 16v3M14.5 16v3M17 13.5h3.5a1.75 1.75 0 0 0 0-3.5H19M7 16l1.5-4.5h3L13 16"/>',+ warning: '<path d="M12 3 22 20H2zM12 9v5.5M12 16v1.8"/>',+ error: '<path d="M8.3 3h7.4L21 8.3v7.4L15.7 21H8.3L3 15.7V8.3zM9 9l6 6M15 9l-6 6"/>',};+// Planning times are shown coarsely, since the estimate is rough, rounded to the nearest unit at half of it.+// Hours or more ask before planning.+const SPEEDS = [{limit: 30, name: "seconds", icon: "bolt"}, {limit: 1800, name: "minutes", icon: "clock"},+ {limit: 12 * 3600, name: "hours", icon: "turtle"},+ {limit: 3.5 * 86400, name: "days", icon: "warning", alert: true},+ {limit: 15 * 86400, name: "weeks", icon: "error", alert: true},+ {limit: Infinity, name: "months", icon: "error", alert: true}];+const SLOW_PLAN = SPEEDS[1].limit;// Progress phases that a capture stage row already shows.const DOWNLOADS = new Set(["Street View", "Satellite", "Downloading terrain tiles", "3D mesh"]);@@ -83,6 +96,7 @@ function megapixels(width, height) {const total = width * height / 1e6;return `${total < 1 ? total.toLocaleString("en-US", {maximumSignificantDigits: 2}) : number(total)} MP`;}+const speed = seconds => SPEEDS.find(s => seconds < s.limit);const megabytes = bytes => bytes >= 1e9 ? `${(bytes / 1e9).toFixed(1)} GB` : bytes >= 1e6 ? `${(bytes / 1e6).toFixed(1)} MB`: `${Math.max(1, Math.round(bytes / 1e3))} KB`;@@ -472,24 +486,34 @@ function renderPreviewButton() {let estimateTimer = null;let estimateCount = 0;+// Imagery sizes and download times, and how long Street View and 3D mesh take to plan.+async function fetchEstimate() {+ const {include, satellite_zoom, terrain_zoom, mesh_level, streetview_workers, satellite_workers, terrain_workers,+ mesh_workers, delay} = readForm();+ if (!state.area || include.every(mode => mode === "osm")) return {};+ try {+ return await api("/api/estimate", {bounds: state.area, options: {include, satellite_zoom, terrain_zoom, mesh_level,+ streetview_workers, satellite_workers, terrain_workers, mesh_workers, delay}});+ } catch {+ return {}; // Invalid values are reported by Preview.+ }+}+function estimate() {clearTimeout(estimateTimer);estimateTimer = setTimeout(async () => {const count = ++estimateCount;- const {include, satellite_zoom, terrain_zoom, satellite_workers, terrain_workers, delay} = readForm();const outputs = {satellite: $("[data-source=satellite] .estimate"), terrain: $("[data-source=terrain] .estimate")};const details = {satellite: $("[data-detail=satellite]"), terrain: $("[data-detail=terrain]")};- let result = {};- if (state.area && (include.includes("satellite") || include.includes("terrain"))) {- try {- result = await api("/api/estimate", {bounds: state.area, options:- {include, satellite_zoom, terrain_zoom, satellite_workers, terrain_workers, delay}});- } catch {- // Invalid values are reported by Preview.- }- }+ const result = await fetchEstimate();if (count !== estimateCount) return;- const {satellite, terrain} = result;+ const {satellite, terrain, planning = {}} = result;+ for (const mode of ["streetview", "mesh"]) {+ const pace = planning[mode] == null ? null : speed(planning[mode]);+ const output = $(`[data-source=${mode}] .estimate`);+ output.innerHTML = pace ? `${icon(pace.icon)}${pace.name} to plan` : "";+ output.classList.toggle("alert", !!pace?.alert);+ }outputs.satellite.textContent = satellite ? `${plural(satellite.tiles, "tile")} (~${duration(satellite.seconds)})` : "";details.satellite.textContent = satellite? `${resolution(satellite.meters_per_pixel)} (${megapixels(satellite.width, satellite.height)})` : "";@@ -611,6 +635,8 @@ async function previewPlan(event) {const error = $("#settings-error");error.hidden = true;if (!state.area) return;+ const {planning = {}} = await fetchEstimate();+ if (!await confirmPlan(planning, readForm())) return;Object.assign(state, {preview: null, planError: null});setData("plan", EMPTY);try {@@ -625,6 +651,24 @@ async function previewPlan(event) {poll();}+// Ask before planning that takes hours or days; resolves true to plan anyway.+function confirmPlan(planning, options) {+ const total = Object.values(planning).reduce((sum, seconds) => sum + seconds, 0);+ if (total < SLOW_PLAN) return Promise.resolve(true);+ const slow = Object.entries(planning).filter(([, seconds]) => seconds >= SLOW_PLAN).sort((a, b) => b[1] - a[1]);+ // Levels above 20 also list every level-20 node, which multiplies the lookups.+ const level = slow.some(([mode]) => mode === "mesh") && options.mesh_level > 20;+ const dialog = $("#slow-plan");+ const pace = speed(total);+ $("h2", dialog).innerHTML = `${icon(pace.icon)}Planning will take ${pace.name}`;+ $("h2", dialog).classList.toggle("alert", !!pace.alert);+ $("p", dialog).textContent = `${slow.map(([mode, seconds]) => `${NAMES[mode]} needs ${speed(seconds).name}`).join(" and ")+ } of lookups before the preview appears. Draw a smaller area${level ? " or set 3D mesh detail to 20 or lower" : ""}.`;+ dialog.returnValue = "";+ dialog.showModal();+ return new Promise(resolve => dialog.addEventListener("close", () => resolve(dialog.returnValue === "plan"), {once: true}));+}+function showPlan() {setData("plan", state.preview.layers);map.fitBounds(lngLatBounds(state.preview.bounds), {padding: 80, maxZoom: 18, duration: 600});diff --git a/src/web/index.html b/src/web/index.htmlindex e50ccd2..4724f72 100644--- a/src/web/index.html+++ b/src/web/index.html@@ -210,6 +210,17 @@</section></aside>+ <dialog id="slow-plan">+ <form method="dialog">+ <h2></h2>+ <p class="detail"></p>+ <div class="buttons">+ <button value="plan" class="subtle">Preview anyway</button>+ <button value="" class="primary" autofocus>Change settings</button>+ </div>+ </form>+ </dialog>+<main class="stage"><div id="map"></div><form id="search" class="search" role="search">diff --git a/src/web/style.css b/src/web/style.cssindex cbba070..aa94a1c 100644--- a/src/web/style.css+++ b/src/web/style.css@@ -176,6 +176,9 @@ button:disabled:hover { background: transparent; color: var(--ink); }.accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }.accent:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }.small { padding: 3px 8px; font-size: 12px; }+/* A quiet choice, for actions the page discourages. */+.subtle { border-color: transparent; color: var(--muted); font-weight: 400; text-decoration: underline; text-underline-offset: 3px; }+.subtle:hover { background: transparent; color: var(--ink); }.wide { width: 100%; }:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }@@ -300,7 +303,9 @@ input[type=range]::-moz-range-thumb { width: 24px; height: 18px; border: 0; bordfont-weight: 600;cursor: pointer;}-.estimate { margin-left: auto; color: var(--muted); font: 400 11px var(--mono); }+.estimate { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; color: var(--muted); font: 400 11px var(--mono); }+.estimate .icon { width: 13px; height: 13px; }+.estimate.alert, dialog h2.alert { color: var(--accent); }.source .fields { display: none; padding: 0 0 14px 23px; }.source.on .fields { display: grid; gap: 9px; }@@ -441,6 +446,18 @@ input[type=range]::-moz-range-thumb { width: 24px; height: 18px; border: 0; bordz-index: 2;}+dialog {+ width: min(380px, calc(100% - 32px));+ padding: 20px;+ border: 1px solid var(--ink);+ background: var(--paper);+ color: var(--ink);+}+dialog::backdrop { background: color-mix(in srgb, var(--ink) 30%, transparent); }+dialog h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font: 600 15px var(--sans); }+dialog h2 .icon { width: 20px; height: 20px; }+dialog .buttons { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }+.viewer {position: absolute;right: 16px;