Skip to content

📦 core ​

This package provides the foundation for the Geospatial SDK.

It includes:

  • Map Context model: TypeScript types and interfaces for declaratively defining maps, layers, and views
  • Diff algorithms: Utilities to compute differences between Map Context objects (computeMapContextDiff)
  • Validation utilities: Tools for working with and validating geospatial data
  • Shared constants: Common definitions used across all packages

The @geospatial-sdk/core package is framework-agnostic and does not depend on any specific mapping library. It's required by all other packages in the SDK.

Installation ​

sh
npm install @geospatial-sdk/core

Usage ​

typescript
import { computeMapContextDiff, type MapContext } from "@geospatial-sdk/core";

const oldContext: MapContext = {
  layers: [{ type: "xyz", url: "https://example.com/{z}/{x}/{y}.png" }],
  view: { center: [0, 0], zoom: 2 },
};

const newContext: MapContext = {
  layers: [{ type: "xyz", url: "https://example.com/{z}/{x}/{y}.png" }],
  view: { center: [5, 45], zoom: 5 },
};

const diff = computeMapContextDiff(newContext, oldContext);

Classes ​

ClassDescription
SourceLoadErrorEvent-

Interfaces ​

InterfaceDescription
FeaturesClickEvent-
FeaturesHoverEvent-
LayerCreationErrorEvent-
LayerGeojsonWithData-
LayerGeojsonWithUrl-
LayerLoadingErrorEvent-
MapClickEvent-
MapContextA map context, containing layers and a view.
MapContextBaseLayer-
MapContextDiffDescribes a delta between two contexts, in order to be applied to an existing map.
MapContextLayerChangedDescribes a layer that was changed: both states before and after change are included
MapContextLayerGeotiff-
MapContextLayerMapLibreStyle-
MapContextLayerPositionedAssociates a position to a layer; the position is the index of the layer in the layers array
MapContextLayerReorderedDescribes a layer being moved to a different position
MapContextLayerVector-
MapContextLayerWms-
MapContextLayerWmts-
MapContextLayerXyz-
MapEventsByType-
MapExtentChangeEvent-
MapLayerDataInfo-
MapLayerStateChangeEvent-
MapStateChangeEvent-
MapViewStateChangeEvent-
ResolvedMapLayerIdentity-
ResolvedMapStateDescribes the actual state of a map after a context or context diff was applied to it. A view of null means the view state hasn't been changed yet. A layer item of null means the layer state hasn't been changed yet.
ResolvedMapViewStateDescribes the actual view state of a map
TimeInterval-
ValueInterval-
ViewByExtent-
ViewByGeometry-
ViewByZoomAndCenter-

Type Aliases ​

Type AliasDescription
CoordinateArray components are respectively: x, y and optionally a CRS identifier (e.g. "EPSG:2154"). Without a CRS, coordinates are expressed in longitude/latitude.
CrsIdentifier-
DateStringDates are expressed as ISO8601 strings, e.g. "2023-01-01T00:00:00Z" or "2023-01-01"
ExtentArray components are respectively: minX, minY, maxX, maxY and optionally a CRS identifier (e.g. "EPSG:2154"). Without a CRS, the extent is expressed in longitude/latitude.
FeaturesByLayerIndex-
LayerDimensionValue-
LayerGeojson-
LayerTimeDimensionValue-
MapContextLayerA layer that can be used in a map context.
MapContextLayerGeojson-
MapContextLayerOgcApi-
MapContextLayerWfs-
MapContextViewA description of a map viewport in one of three ways: * by center and zoom level, * by extent, * by geometry (in GeoJSON)
MapContextViewDiffIf the projection field is omitted, it means that the view projection should not be changed. A return to the default map view projection should be explicitly stated in the projection property. null means reset to the default view.
MapLayerCreationStatus-
MapLayerLoadingStatus-
ResolvedMapLayerState-
VectorStyle-

Variables ​

VariableDescription
defaultHighlightStyle-
defaultStyle-
FeaturesClickEventType-
FeaturesHoverEventType-
LayerCreationErrorEventType-
LayerLoadingErrorEventType-
MapClickEventType-
MapExtentChangeEventTypeDEPRECATED Use the MapViewStateChangeEvent instead
MapLayerStateChangeEventType-
MapStateChangeEventType-
MapViewStateChangeEventType-
SourceLoadErrorTypeDEPRECATED Use the MapLayerStateChangeEvent and LayerLoadingErrorEvent instead

Functions ​

FunctionDescription
addLayerToContextAdds a layer to the context at a specific position or at the end if no position is specified.
changeLayerPositionInContextChanges the position of a layer in the context.
computeMapContextDiffThe following logic is produced by identifying layers in both context and determining whether they have been added, removed, changed or reordered.
createViewFromLayerCreates a view from a layer by extracting its extent. The returned extent is preferably returned in EPSG:4326; if not available, it will be returned in a CRS available for this layer
deepFreeze-
ensureContextCrsReadyMakes sure all CRS used in a map context are registered
ensureDiffCrsReadyMakes sure all CRS used in a map context diff are registered
equals-
extendfirst extent will be modified
getCrsReturns the CRS of a coordinate or extent; defaults to EPSG:4326 (longitude/latitude)
getExtentFromGeojsonThis assumes the geometry is in EPSG:4326 TODO: support other CRSs
getExtentFromGeometryThis assumes the geometry is in EPSG:4326 TODO: support other CRSs
getHash-
getLayerPositionShould not be part of the API
getLayerPositionInContextReturns the position of a layer in the context. Returns -1 if the layer is not present.
readLayerDataThis will read the layer data and keep it in cache for future calls; it will also properly report errors in case of invalid GeoJSON or network issues
removeLayerFromContextRemoves a layer from the context.
removeSearchParamsRemoves the given search params from the URL completely; this is case-insensitive
replaceLayerInContextReplaces a layer in the context with a new layer.
setCrsApply a CRS identifier to a coordinate; THIS DOES NOT TRANSFORM COORDINATES
toGeographicReturns another extent which is in geographic coordinates (EPSG:4326)
transformProject an extent into another CRS
updateLayerApplies the updates partial to the given layer. The layer will also be adjusted depending on the presence of the id and version fields. Note: any property set to undefined in updates will be removed from the resulting layer.
updateLayerInContextUpdates an existing layer in the context by applying partial changes.