How to use the @mapbox/mapbox-gl-style-spec.expression function in @mapbox/mapbox-gl-style-spec

To help you get started, we’ve selected a few @mapbox/mapbox-gl-style-spec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mapbox / vtshaver / lib / styleToFilters.js View on Github external
function getPropertyFromFilter(filter, properties) {
  if (styleSpec.expression.isExpression(filter)) {
    getPropertyFromExpression(filter, properties);
  }

  // Warning: Below code should put in to an else conditions,
  // but since the `isExpression` can not tell it is a expression or filter syntax I put it outsied the else
  // this could reduce the performance or cause some potential bugs, we must keep an eye on this.

  // else {
  let subFilter = [];
  for (let i = 0; i < filter.length; i++) {
    if (typeof filter[i] === 'object' && filter[i] instanceof Array) {
      subFilter.push(filter[i]);
    }
  }

  if (subFilter.length > 0) {
github mapbox / vtshaver / lib / styleToFilters.js View on Github external
// - special properties: `mapbox_clip_start`, `mapbox_clip_end`
    if (typeof value === 'string') {
      // if the value is string try to get property name from `xx{PropertyName}xx` like.
      // the /{[^}]+}/ig return all the value like {xxx}
      // eg 'a{hello}badfa' => ['{hello}']
      // eg 'a{hello}ba{world}dfa' => ['{hello}','{world}']
      let preProperties = value.match(/{[^}]+}/ig);
      preProperties && preProperties.forEach(item => {
        properties.push(item.slice(1, -1));
      });
    } else if (typeof value === 'object' && typeof value.property === 'string') {
      // - legacy functions with `property`
      properties.push(value.property);
    } else {
      // test isExpression from sytleSpec
      if (styleSpec.expression.isExpression(value)) {
        // TODO: now we implement this by ourself in vtshavem, we need to talk with ‘style spec’ member to see if there have a official method to get used property, to make this can be synchronized with the expression update.
        getPropertyFromExpression(value, properties);
      } else {
        // otherwise continual loop;
        getPropertyFromLayoutAndPainter(value, properties);
      }
    }
  })
}
github orangemug / simple-expr / bin / cli.js View on Github external
.then(function(data) {
          var json = simpleExpr.compile(data)

          var out = mgl.expression.createExpression(json, {})
          var result = out.value.evaluate(globalOpts, {
            id: argv["feature-id"],
            type: argv["feature-type"],
            properties: featureOpts
          })

          console.log(result);
          process.exit(0);
        })
        .catch(handleError)