feature-filter-geojson
Creates filtering function for GeoJSON features
Last updated 4 years ago by gmaclennan .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install feature-filter-geojson 
SYNC missed versions from official npm registry.

feature-filter-geojson

Build Status npm

This library is forked from mapbox/feature-filter, but adapted to work with GeoJSON features rather than features from a vector tile. This library implements the semantics specified by the Mapbox GL JS spec.

API

featureFilter(filter)

Given a filter expressed as nested arrays, return a new function that evaluates whether a given feature (with a .properties or .tags property) passes its test.

Parameters

parameter type description
filter Array mapbox gl filter

Returns Function, filter-evaluating function

Usage

var ff = require('feature-filter');

// will match a feature with class of street_limited,
// AND an admin_level less than or equal to 3,
// that's NOT a polygon.
var filter = [
    "all",
    ["==", "class", "street_limited"],
    ["<=", "admin_level", 3],
    ["!=", "$type", "Polygon"]
]

// will match a feature that has a class of
// wetland OR wetland_noveg.
// ["in", "class", "wetland", "wetland_noveg"]

// testFilter will be a function that returns a boolean
var testFilter = ff(filter);

// Layer feature that you're testing. Must have type
// and properties keys.
var feature = {
    type: 'Feature'
    geometry: {
      type: 'Polygon',
      coordinates: [[...]]
    },
    properties: {
       class: "street_limited"
       admin_level: 1
    }
};

// will return a boolean based on whether the feature matched the filter
return testFilter(feature);

Current Tags

  • 1.0.0                                ...           latest (4 years ago)

1 Versions

  • 1.0.0                                ...           4 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (0)
None
Dev Dependencies (5)

Copyright 2014 - 2016 © taobao.org |