// --------------------------------------------------------------------------- // customer-grid / MapView.tsx // "Map" is a VIEW beside Grid/List/Calendar/Kanban, not a module: it projects // the SAME pipeline output the grid paints, so the toolbar count, filters and // sorts mean exactly what they mean on the grid; only the projection changes. // // Wave 8 grows it up (I2/I3/I5/I6, contracts C2/C3/C7): // I2 wheel/pinch zoom, drag to pan, and a box-select that feeds the grid's // OWN selection — so the existing "N selected · Add to cohort" bar serves // the map with no second cohort picker to keep in sync. // I3 colour pins by any single-select field (`display.colorField`) + legend. // I5 size pins by any numeric/measure field (`display.sizeField`) + legend. // I6 a less templatic picture: water wash, land fill, thin C1 strokes, // graticule, hover halos. // // C7 CALL — NO map library, and that call still stands. C7 allowed maplibre-gl // "with a self-hosted vector/raster-free style"; a tileless maplibre would have // rendered exactly the geometry below for +230 KB gz on a 251 KB budget. // // ⭐⭐ WAVE 37 (R3/R14, W37-T35) — THE MAP NOW FETCHES TILES, AND THE OLD NOTE // HERE SAID THE OPPOSITE. It read: "Nothing is fetched and no coordinate leaves // the page unless the user deliberately clicks." That was true for two waves and // is FALSE now, so it is rewritten rather than left to rot. What is true today: // // - a RASTER BASEMAP is fetched, by the browser, straight from the tile // provider. Panning the map therefore tells that provider roughly where you // are looking. It does NOT tell them who: no record, no name and no address // is ever sent, because a tile request carries only a z/x/y grid square that // millions of other people also request; // - the provider is a SEAM, not a vendor. `/api/v1/geo/providers` serves a URL // template plus a credit line, both environment-driven, so pointing this at // a paid vendor is configuration and not a rewrite. That seam is the whole // reason R14 could defer the Google key without dropping the feature; // - the DEFAULT is OpenStreetMap, which needs no key and no billing account. // Its credit line is a LICENCE TERM and is rendered, not optional; // - GEOCODING is still not automatic and never will be from here (R3). It has // its own door, it takes an explicit list of addresses, and it is rate // limited in code. Nothing on this surface geocodes anything; // - if the tiles fail to load, the vendored vector basemap below is still // here and takes over. A map that has lost its network draws the coastline // it always drew rather than an empty rectangle. // // Honesty rules (rule 8b), carried and extended: // - rows WITHOUT coordinates are never silently hidden: the count line reads // "N of M mapped", so the unmapped share is the gap between the two numbers; // - a pin per row at its geocoded position, no clustering and no jitter (two // customers at one address overlap rather than being drawn where they are // not); // - the colour legend STATES it when a field has more choices than the // palette has entries, rather than recycling a colour onto a second meaning; // - a row with no value under the size field gets the smallest dot and the // legend says so — it is never dropped from the map. // --------------------------------------------------------------------------- import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { LogoLoader } from "../ui/LogoLoader"; import type { KeyboardEvent as ReactKeyboardEvent, PointerEvent as ReactPointerEvent, ReactNode } from "react"; import type { CatalogSpec, Conjunction, Field, FilterNode, Row, ViewConfig } from "./types"; import { API_V1, CREDENTIALS, NAV_MINIMIZE_EVENT, signal } from "../apiContract"; import { formatDisplay } from "./cells"; import { readDataPath } from "./dataPath"; import { AppFrame } from "./AppFrame"; // C1: Routing and Catalog are Odoo Apps; verify_icons.py holds these two marks to TEMPLATES. import { AppFrameMarks } from "../apps/templateMarks"; import { CatalogApp } from "../apps/catalog/CatalogApp"; import { RouteApplicationMapView } from "../apps/routing/RouteApplicationMapView"; import type { CatalogApplicationDefinition, CatalogViewSpec } from "./CatalogView"; import { applicationTemplateSurface } from "./viewModes"; import { LAND_PATH, LAKE_PATHS } from "./mapGeometry"; import { routingPreferenceKey, bubbleSizeRange, pointRadius, routeFilterSignatureOf } from "./routePrefs"; import type { RoutingCustomerDetail } from "./RouteNav"; import { RouteCustomerPane } from "./RouteNav"; import { BASEMAP_DETAIL_K, bubbleRadius, magnitudeDomain, cardBox, clientToUser, dashPattern, fitView, formatDuration, fromScreen, googleMapsUrl, googleRouteUrls, googleZoomForK, graticuleOpacity, hairline, haversineKm, isPlottable, normRect, parseLatLon, pathBounds, planRoute, pointInPolygon, project, rotateAt, routeFingerprint, routeRanks, ROUTE_STOP_CAP, toScreen, unproject, WORLD, zoomAt, zoomLimits, } from "./mapProjection"; import type { GeoStop, Pt, RouteStamp, View } from "./mapProjection"; import { LP_INK, LP_MAP_SELECTED, LP_PURPLE, LP_PURPLE_DEEP, LP_RED, LP_RED_DEEP, LP_ZONE_FILL_OPACITY, LP_ZONE_STROKE_WIDTH } from "./theme"; import { GoogleMapsMark, RouteNav } from "./RouteNav"; import { endpointRoutePlan, normalizedRouteMapLinks } from "./routeLinks"; import { fetchRouteDeliveryRecipients, requestRouteDelivery, routeInventoryPath, routeApplicationPath, usesNormalizedCustomerZones, zoneCollectionPath, zoneItemPath, zoneMutationPayload, } from "./routeZoneApi"; import { mapNavigatorMode, routeSourceStopIds, toggleRouteSelection } from "./routeZoneTypes"; // W51-T28 / R6 + C8 — the wave-51 base kit. Every destructive act on this surface goes through // the ONE dialog, and every panel registers its Escape claim with the ONE arbiter. Neither is // re-implemented here: `ConfirmDialog` brings its own portal, focus trap, backdrop and focus // restore, and `useEscapeClose` brings the topmost-wins stack. import { ConfirmDialog } from "../ui/ConfirmDialog"; import { useEscapeClose } from "../ui/useEscapeClose"; import type { MapRouteDto, MapRouteFolderDto, MapRouteSource, MapRouteUpdate, MapZoneDto, RouteDeliveryRecipientDirectory, RouteDeliveryDto, RouteDeliveryRequest, RouteSelectionRequest, RouteSelectionResponse, ZoneGeometry, } from "./routeZoneTypes"; import "./map.css"; import "../styles/wave46/map-panels.css"; import "../styles/sdlc74/routing.css"; /** * W37-T35 — THE PROVIDER SEAM, client side. * * A URL template and a credit line, nothing else. The renderer never learns which company is * behind them, which is exactly what makes swapping in a paid provider a config change (R14). * These constants are the OFFLINE DEFAULT: `/api/v1/geo/providers` overrides them at mount, and * the map still draws if that call never answers. */ interface TileProvider { url: string; attribution: string; attributionUrl: string; maxZoom: number; } const TILES_DEFAULT: TileProvider = { url: "https://tile.openstreetmap.org/{z}/{x}/{y}.png", attribution: "© OpenStreetMap contributors", attributionUrl: "https://www.openstreetmap.org/copyright", maxZoom: 19, }; /** How many tiles one frame may paint. A pathological zoom/pan otherwise asks for thousands, and * a shared free tile service is exactly the wrong place to find that out. */ const TILE_BUDGET = 240; /** ⭐ OWNER ITEM 1 (2026-08-23) — degrees per click of Rotate left / Rotate right, the owner's * own number: *"every click is say rotating the map by 5 degrees"*. 72 clicks is a full turn, * which is why Fit to data doubles as the way back to north. */ const ROTATE_STEP = 5; /** * CSS pixels per SVG user unit, at the width this view is normally painted. * * ⛔ MIRRORED FROM `mapProjection.googleZoomForK`, WHICH HARDCODES THE SAME 1.08 AND DOES NOT * EXPORT IT. Two copies of one number is [[one-question-two-normalizers]], so `verify_map.py` * asserts the constant still reads 1.08 over there. If that gate goes red, these two have drifted * and the tile grid will be one zoom level off the hand-off link it is supposed to agree with. */ const CSS_PX_PER_UNIT = 1.08; /** The inverse of `googleZoomForK`: the camera `k` at which one 256px tile paints at ~256 CSS px. * Used for the zoom ceiling, so "as far in as the provider actually serves" is a number and not * a guess. */ function kForTileZoom(z: number): number { return (256 * Math.pow(2, z)) / (WORLD * CSS_PX_PER_UNIT); } /** Consecutive tile errors before the vendored vector basemap takes back over. Three rather than * one: a single 404 at the edge of coverage is normal and is not an outage. */ const TILE_FAIL_LIMIT = 3; const VIEW_W = 1000; const VIEW_H = 620; const R_MIN = 3.2; const R_MAX = 15; const R_PLAIN = 4.5; const R_NULL = 2.6; /** A synthetic route-only id. Odoo record ids are positive, so zero cannot become a customer. */ const DEPOT_PID = 0; /** * ⭐⭐ OWNER ITEM 9 — ONE SEARCHABLE RECORD PICKER, used twice. * * The owner asked for search in two places at once: the Start dropdown, and a way to add a record * by looking it up in the database. Those are the same control over two different pools, so this * is one component rather than two that drift. * * ⛔ IT IS A FILTERED LIST, NOT A FLOATING COMBOBOX, and that is deliberate. The route panel is * already an absolutely positioned `