Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
stevage committed Jan 21, 2025
1 parent 1a8926d commit 7e70b6f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Full documentation: https://stevage.github.io/map-gl-utils
* `setFilter()` (works on multiple layers at once),
* `setData()` clears data if no GeoJSON provided.
* `loadImage()` loads and adds an image in one step.
* Expression syntactic sugar (called statically):
* `U.stepZoom(2, { 8: 3 })` => `['step', ['zoom'], 2, 8, 3]`
* `U.interpolateZoom({ 14: 2, 16: 4 })` => `['interpolate', ['linear'], ['zoom'], 14, 2, 16, 4]`
* `U.interpolate('size', {2: 15, 4: 30 }')` => `['interpolate', ['get', 'size'], 2, 15, 4, 13]`
* `U.match('size', { small: 12, medium: 18, default: 24 })` => `['match', ['get', 'size'], 'small', 12, 'medium', 18, 24]`

## Usage

Expand Down
8 changes: 6 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset='utf-8'>
<title>map-gl-utils 0.50.1 | Documentation</title>
<title>map-gl-utils 0.50.2 | Documentation</title>
<meta name='description' content='Utility functions for Mapbox GL JS or Maplibre GL JS'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' rel='stylesheet'>
Expand All @@ -15,7 +15,7 @@
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>map-gl-utils</h3>
<div class='mb1'><code>0.50.1</code></div>
<div class='mb1'><code>0.50.2</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down Expand Up @@ -4653,6 +4653,10 @@ <h3>0.50.0</h3>
<li>convert from Flow to TypeScript.</li>
<li>probably mess up the packaging once more.</li>
</ul>
<h3>0.45.0-0</h3>
<ul>
<li>fixing packaging issues ("regeneratorRuntime is not defined")</li>
</ul>
<h3>0.44.0</h3>
<ul>
<li>add match/interpolate/zoom convenience functions, somewhat experimental</li>
Expand Down
17 changes: 16 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ class _MapGlUtils implements UtilsFuncs {

static zoom = _MapGlUtils.interpolateZoom;

/**
* Generates a ["step", input, lowest, ...steps] expression.
*/
static step(
expression: ExpressionSpecification,
lowest: number,
Expand All @@ -378,6 +381,10 @@ class _MapGlUtils implements UtilsFuncs {
];
}

/**
* Generates a ["step", ["zoom"], lowest, ...steps] expression.
* @example stepZoom(2, { 8: 3, })
*/
static stepZoom(
lowest: number,
stops:
Expand All @@ -390,6 +397,10 @@ class _MapGlUtils implements UtilsFuncs {
return this.step(['zoom'], lowest, stops, ...moreStops);
}

/**
* Generates a ["interpolate", ["linear"], input, lowest, ...stops] expression.
* @example interpolate('size', { 2: 15, 4: 30, })
*/
static interpolate(
expression: string | ExpressionSpecification,
stops: number | { [s: string]: unknown } | ArrayLike<unknown>,
Expand All @@ -409,7 +420,11 @@ class _MapGlUtils implements UtilsFuncs {
: [stops, ...moreStops]),
];
}

/**
* Generates a ["match", input, output, default] expression.
* @example MapGlUtils.match('type', { 'house': '🏠', 'tree': '🌲' }, '❓')
*
*/
static match(
expression: string,
cases: { [s: string]: unknown; default?: any },
Expand Down

0 comments on commit 7e70b6f

Please sign in to comment.