docs

    CHRTinteract

    Click-to-inspect for CHRT charts. One call turns raw S-57 tile attributes into decoded, human-readable feature details — light characteristics ("Fl(2+1) W 10s"), flash timing, sector arcs, bridge clearances, restrictions, and seasonal notes.

    Overview

    CHRT vector tiles preserve the underlying S-57 attributes (LITCHR, COLOUR, SIGPER, OBJNAM, …), but those codes are cryptic on their own. CHRTinteract is the decode intelligence: it merges co-located S-57 objects (a buoy's light, fog signal, and topmark are separate features), translates every code through the same tables the CHRT platform uses, and returns a typed InspectResult you can render however you like.

    Included with the Dev plan and above. The entitlement is checked server-side when you attach — Free-plan keys receive a typed interact_not_enabled error with an upgrade hint.

    CHRTinteract is for situational awareness, not primary navigation. CHRT is not an ECDIS and is not SOLAS-compliant. Every result carries this disclaimer, the issuing hydrographic-office attribution, and the data currency.

    Quickstart — attach to a map

    chrt.interact.attach(map) wires click-to-inspect onto the MapLibre or Mapbox GL map you already have. With no options it shows the built-in minimal popup:

    map.ts
    import { Chrt } from "@chrtco/sdk";
    import maplibregl from "maplibre-gl";
    
    const chrt = new Chrt("chrt_sk_live_...");
    
    const map = new maplibregl.Map({
      container: "map",
      style: chrt.style({ palette: "DAY" }),
      transformRequest: chrt.transformRequest(),
      center: [-70.9, 42.35],
      zoom: 13,
    });
    
    map.on("load", async () => {
      // Server-checked: resolves for Dev+ keys, throws InteractError for Free.
      const handle = await chrt.interact.attach(map);
      // later: handle.detach();
    });

    Headless mode — render your own UI

    Pass onInspect to receive every decoded result and skip the built-in popup (add popup: true to keep both). The result is a discriminated union on kind: "navaid" | "bridge" | "area".

    headless.ts
    const handle = await chrt.interact.attach(map, {
      onInspect: (result, ctx) => {
        result.title;               // 'Weymouth Back River Channel Lighted Buoy 8'
        result.objectClass;         // 'Lateral Buoy'
        result.properties;          // [{ label: 'Colour', value: 'Red' }, ...]
        result.notice.disclaimer;   // non-SOLAS disclaimer — always present
        result.notice.attribution;  // issuing hydrographic office
        result.notice.dataCurrency; // edition / update / issue date (after enrich)
    
        if (result.kind === "navaid") {
          result.characteristic;         // 'Fl R 4s'
          result.navAid.topmarkMeaning;  // 'Port-hand mark'
          result.navAid.status;          // 'Periodic/intermittent'
          result.navAid.sectors;         // sector arcs for sector lights
          result.flashPattern;           // on/off phase timing for animation
        }
        if (result.kind === "bridge") {
          result.bridge.verticalClearanceClosed; // 4.0 (metres)
          result.bridge.verticalClearanceOpen;   // 41.1
        }
      },
      onMiss: ({ lngLat }) => console.log("no feature at", lngLat),
    });

    The click pipeline mirrors the first-party CHRT map: navigational aids win over bridges, bridges win over area features, and co-located S-57 child objects (LIGHTS, FOGSIG, TOPMAR, RTPBCN, parent buoy names) are merged before decoding — clicking an unnamed light on a lighted buoy still resolves the buoy's name, colour, and topmark.

    Multiple features under one click

    Real harbors stack: a buoy sits on a channel over a depth area. A click collects every feature under it (within a configurable tolerance pixel radius for point and line targets — default 8px), deduplicates features split across tile boundaries by their S-57 identity (LNAM), folds a buoy's child objects into one entry, and orders the result by class priority: points > lines > areas, safety-critical classes first within each band. Area features never preempt the buoy on top of them, but they stay selectable — a click on open water resolves to its depth area (DEPARE).

    How a multi-feature click behaves depends on the mode:

    • Built-in popup — shows a candidate list; picking a row opens the result card.
    • onCandidates — your UI receives the ordered candidates; resolve a choice with ctx.select(candidate).
    • onInspect only — the top candidate is inspected immediately, and clicking the same spot again cycles to the next candidate (buoy → channel → depth area → back to the buoy).
    candidates.ts
    const handle = await chrt.interact.attach(map, {
      onCandidates: (candidates, ctx) => {
        candidates.map((c) => `${c.title} (${c.objectClass})`);
        // ['Buoy 8 (Lateral Buoy)', 'Submarine Cable', 'Depth Area 9.1–18.2m']
        candidates[0].targetClass;       // 'point' | 'line' | 'area'
        candidates[0].collapsedChildren; // ['LIGHTS', 'TOPMAR'] — folded into the buoy
        candidates[0].notice.disclaimer; // invariant — on every candidate too
    
        // Render your own picker, then:
        ctx.select(candidates[2]).then((result) => {
          result.kind; // 'area' — the DEPARE under the buoy
        });
      },
      tolerance: 12, // px hit radius for point/line targets (default 8)
    });

    Headless without a map event, chrt.interact.inspectAll() returns the same candidate list for any point — screen pixels or [lng, lat]:

    inspectAll.ts
    const { candidates, select } = await chrt.interact.inspectAll(map, e.point);
    // candidates: deduped, priority-ordered InspectCandidate[]
    const result = await select(candidates[0]);          // full decode + merge
    const enriched = await select(candidates[0], { enrich: true }); // + provenance

    Inspect a single feature

    chrt.interact.inspect(feature) decodes one feature without a map — pass anything from queryRenderedFeatures(), the features API, or a plain object. The first call performs the same server-side entitlement check.

    inspect.ts
    const result = await chrt.interact.inspect(
      { properties: { LITCHR: "2", SIGPER: "4", COLOUR: '["3"]' } },
      { layer: "LIGHTS", coordinates: [-70.66, 43.09] },
    );
    result.kind;                                  // 'navaid'
    if (result.kind === "navaid") result.characteristic; // 'Fl R 4s'

    Enrichment — full properties + data currency

    Tiles carry a rendering-oriented subset of S-57 attributes and no cell metadata. Pass enrich: true to resolve the feature through the CHRT features API and its source cell through the cells API — full S-57 properties plus the cell's edition, update_number, and issue_date.

    enrich.ts
    const result = await chrt.interact.inspect(feature, { enrich: true });
    
    result.enrichment?.properties;  // full S-57 properties from the source data
    result.enrichment?.cellId;      // 'US5MA28M'
    result.enrichment?.cell?.edition;        // 13
    result.enrichment?.cell?.update_number;  // 4
    result.enrichment?.cell?.issue_date;     // '2026-05-02'
    result.notice.dataCurrency;     // 'Edition 13, update 4, issued 2026-05-02.'
    
    // Or enrich every click:
    await chrt.interact.attach(map, { enrich: true, onInspect: render });

    Metering: enrichment calls GET /v1/features with your API key and counts against your monthly featureCalls quota (each enrich returns at most 5 candidate features). The cell-metadata lookup is not metered. Un-enriched decoding is free — it runs entirely on attributes already in your tiles.

    Entitlement & errors

    CHRTinteract is included with Dev, Pro, and World plans (and Enterprise). The gate is enforced server-side at attach time via POST /v1/interact/entitlement — the SDK calls it for you and caches the grant per client. Denials never wire any handlers.

    errors.ts
    import { InteractError } from "@chrtco/sdk";
    
    try {
      await chrt.interact.attach(map);
    } catch (err) {
      if (err instanceof InteractError) {
        switch (err.code) {
          case "interact_not_enabled":
            // Free plan — err.plan === 'free'; err.message includes the upgrade URL
            showUpgradeBanner(err.message);
            break;
          case "invalid_api_key":   // key unknown, disabled, or expired
          case "missing_scope":     // key was narrowed to exclude interact
          case "network_error":     // transient — safe to retry
            break;
        }
      }
    }
    CodeMeaning
    interact_not_enabledThe team's plan doesn't include CHRTinteract (Free). Upgrade to Dev or above.
    invalid_api_keyKey unknown, disabled, or expired.
    missing_scopeThe key's scopes were explicitly narrowed (e.g. a tiles-only embed key). Add interact:read or use default scopes.
    enrich_failedThe features/cells lookup failed (including a 429 quota exhaustion).
    unknown_layerinspect() couldn't resolve the feature's chart layer — pass { layer }.
    network_error / unexpected_responseTransport failure / unrecognized server response.

    Key scopes: keys with the default scope set (tiles:read, features:read, cells:read) or data:read pass automatically on Dev+ teams. A key narrowed to tiles:read only (a common pattern for public embeds) is denied unless you explicitly add the interact:read scope.

    The built-in popup

    The default popup is deliberately minimal — plain DOM, no framework, ~3 KB. It shows the decoded title, an animated flash badge for lit aids, the decoded property rows, and a footer with the non-SOLAS disclaimer, source attribution, and data currency (the footer is an invariant — it cannot be disabled). Theme it with CSS custom properties:

    theme.css
    :root {
      --chrt-interact-bg: #0b1524;
      --chrt-interact-fg: #e2e8f0;
      --chrt-interact-muted: #94a3b8;
      --chrt-interact-border: rgba(148, 163, 184, 0.25);
      --chrt-interact-font: "Inter", system-ui, sans-serif;
    }

    For the full CHRT-styled experience (timing diagrams, sector-arc overlays), render your own UI from the InspectResult — the decoded data is complete, and buildSectorArcsFC() is exported for drawing sector arcs as a GeoJSON source. A React component kit is a fast-follow.

    Safety invariants

    Every InspectResult carries a notice with the non-SOLAS disclaimer, hydrographic-office attribution, and data currency. If you build your own UI on CHRTinteract, surface all three — it's a condition of the data license, and it's how your users know what they're looking at. Never present decoded chart data as authoritative for navigation.

    For situational awareness only — not for primary navigation. CHRT is not an ECDIS and is not SOLAS-compliant.

    CHRT uses only the cookies and local storage the site needs to work — keeping you signed in, remembering your preferences, and protecting the forms. There is no analytics, no advertising and no cross-site tracking, so there is nothing here to opt out of. Privacy Policy