mapbox-expression

0.0.3 • Public • Published

Mapbox-expression

This library lets you evaluate a Mapbox GL expression directly, for a given feature, in a given context.

Credit for the code goes to danvk. Most of the code comes from here. See the Mapbox GL issue for further context.

You need to include Mapbox GL separately.

Usage

import Expression from 'mapbox-expression';

const feature = {
    type: 'Feature',
    properties: {
        name: 'Jan'
    },
    geometry: null
};

Expression.parse(['concat', 'Hello, ', ['get', 'name']]).evaluate(feature);
// 'Hello, Jan'

You can also pass in a context object. Mapbox GL seems to recognise these values:

zoom: number, // required
heatmapDensity: number,
lineProgress: number,
isSupportedScript: (string) => boolean,
accumulated: Value

So:

Expression.parse(['interpolate', ['linear'], ['zoom'], 10, 3, 15, 8]).evaluate(feature, { zoom: 12 })
// 5

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.3
    82
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.3
    82
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i mapbox-expression

Weekly Downloads

82

Version

0.0.3

License

ISC

Unpacked Size

2.53 kB

Total Files

3

Last publish

Collaborators

  • stevage