-
-
Notifications
You must be signed in to change notification settings - Fork 3
Tutorials
Step-by-step guides for using MaplatTin in Node.js and the browser.
Note: For the latest quick start (install commands, CDN URLs, version numbers), see the README. This page covers release-independent tutorial material.
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('Topology OK: roundtrip transform is guaranteed');
} else if (tin.strict_status === Tin.STATUS_LOOSE) {
console.log('Topology warning: roundtrip transform is not guaranteed');
}
// Forward transform
const ord = tin.transform([160, 160], false);
console.log(ord);
// Backward transform
const rev = tin.transform(ord, true);
console.log(rev);Note on method name: The historical wiki documented
updateTinAsync()returning a Promise. The current API exposesupdateTin()(synchronous after the internal computation completes). Seedocs/api/for the authoritative signature.
<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><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>The legacy script
maplat_tin.js(note the underscore) referenced in the old wiki is the same UMD bundle; the current package name is@maplat/tin(scoped). Use the scoped name in all new code.
Solving the TIN network from many control points is expensive. MaplatTin supports object serialization so the solved state can be reused.
// After updateTin()
const compiled = tin.getCompiled();
// Later, in another process
const tin2 = new Tin();
tin2.setCompiled(compiled);
// No updateTin() call is needed — the triangulation is already loaded.
console.log(tin2.transform([160, 160], false));try {
tin.updateTin();
} catch (e) {
if (e === 'TOO LINEAR1' || e === 'TOO LINEAR2') {
console.log('Given GCP points are too linear; cannot build TIN.');
} else if (e === 'SOME POINTS OUTSIDE') {
console.log('Some points are outside the boundary.');
} else {
throw e;
}
}For the complete list of error cases, see
docs/api/ Error handling section.
日本語版はこちら / Read this page in Japanese
- Home
- Concepts — TIN theory and strict/loose modes
- API-Reference — API concepts and usage patterns
- README — latest quick start
-
docs/api/— authoritative API signatures
- 🇬🇧 English (Home)
- 🇯🇵 日本語 (Home.ja)
English
日本語
- 📄 README / README.ja
- 📚 docs/api/ — API signatures
- 🗺️ Ecosystem Map(現在外部非公開)
- 🌐 Product site / 製品サイト
- 🏢 Nayuta, Inc. / コーポレートサイト