A JavaScript library that performs coordinate transformation between two plane coordinate systems using transformation definitions generated by Maplat. This is part of the Maplat project.
日本語のREADMEはこちら
- Import Transformation Definitions: Import and build internal structures from transformation definitions generated by Maplat
- Bidirectional Coordinate Transformation: Convert coordinates between two planes in both directions
- Topology Preservation: Maintains homeomorphic properties during transformation
- Multiple Coordinate System Support: Handles transformations between various coordinate systems including standard orthogonal coordinates, Y-axis inverted coordinates, and distorted coordinates like bird's-eye views
- State Management: Save and restore transformation states
- Node.js: >= 20
- pnpm: >= 9 (for development)
pnpm add @maplat/transformnpm install @maplat/transform<script src="https://unpkg.com/@maplat/transform/dist/maplat_transform.umd.js"></script>import { Transform } from '@maplat/transform';
// Import transformation definition
const transform = new Transform();
transform.setCompiled(compiledData); // Apply transformation definition generated by Maplat
// Forward transformation (source → target coordinate system)
const transformed = transform.transform([100, 100], false);
// Backward transformation (target → source coordinate system)
const restored = transform.transform(transformed, true);The library may throw errors in the following cases:
- Transformation errors in strict mode
- Attempting backward transformation when not allowed
- Invalid data structure during transformation
If errors occur, the transformation definition data needs to be modified. Please use editor tools that incorporate @maplat/tin to modify transformation definitions.
The main class for coordinate transformation.
const transform = new Transform();Import and apply a compiled transformation definition generated by Maplat.
- Parameters:
compiled: Compiled transformation definition object
Perform coordinate transformation.
- Parameters:
apoint: Coordinate to transform[x, y]backward: Whether to perform backward transformation (default:false)ignoreBounds: Whether to ignore boundary checks (default:false)
- Returns: Transformed coordinate or
falseif out of bounds - Throws: Error if backward transformation is attempted when
strict_status == "strict_error"
Vertex Modes:
Transform.VERTEX_PLAIN: Standard plane coordinate systemTransform.VERTEX_BIRDEYE: Bird's-eye view coordinate system
Strict Modes:
Transform.MODE_STRICT: Strict transformation modeTransform.MODE_AUTO: Automatic mode selectionTransform.MODE_LOOSE: Loose transformation mode
Strict Status:
Transform.STATUS_STRICT: Strict statusTransform.STATUS_ERROR: Error status (backward transformation not allowed)Transform.STATUS_LOOSE: Loose status
Y-axis Modes:
Transform.YAXIS_FOLLOW: Follow Y-axis directionTransform.YAXIS_INVERT: Invert Y-axis direction
PointSet,BiDirectionKey,WeightBufferBD,VertexMode,StrictMode,StrictStatus,YaxisModeCentroidBD,TinsBD,KinksBD,VerticesParamsBD,IndexedTinsBDCompiled,CompiledLegacyTins,Tri,PropertyTriKeyEdge,EdgeSet,EdgeSetLegacy
transformArr: Low-level coordinate transformation functionrotateVerticesTriangle: Rotate vertices of a trianglecounterTri: Counter triangle utilitynormalizeEdges: Normalize edge definitions
import { format_version } from '@maplat/transform';
console.log(format_version); // Current format versionFor detailed technical information about the transformation internals, see:
- Transform Internals - Runtime notes on how Transform class reconstructs state and performs coordinate lookups
pnpm testThis library specializes in executing coordinate transformations and does not include functionality for generating or editing transformation definitions. If you need to create or edit transformation definitions, please use the @maplat/tin package.
Maplat Limited License 1.1
Copyright (c) 2025 Code for History
- Kohei Otsuka
- Code for History
We welcome your contributions! Feel free to submit issues and pull requests.