Skip to content

API Reference

Kohei Otsuka edited this page Jul 24, 2026 · 1 revision

API Reference

Concepts and usage patterns for the Tin class exposed by MaplatTin. This page focuses on release-independent explanatory material (ADR-0012). For the complete and up-to-date API signature list, see docs/api/ in the repository.

Table of Contents


Tin lifecycle

The Tin class is the main class of MaplatTin. Its lifecycle has three phases:

  1. Constructionnew Tin(options) creates an instance. Either bounds or wh must be specified.
  2. Pre-computationsetPoints(points) (and optionally setEdges(edges)) feeds control data. updateTin() then computes the TIN. After this resolves, strict_status indicates whether strict topology was achieved.
  3. Transformtransform(xy, inverse) converts coordinates. The instance is reusable: calling setPoints / setWh / setEdges again resets the TIN and updateTin() must be called once more.

Why an explicit updateTin()? Solving the triangulation is the expensive step. Separating configuration (setPoints) from computation (updateTin) lets callers batch edits and compute once.

Serialization shortcut: setCompiled(data) skips updateTin() by loading a previously serialized TIN. See Tutorials § Saving and restoring.

Option categories

The options object passed to the constructor has several categories:

Category Key properties Purpose
Geometry bounds, wh Boundary polygon OR width/height of source plane (one required)
Vertex handling vertexMode "plain" (default) or "birdeye" (perspective correction)
Topology strictMode "strict", "auto" (default), or "loose"
Y-axis yaxisMode "follow" or "invert" (default)
Metadata importance, priority Map importance/priority hints (used by MaplatCore)

The options control transform behavior. The control points and edges are added separately via setPoints / setEdges (after construction), so the same Tin instance can be reused with different GCP sets.

Usage patterns

Pattern 1: CDN minimal usage

<script src="https://cdn.jsdelivr.net/npm/@maplat/tin@0.14.2/dist/maplat_tin.umd.js"></script>
<script>
  const tin = new maplatTin.default({ wh: [500, 500] });
  tin.setPoints([
    [[100, 100], [200, 200]],
    [[200, 200], [400, 400]],
    [[150, 150], [320, 350]],
    [[200, 100], [420, 220]],
  ]);
  tin.updateTin();
  console.log(tin.transform([160, 160], false));
</script>

Pattern 2: npm ESM import

import Tin from '@maplat/tin';

const tin = new Tin({ wh: [500, 500] });
tin.setPoints([/* ... */]);
tin.updateTin();

Pattern 3: Node.js offline preprocessing

MaplatTin runs in pure Node.js (no OpenLayers needed), so it can be used in batch preprocessing pipelines (e.g. with MaplatTransform):

import Tin from '@maplat/tin';
import { readFileSync, writeFileSync } from 'node:fs';

const tin = new Tin({ wh: [2000, 1500] });
tin.setPoints(JSON.parse(readFileSync('gcps.json')));
tin.updateTin();
writeFileSync('compiled.json', JSON.stringify(tin.getCompiled()));

API signature reference

The complete API signature list (constructor options, methods, constants, utility functions, error cases) is maintained in docs/api/ in the repository. This Wiki page intentionally does not duplicate the signatures to avoid divergence from the source of truth.

See:


日本語版はこちら / Read this page in Japanese

See Also

MaplatTin

Language / 言語

Pages / ページ

English

日本語

External / 外部

Clone this wiki locally