A Typescript library for interacting with OGC-compliant services
ogc-client is a Typescript library which implements several OGC standards and will help you interact with them in a user-friendly and consistent way.
Documentation and live demo here!
The following standards are partially implemented:
- WMS - Web Map Service
- WFS - Web Feature Service
- WMTS - Web Map Tile Service
- WPS - Web Processing Service
- OGC API (Records and Features)
- OGC API — Connected Systems (CSAPI)
- TMS - Tile Map Service
- STAC API - SpatioTemporal Asset Catalog
- NcWMS - Extended WMS for scientific data (Thredds, ERDDAP, CMEMS…)
- ogc-client will abstract the service version so you don't have to worry about it
- ogc-client will handle XML so you only have to deal with native Javascript objects
- ogc-client will hide the complexity of OGC standards behind straightforward APIs
- ogc-client will run heavy tasks in a worker to avoid blocking the main thread
- ogc-client will keep a persistent cache of operations to minimize requests and processing
- ogc-client will tell you if a service is not usable for CORS-related issues
To install ogc-client, run:
$ npm install --save @camptocamp/ogc-clientTo use, import API symbols like so:
import {
WmsEndpoint,
WfsEndpoint,
StacEndpoint,
NcwmsEndpoint,
} from '@camptocamp/ogc-client';Note: if you want to disable web worker usage, for example to solve issues with the Referer header on outgoing
requests, use:
import { enableFallbackWithoutWorker } from '@camptocamp/ogc-client';
enableFallbackWithoutWorker();All processing will be done on the main thread after this call, including HTTP requests.
The @camptocamp/ogc-client NPM package is updated on every commit on the main branch under the @dev tag. To use it:
$ npm install --save @camptocamp/ogc-client@devA provided application containing the documentation and demo is located in the app folder.
To start it locally, clone the repository and run the following commands:
$ npm install
$ cd app
$ npm install
$ npm startThe app is based on Vue.js and will showcase most features implemented in the library. You will need to supply it with valid OGC service urls.
import { NcwmsEndpoint } from '@camptocamp/ogc-client';
const endpoint = new NcwmsEndpoint(
'https://my.thredds.server/thredds/wms/dataset',
);
// Detect NcWMS and get available palettes and scale range
const details = await endpoint.getLayerDetails('temperature');
if (details) {
console.log(details.palettes); // ['rainbow', 'occam', ...]
console.log(details.scaleRange); // [-2, 35]
console.log(details.units); // '°C'
}
// Auto-detect min/max from the current map extent
const { min, max } = await endpoint.getMinMax('temperature', [-10, 30, 10, 50]);
// Build a legend image URL (no network request)
const legendUrl = endpoint.getLegendUrl('temperature', {
style: 'boxfill/rainbow',
colorScaleRange: [min, max],
logScale: false,
});See the examples/ directory for more complete examples, including:
examples/stac-query.js- Full STAC API query example with spatial and temporal filtersexamples/wps-sextant.mjs- WPS 1.0.0 example: read service info, list/describe processes and run one asynchronously
Run examples with:
npm run build
node examples/stac-query.jsThe library includes support for the OGC API — Connected Systems standard (Part 1: Feature Resources, Part 2: Dynamic Data). This standard extends the OGC API family into the IoT/sensor domain, providing a REST API for discovering and querying sensor systems, deployments, datastreams, observations, commands, and related resources.
CSAPI remains behind an opt-in module boundary. The preferred endpoint.csapi(...) facade loads it dynamically when needed; parsers and the advanced factory are also available from the @camptocamp/ogc-client/csapi sub-path.
Nothing changes. Use the library exactly as before:
import { OgcApiEndpoint, WmsEndpoint } from '@camptocamp/ogc-client';CSAPI code will not be loaded at runtime.
Use the discoverable endpoint facade:
import { OgcApiEndpoint } from '@camptocamp/ogc-client';
const endpoint = new OgcApiEndpoint('https://api.example.org');
if (await endpoint.hasConnectedSystems) {
const builder = await endpoint.csapi('weather-stations');
const systemsUrl = builder.getSystems({ limit: 50 });
const datastreamsUrl = builder.getDatastreams();
}The returned CSAPIQueryBuilder provides methods for all 9 resource types: systems, deployments, sampling features, procedures, properties, datastreams, observations, control streams, and commands.
Advanced consumers who already hold a collection descriptor and a discovered resource-URL map can use the pure factory directly:
import {
createCSAPIBuilder,
type CSAPICollectionRef,
} from '@camptocamp/ogc-client/csapi';
const collection: CSAPICollectionRef = {
id: 'weather-stations',
links: [],
};
const resourceUrls = new Map([['systems', 'https://api.example.org/systems']]);
const builder = createCSAPIBuilder(collection, resourceUrls);Unlike endpoint.csapi(...), createCSAPIBuilder(collection, resourceUrls) performs no discovery or network I/O. The endpoint facade is the preferred entry point for normal consumers.
The OGC Connected Systems standard is large — it spans 9 resource types across 2 specification parts with multiple response formats (GeoJSON, SWE Common, SensorML). By isolating CSAPI behind a dynamic boundary and sub-path export, users who only need WMS/WFS/WMTS/etc. don't pay the bundle-size cost for functionality they're not using. Modern bundlers (Webpack 5+, Vite, Rollup, esbuild) handle this automatically.