lib/styleToFilters.js
function styleToFilters(style) {
  var layers = {};
  // Store layers and filters used in style
  if (style && style.layers) {
    for (var i = 0; i < style.layers.length; i++) {
      var layerName = style.layers[i]['source-layer'];
      if (layerName) {
        // if the layer already exists in our filters, update it
        if (layers[layerName]) {
          // Update zoom levels
          var styleMin = style.layers[i].minzoom || 0;
          var styleMax = style.layers[i].maxzoom || 22;
          if (styleMin < layers[layerName].minzoom) layers[layerName].minzoom = styleMin;
          if (styleMax > layers[layerName].maxzoom) layers[layerName].maxzoom = styleMax;
          // Modify filter
          if (layers[layerName].filters === true || !style.layers[i].filter) {
            layers[layerName].filters = true;
          } else {
            layers[layerName].filters.push(style.layers[i].filter);
          }
        } else {
          // otherwise create the layer & filter array, with min/max zoom
          layers[layerName] = {};
          layers[layerName].filters = style.layers[i].filter ? ['any', style.layers[i].filter] : true;
          layers[layerName].minzoom = style.layers[i].minzoom || 0;
          layers[layerName].maxzoom = style.layers[i].maxzoom || 22;
        }

        // Collect the used properties 
        // 1. from paint, layout, and filter
        layers[layerName].properties = layers[layerName].properties || [];
        ['paint', 'layout'].forEach(item => {
          let itemObject = style.layers[i][item];
          itemObject && getPropertyFromLayoutAndPainter(itemObject, layers[layerName].properties);
        });
        // 2. from filter
        if (style.layers[i].filter) {
          getPropertyFromFilter(style.layers[i].filter, layers[layerName].properties);
        }
      }
    }
  }

  // remove duplicate propertys and fix choose all the propertys in layers[i].properties
  Object.keys(layers).forEach(layerId => {
    let properties = layers[layerId].properties;
    if (properties.indexOf(true) !== -1) {
      layers[layerId].properties = true;
    } else {
      let unique = {};
      properties.forEach(function(i) {
        if (!unique[i]) {
          unique[i] = true;
        }
      });
      layers[layerId].properties = Object.keys(unique);
    }
  });
  return layers;
}
function styleToFilters(style) {
  var layers = {};
  // Store layers and filters used in style
  if (style && style.layers) {
    for (var i = 0; i < style.layers.length; i++) {
      var layerName = style.layers[i]['source-layer'];
      if (layerName) {
        // if the layer already exists in our filters, update it
        if (layers[layerName]) {
          // Update zoom levels
          var styleMin = style.layers[i].minzoom || 0;
          var styleMax = style.layers[i].maxzoom || 22;
          if (styleMin < layers[layerName].minzoom) layers[layerName].minzoom = styleMin;
          if (styleMax > layers[layerName].maxzoom) layers[layerName].maxzoom = styleMax;
          // Modify filter
          if (layers[layerName].filters === true || !style.layers[i].filter) {
            layers[layerName].filters = true;
          } else {
            layers[layerName].filters.push(style.layers[i].filter);
          }
        } else {
          // otherwise create the layer & filter array, with min/max zoom
          layers[layerName] = {};
          layers[layerName].filters = style.layers[i].filter ? ['any', style.layers[i].filter] : true;
          layers[layerName].minzoom = style.layers[i].minzoom || 0;
          layers[layerName].maxzoom = style.layers[i].maxzoom || 22;
        }

        // Collect the used properties 
        // 1. from paint, layout, and filter
        layers[layerName].properties = layers[layerName].properties || [];
        ['paint', 'layout'].forEach(item => {
          let itemObject = style.layers[i][item];
          itemObject && getPropertyFromLayoutAndPainter(itemObject, layers[layerName].properties);
        });
        // 2. from filter
        if (style.layers[i].filter) {
          getPropertyFromFilter(style.layers[i].filter, layers[layerName].properties);
        }
      }
    }
  }

  // remove duplicate propertys and fix choose all the propertys in layers[i].properties
  Object.keys(layers).forEach(layerId => {
    let properties = layers[layerId].properties;
    if (properties.indexOf(true) !== -1) {
      layers[layerId].properties = true;
    } else {
      let unique = {};
      properties.forEach(function(i) {
        if (!unique[i]) {
          unique[i] = true;
        }
      });
      layers[layerId].properties = Object.keys(unique);
    }
  });
  return layers;
}
function styleToFilters ( style ) { var layers = { } ; // Store layers and filters used in style if ( style && style . layers ) { for ( var i = 0 ; i < style . layers . length ; i ++ ) { var layerName = style . layers [ i ] [ 'source-layer' ] ; if ( layerName ) { // if the layer already exists in our filters, update it if ( layers [ layerName ] ) { // Update zoom levels var styleMin = style . layers [ i ] . minzoom || 0 ; var styleMax = style . layers [ i ] . maxzoom || 22 ; if ( styleMin < layers [ layerName ] . minzoom ) layers [ layerName ] . minzoom = styleMin ; if ( styleMax > layers [ layerName ] . maxzoom ) layers [ layerName ] . maxzoom = styleMax ; // Modify filter if ( layers [ layerName ] . filters === true || ! style . layers [ i ] . filter ) { layers [ layerName ] . filters = true ; } else { layers [ layerName ] . filters . push ( style . layers [ i ] . filter ) ; } } else { // otherwise create the layer & filter array, with min/max zoom layers [ layerName ] = { } ; layers [ layerName ] . filters = style . layers [ i ] . filter ? [ 'any' , style . layers [ i ] . filter ] : true ; layers [ layerName ] . minzoom = style . layers [ i ] . minzoom || 0 ; layers [ layerName ] . maxzoom = style . layers [ i ] . maxzoom || 22 ; } // Collect the used properties  // 1. from paint, layout, and filter layers [ layerName ] . properties = layers [ layerName ] . properties || [ ] ; [ 'paint' , 'layout' ] . forEach ( item => { let itemObject = style . layers [ i ] [ item ] ; itemObject && getPropertyFromLayoutAndPainter ( itemObject , layers [ layerName ] . properties ) ; } ) ; // 2. from filter if ( style . layers [ i ] . filter ) { getPropertyFromFilter ( style . layers [ i ] . filter , layers [ layerName ] . properties ) ; } } } } // remove duplicate propertys and fix choose all the propertys in layers[i].properties Object . keys ( layers ) . forEach ( layerId => { let properties = layers [ layerId ] . properties ; if ( properties . indexOf ( true ) !== - 1 ) { layers [ layerId ] . properties = true ; } else { let unique = { } ; properties . forEach ( function ( i ) { if ( ! unique [ i ] ) { unique [ i ] = true ; } } ) ; layers [ layerId ] . properties = Object . keys ( unique ) ; } } ) ; return layers ; }
Takes optimized filter object from shaver.styleToFilters and returns c++ filters for shave.
@function styleToFilters
@param {Object} style -  Mapbox GL Style JSON
@example
var shaver = require('@mapbox/vtshaver');
var style = require('/path/to/style.json');
var filters = shaver.styleToFilters(style);
console.log(filters);
// {
//   "poi_label": ["!=","maki","cafe"],
//   "road": ["==","class","path"],
//   "water": true,
//   ...
// }
Takes optimized filter object from shaver . styleToFilters and returns c ++ filters for shave .