Skip to main content

zarr-maps-tiling

Framework-independent utilities for loading, slicing, styling, and rendering tiled Zarr data.

The package contains the shared data pipeline used by zarr-maps-leaflet, zarr-maps-ol, and zarr-cesium. It does not depend on Cesium, Leaflet, or OpenLayers.

import { initZarrDataset, calculateSliceArgs } from 'zarr-maps-tiling';
import { colormapBuilder } from 'zarr-maps-colormap';

ZarrTileProvider accepts either a URL or a custom Zarrita Readable store. This supports Icechunk and other storage backends without coupling the tiling package to a specific client:

const store = await IcechunkStore.open(url, { branch: 'main', formatVersion: 'v1' });
const provider = new ZarrTileProvider({ store, variable: 'temperature' });

Private HTTP stores can use requestOverrides for static fetch options or transformRequest for per-object headers, credentials, proxies, and signed URLs. onAuthError is called once for HTTP 400/401 responses so applications can refresh expired credentials.

Decoded numeric tiles are cached per provider so changing the colormap or scale can redraw without reading the same Zarr slice again. The default per-layer budget assumes no more than five active layers: 8 MiB on devices with up to 2 GiB, 16 MiB up to 4 GiB, 32 MiB up to 8 GiB, and 64 MiB above that. Browsers that do not expose a device-memory hint use 32 MiB.

const provider = new ZarrTileProvider({
url: 'https://example.com/data.zarr',
variable: 'temperature',
cache: { maxBytes: 16 * 1024 * 1024 }
});

console.log(provider.tileCacheStats);
provider.clearTileCache();

Caching defaults to true. Set cache: false (or cache: { enabled: false }) to disable it. The budget is per layer, so five layers configured with 16 MiB can retain at most 80 MiB of decoded tile data in total.

From the zarr-maps repository root, build all packages with:

npm run build

Classes​

ClassDescription
ZarrTileProviderProvides Zarr dataset access and rendering capabilities for web-map layers.

Interfaces​

InterfaceDescription
BoundsPropsGeographic bounding box definition (degrees).
DataSlicePropsDescribes a slice of a multidimensional array.
DimensionNamesPropsDescribes the mapping between dataset dimensions and their standardized names.
DimensionValuesMapping of dimension names to their corresponding coordinate arrays.
DimIndicesPropsMaps dimension keys to their indices and associated coordinate arrays.
FullTransectResultA distance-by-elevation transect. Values are indexed [elevation][position].
QueryBackendMinimal interface required by the framework-neutral convenience queries.
QueryMultiPolygonGeometryGeoJSON multipolygon geometry, reserved for region-query support.
QueryOptionsControls a shared Zarr data query.
QueryPointGeometryGeoJSON point geometry expressed as WGS84 longitude and latitude.
QueryPolygonGeometryGeoJSON polygon geometry, reserved for region-query support.
QueryResultValues and coordinates returned from a shared Zarr query.
RequestOverridesSerializable static fetch options suitable for application state and FetchStore.
RequestParameters-
TileCacheOptionsControls the in-memory cache used to recolor tiles without reading Zarr data again.
TileCacheStatsRuntime counters for a provider's decoded tile cache.
TransectQueryOptionsSampling controls for one-level and full-depth transects.
TransectResultA one-level transect. Values preserve no-data gaps as null.
XYLimitsDescribes the XY coordinate boundaries of a dataset.
XYLimitsPropsAlias of XYLimits with explicit type name for Zarr coordinate bounds.
ZarrLevelMetadataMetadata for a single multiscale level in a Zarr dataset.
ZarrSelectorsDescribes a selector for a Zarr dataset dimension.
ZarrSelectorsProps-
ZarrTileOptionsFramework-neutral options for the shared 2D Zarr tile renderer.

Type Aliases​

Type AliasDescription
BrowserNameBrowser names used for WebGL compatibility handling.
CalendarDateRepresents a date in a calendar system.
CFCalendarSupported CF calendar types.
CRSSupported Coordinate Reference Systems.
MultiscaleFormatSupported conventions for discovering multiscale Zarr levels.
OnAuthError-
QueryGeometryGeometry accepted by the shared query API. Only points are implemented currently.
QueryPositionWGS84 longitude/latitude coordinate used by convenience query APIs.
SliceArgsRepresents a multidimensional slice argument for Zarr array indexing.
TransformRequest-

Functions​

FunctionDescription
calculateElevationSliceDetermines the index range of the elevation axis to load from a Zarr cube.
calculateHeightMetersConverts elevation index to Cesium height (meters), applying vertical exaggeration and optional below-sea-level offset.
calculateNearestIndexFinds the index of the value in values nearest to target.
calculateSliceArgsConstructs Zarr slice arguments for extracting a subregion of a multidimensional array.
calculateSliceArgsRequestImageConstructs Zarr slice arguments for extracting a subregion of a multidimensional array.
calculateXYFromBoundsConverts geographic bounds (lat/lon) to pixel-space indices for slicing Zarr arrays. Supports both EPSG:4326 and EPSG:3857 projections.
createColorRampTextureCreates a flexible 1D color-ramp texture supporting either normalized (0–1) or integer (0–255) color definitions.
createProgramCreates and links a WebGL program using the specified vertex and fragment shaders.
createShaderCreates and compiles a WebGL shader from source code.
decodeCFTimeDecodes CF-compliant time coordinate values into ISO date strings.
detectBrowserDetects the current browser based on the user agent string.
detectCRSDetects the coordinate reference system (CRS) of a Zarr dataset based on metadata or coordinate range. Defaults to EPSG:4326 (WGS84) if uncertain.
extractNoDataMetadataExtracts no-data related metadata from a Zarr array's attributes.
getCubeDimensionsComputes cube dimension ordering and strides based on dimension indices. Useful for reshaping 3D Zarr arrays into Cesium-renderable layouts.
getFullTransectQueries all elevation levels along a line between two WGS84 positions.
getTimeSeriesQueries every time coordinate at one point and the selected elevation.
getTransectQueries one scalar level along a line between two WGS84 positions.
getVerticalProfileQueries every elevation coordinate at one point and the selected time.
getXYLimitsRetrieve the geographic coordinate limits (min/max latitude/longitude) for a Zarr array.
getZarrDataReads an array with the same Zarrita module instance that opened it. Zarrita 0.7 keeps array decoding context module-local, so consumers must not call a separately resolved copy of zarrita.get on arrays returned here.
identifyDimensionIndicesIdentify the indices of common dimensions (lat, lon, time, elevation) in a Zarr array, optionally using CF-compliant standard names or custom dimension mappings.
initZarrDatasetOpens a Zarr variable (single-scale or multiscale pyramid) and prepares its metadata.
latDegToMercY-
limitStoreRequestsWrap a Zarrita store so all reads share one request-concurrency budget.
loadDimensionValuesLoads the coordinate values for a specific dimension.
lonDegToMercX-
openLevelArrayOpens and caches a specific multiscale level array. Keeps a small LRU-style cache of up to three levels.
parseCFUnitsParses a CF-compliant units string into its components.
resolveNoDataRangeResolves the no-data value range for masking dataset values.
sampleTransectPositionsBuilds evenly spaced WGS84 samples along the shortest longitude path.
updateImgDataUpdates an ImageData object with a new pixel color derived from a numeric value and a ColorScaleProps colormap.