Skip to content

Tutorials.ja

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

Tutorials(日本語)

Node.js およびブラウザから MaplatTin を利用するためのステップバイステップガイドです。

: 最新のクイックスタート(インストールコマンド・CDN URL・バージョン番号)は README を参照してください。本ページはリリース非依存の チュートリアルを扱います。

目次


1. Node.js での利用

import Tin from '@maplat/tin';

const tin = new Tin({
  wh: [500, 500],
  yaxisMode: Tin.YAXIS_FOLLOW,
});

tin.setPoints([
  [[100, 100], [200, 200]],
  [[200, 200], [400, 400]],
  [[150, 150], [320, 350]],
  [[200, 100], [420, 220]],
]);

tin.updateTin();

if (tin.strict_status === Tin.STATUS_STRICT) {
  console.log('トポロジーOK: 往復変換が保証されます');
} else if (tin.strict_status === Tin.STATUS_LOOSE) {
  console.log('トポロジー警告: 往復変換が保証されません');
}

// 順方向の変換
const ord = tin.transform([160, 160], false);
console.log(ord);

// 逆方向の変換
const rev = tin.transform(ord, true);
console.log(rev);

メソッド名に関する注記: 旧 Wiki では updateTinAsync() が Promise を 返すと記載されていました。現行 API は updateTin()(内部計算完了後は同期)を 公開しています。正本のシグネチャは docs/api/ を 参照してください。

2. ブラウザでの利用

UMD

<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>

ES Modules

<script type="module">
  import Tin from 'https://cdn.jsdelivr.net/npm/@maplat/tin@0.14.2/dist/maplat_tin.js';
  const tin = new Tin({ wh: [500, 500] });
  // ...
</script>

旧 Wiki が参照していたレガシースクリプト maplat_tin.js(アンダースコア表記) は同じ UMD バンドルです。現在のパッケージ名は @maplat/tin(スコープ付き)で す。新規コードではスコープ付き名を使用してください。

3. 解決済み TIN の保存と復元

多数の制御点から TIN ネットワークを解く処理は重いです。MaplatTin は オブジェクト直列化をサポートし、解決済み状態を再利用できます。

// updateTin() 後
const compiled = tin.getCompiled();

// 後で別プロセスで
const tin2 = new Tin();
tin2.setCompiled(compiled);
// updateTin() の呼出は不要 — 三角分割は既に読込済み。

console.log(tin2.transform([160, 160], false));

4. エラーハンドリング

try {
  tin.updateTin();
} catch (e) {
  if (e === 'TOO LINEAR1' || e === 'TOO LINEAR2') {
    console.log('与えられた GCP 点が直線状に並びすぎており、TIN を構築できません。');
  } else if (e === 'SOME POINTS OUTSIDE') {
    console.log('一部の点が境界の外にあります。');
  } else {
    throw e;
  }
}

エラーケースの完全な一覧は docs/api/ のエラーハンドリング節を参照してください。


英語版はこちら / Read this page in English

関連項目

MaplatTin

Language / 言語

Pages / ページ

English

日本語

External / 外部

Clone this wiki locally