Get started
TypeScript SDK

Geo and navigation

Geo without a map

Four entries of @mountaya/elements do the maths a map does, with no map: ./geo, ./profile, ./units and ./i18n. They load no renderer and make no request, so they run on a server, in a worker, or in a test.

Measure and format distances

import { haversineMeters } from "@mountaya/elements/geo";
import { formatDistance } from "@mountaya/elements/profile";

const chamonix: [number, number] = [6.8712, 45.9231];
const argentiere: [number, number] = [6.9271, 45.9822];

const meters = haversineMeters(chamonix, argentiere); // 7865.2…
formatDistance(meters, { language: "fr", length: "metric" }); // "7,9 km"
formatDistance(meters, { language: "en", length: "imperial" }); // "4.9 mi"

Positions are [longitude, latitude], as GeoJSON writes them. Formatting follows the reader's language and units.

Build an elevation series

buildElevationSeries reads the third coordinate of each position into a profile:

import type { LineString } from "geojson";
import { buildElevationSeries, formatElevation, profileTotals } from "@mountaya/elements/profile";

const route: LineString = {
  coordinates: [
    [6.8712, 45.9231, 1035],
    [6.8936, 45.9829, 2352],
    [6.9271, 45.9822, 1252],
  ],
  type: "LineString",
};

const { ascent, descent, distance } = profileTotals(buildElevationSeries(route));
// ascent 1317, descent 1100, distance 9460.9…
formatElevation(ascent, { language: "en", length: "imperial" }); // "4,321 ft"

It takes a Feature, a FeatureCollection or a bare geometry, and ignores anything that is not a line.

Read the terrain at a point

From the heights around a point, slopeAspectFromNeighbours answers how steep the ground is and which way it faces:

import { aspectCardinal, slopeAspectFromNeighbours } from "@mountaya/elements/geo";
import { formatSlope } from "@mountaya/elements/profile";

// Heights in meters, 0.0001° north, south, east and west of a point at 45.9°N.
const { aspect, slope } = slopeAspectFromNeighbours(
  { east: 2401, north: 2404, south: 2400, west: 2403 },
  45.9,
  0.0001,
);

formatSlope(slope, { language: "en", slope: "degrees" }); // "12°"
aspectCardinal(aspect); // "SE"

From elevation tiles you have decoded, terrainFromElevationTiles answers the elevation, slope and aspect at a point in one call.

Units and languages

import { resolveElementsStrings } from "@mountaya/elements/i18n";
import { frElementsStrings } from "@mountaya/elements/i18n/fr";
import { convertLength, convertSpeed } from "@mountaya/elements/units";

convertLength(1, "mile", "foot"); // 5280
convertSpeed(4.5, "kilometer-per-hour", "minute-per-kilometer"); // 13.33…, a 13:20 pace

const words = resolveElementsStrings("fr", undefined, { fr: frElementsStrings });
words.profile.ascent; // "Dénivelé +"

Every unit id is the one Intl.NumberFormat takes. English is built in, and each other language is an entry of its own.

Next steps

Last updated