@territory-kit/core
v1.2.0
Published
Core TerritoryKit zone engine, hierarchy, adjacency, and spatial queries.
Readme
@territory-kit/core
Core TerritoryKit engine APIs for hierarchical zones, spatial lookup, adjacency, bounds queries, and zoom-level transitions.
Installation
pnpm add @territory-kit/core @territory-kit/datasetBasic Usage
import { readFile } from "node:fs/promises";
import { createTerritoryEngine } from "@territory-kit/core";
import { loadTerritoryDataset } from "@territory-kit/dataset";
const dataset = loadTerritoryDataset(input);
const adjacency = JSON.parse(await readFile("adjacency.json", "utf8"));
const engine = createTerritoryEngine({ dataset, adjacency });
const zoneId = engine.latLngToZone({ lat: 41.0, lng: 29.0 });
const sharedBorderNeighbors = engine.zoneNeighbors("tr:adm2:fatih", {
types: ["shared-border"]
});API Summary
createTerritoryEngine({ dataset, adjacency, levelStrategy })builds the query engine.latLngToZone(coordinate, options)locates the containing zone.zoneNeighbors(zoneId, options)returns legacy neighbors and optional adjacency artifact neighbors.getAdjacencyRelations(zoneId, options)returns typed artifact edges such asshared-border,point-touch,maritime, andlogical.getVisibleZones(query)andgetViewportCacheKey(query)support viewport flows.encodeTerritoryBinarySpatialIndex,decodeTerritoryBinarySpatialIndex,inspectTerritoryBinarySpatialIndex, andvalidateTerritoryBinarySpatialIndexprovide the versioned.tksibinary spatial index contract with packed Flatbush tree data.createTerritoryEngine({ dataset, spatialIndex })accepts a prebuilt binary index and falls back to runtime Flatbush construction when no index is provided.getSpatialIndexSummary()reports whether an engine is usingflatbushorbinary-flatbushlookup.zoomToDefaultLevelanddefaultZoomLevelStrategyprovide default zoom mapping.createTerritoryCountryDatasetDescriptorandloadTerritoryCountryDatasetsupport thin resolver-driven country loader packages.
Registry client exports from the core root are deprecated compatibility exports. New code should
import registry APIs from @territory-kit/registry; migration-only code can use
@territory-kit/core/legacy-registry.
License
Apache-2.0
