SWMAPS DocumentationAPI portal

Services and field tools

Bathymetry and depth

Show available seabed layers and inspect depths with clear source and accuracy information.

On this page

Discover and display layers #

Prerequisites: maps scope for the map and depth scope for point queries. Wait until the map style loads before reading its metadata. Sources vary by release; GMRT is optional.

javascript
import { bathymetryOptions, setBathymetry, bathymetryVisible,
  NOT_FOR_NAVIGATION } from 'https://maps.example/sw-map.js';
map.once('load', () => {
  const available = bathymetryOptions(map);
  if (!available) return;
  console.log(available.options); // available {id,name} source choices
  const source = available.options.find(x => x.id === 'gebco')?.id;
  if (source) setBathymetry(map, { source, shading: true,
    contours: available.contours.length > 0, coverage: false });
  const notice = document.createElement('p');
  notice.textContent = NOT_FOR_NAVIGATION;
  notice.hidden = !bathymetryVisible(map);
  document.body.append(notice);
});
LayerUse and limits
GEBCO 202615 arc-second global-derived depth; Terrarium raster, typically z3–8
ETOPO 2022Alternative elevation/depth surface; typically z3–8
GMRTHigher-resolution survey areas with GEBCO support; optional, typically z3–10
Natural EarthGeneralized vector depth bands
ContoursGEBCO-derived depth contour lines
CoverageGEBCO source types: directly measured versus estimated/interpolated

Use the actual release minzoom/maxzoom and style metadata rather than hard-coding availability. At higher zooms GMRT covers surveyed cells only; GEBCO is drawn underneath. A measured flag does not guarantee chart-level accuracy. Turn off shaded sources with setBathymetry(map, {source:null}); specify contours/coverage if those should remain enabled.

Query a depth #

javascript
import { configure, depth } from 'https://maps.example/sw-services.js';
configure({ baseUrl: 'https://maps.example/', apiKey: 'YOUR_API_KEY' });
const sample = await depth([126.8, 10]);
console.log(sample.depth_m, sample.elevation_m,
  sample.source, sample.method, sample.measured, sample.cell_m);

Expected result: {at, elevation_m, depth_m, source, method, measured, cell_m, not_for_navigation:true}. depth_m is positive below sea level and null on land or no data; elevation_m is negative below sea level. cell_m is an approximate longitudinal grid-cell size at the query latitude. The API samples the release’s GEBCO grid even when the viewer displays ETOPO or GMRT. It does not sample whichever layer happens to be visible.

The depth grid is about 460 m at the equator, not a sonar reading. An absent grid returns 503; an out-of-grid/service point returns 422. Null depth does not establish that a vessel can pass.

Sample a local Terrarium tile #

For an offline pack with a DEM layer, your app can read the tile, decode its PNG to RGBA, then use the pure style helpers. This gives a sample from that raster; it does not reproduce the API’s GEBCO source-type classification.

javascript
import { tilePixel, depthFromRgba, terrariumElevation } from '@sw-maps/core/style';
const pixel = tilePixel([126.8, 10], 8);
// Read pixel.z/x/y from the pack DEM archive and decode PNG to RGBA.
// rgba must be the full decoded 256 x 256 x 4 byte array.
const sample = depthFromRgba(rgba, pixel);
console.log(sample.depth_m, sample.not_for_navigation);
// Formula: R * 256 + G + B / 256 - 32768 metres.
// terrariumElevation(R,G,B) returns null at the no-data sentinel (>=9000 m).
Bathymetry is for planning and awareness only: not for navigation. Show this notice whenever any bathymetry layer or depth result is visible. It is not a nautical chart, tide correction, clearance calculation or safe-water guarantee.