You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

mapbox-expression

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mapbox-expression

Evaluate Mapbox GL expression

0.0.3
latest
npmnpm
Version published
Weekly downloads
79
-19.39%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 17 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts