IITC.filters

Filters API

Filters API is a mechanism to hide intel entities using their properties (faction, health, timestamp...). It provides two level APIs: a set of named filters that apply globally (any entity matching one of the filters will be hidden), and low level API to test an entity against a filter for generic purpose. This comes with a Leaflet layer system following the old layer system, the filter is disabled when the layer is added to the map and is enabled when removed.

A filter applies to a combinaison of portal/link/field and is described by

  • data properties that must (all) match
  • or a predicate for complex filter

{ portal: true, link: true, data: { team: 'E' }} filters any ENL portal/link

[{ link: true, data: { oGuid: "some guid" }}, { link: true, data: { dGuid: "some guid" }}] filters any links on portal with guid "some guid"

{ field: true, pred: function (f) { return f.options.timestamp < Date.parse('2021-10-31'); } } filters any fields made before Halloween 2021

Data properties can be specified as value, or as a complex expression (required for array data properties). A complex expression is a 2-array, first element is an operator, second is the argument of the operator for the property. The operators are:

  • ['eq', value] : this is equivalent to type directly value
  • ['not', ]
  • ['or', [exp1, exp2,...]]: the expression matches if one of the exp1.. matches
  • ['and', [exp1, exp2...]]: matches if all exp1 matches (useful for array properties)
  • ['some', exp]: when the property is an array, matches if one of the element matches exp
  • ['every', exp]: all elements must match exp
  • ['<', number]: for number comparison (and <= > >=)

Examples:

{ portal: true, data: ['not', { history: { scoutControlled: false }, ornaments: ['some', 'sc5_p'] }] } filters all portals but the one never scout controlled that have a scout volatile ornament

{ portal: true, data: ['not', { resonators: ['every', { owner: 'some agent' } ] } ] } filters all portals that have resonators not owned from 'some agent' (note: that would need to load portal details)

{ portal: true, data: { level: ['or', [1,4,5]], health: ['>', 85] } } filters all portals with level 1,4 or 5 and health over 85

{ portal: true, link: true, field: true, options: { timestamp: ['<', Date.now() - 3600000] } } filters all entities with no change since 1 hour (from the creation of the filter)

Classes

FilterLayer

Members

static _filters :Object.<string, IITC.filters.FilterDesc>

Methods

static filterEntities()

Applies all existing filters to the entities (portals, links, and fields) on the map. Entities that match any of the active filters are removed from the map; others are added or remain on the map.

static filterField(field) → {boolean}

Tests whether a given field matches any of the currently active filters.

Parameters:
Name Type Description
field object

Field to test

Returns:
boolean -

true if the the field matches one of the filters

Tests whether a given link matches any of the currently active filters.

Parameters:
Name Type Description
link object

Link to test

Returns:
boolean -

true if the the link matches one of the filters

static filterPortal(portal) → {boolean}

Tests whether a given portal matches any of the currently active filters.

Parameters:
Name Type Description
portal object

Portal to test

Returns:
boolean -

true if the the portal matches one of the filters

static has(name) → {boolean}

Checks if a filter with the specified name exists.

Parameters:
Name Type Description
name string

The name of the filter to check.

Returns:
boolean -

True if the filter exists, false otherwise.

static remove(name) → {boolean}

Removes a filter with the specified name.

Parameters:
Name Type Description
name string

The name of the filter to be removed.

Returns:
boolean -

True if the filter was successfully deleted, false otherwise.

static set(name, filterDesc)

Sets or updates a filter with a given name. If a filter with the same name already exists, it is overwritten.

Parameters:
Name Type Description
name string

filter name

filterDesc IITC.filters.FilterDesc | Array.<IITC.filters.FilterDesc>

filter description (OR)

static testFilter(type, entity, filter) → {boolean}

Tests whether a given entity matches a specified filter.

Parameters:
Name Type Description
type "portal" | "link" | "field"

Type of the entity

entity object

Portal/link/field to test

filter IITC.filters.FilterDesc

Filter

Returns:
boolean -

true if the the entity of type type matches the filter

Type Definitions

FilterDesc

Properties:
Name Type Attributes Description
filterDesc.portal boolean

apply to portal

filterDesc.link boolean

apply to link

filterDesc.field boolean

apply to field

filterDesc.data object <optional>

entity data properties that must match

filterDesc.options object <optional>

entity options that must match

filterDesc.pred IITC.filters.FilterPredicate <optional>

predicate on the entity

FilterPredicate(ent) → {boolean}

Parameters:
Name Type Description
ent Object

IITC entity

Returns:
boolean