Skip to content

FeatureEvaluator

FeatureEvaluator is a class that provides access to feature data and dynamic styling of features based on their properties. It can be obtained through the featureCreated and featureUpdated events of a Layer.

This class allows you to:

  • Read feature properties from data sources
  • Dynamically style features based on their properties

Type: FeatureSetId

Description: The ID of the feature set this evaluator covers, the same value as featureSetId in the layer’s feature events and in picks. A tile that is unloaded and loaded again gets a new feature set with a new ID. To identify a single feature, use featureId of FeatureInfo instead. See Identifiers for how the IDs relate.

Example:

layer.on("featureCreated", ({ evaluator }) => {
console.log("Feature set ID:", evaluator.featureSetId);
});
type FeatureInfo = {
batchId: number; // Picking ID of the rendered feature, valid while its feature set exists
properties: Record<string, unknown> | undefined;
featureId?: string | number; // Top-level GeoJSON `id` or MVT feature id, kept apart from `properties` (undefined when the feature has none)
layerId: string | undefined;
meshGeomType?: GeometryType; // Mesh geometry type (e.g. "billboard", "text")
};
type FeatureEvaluatorCallback = (info: FeatureInfo) => EvaluatedResult;

What the callback returns: the properties of EvaluatedValue to override, and optionally how they move to their new values.

type EvaluatedResult = Partial<EvaluatedValue> & {
transition?: EvaluatedTransition;
};

See Transition for transition.

Reads the properties of the features in this feature set from the data source. The callback is invoked once per feature.

Syntax:

readFeatureProperties(
f: (info: FeatureInfo, batchIndex: number) => void
): void

Parameters:

  • f: A callback function that receives a FeatureInfo object for each feature, and the feature’s 0-based index within this feature set

Example:

// Log all properties
evaluator.readFeatureProperties(({ batchId, properties }) => {
console.log(`Batch ${batchId}:`, properties);
});
evaluator.readFeatureProperties(({ properties }) => {
const attributes = properties?.["attributes"] ?? {};
const minHeight = attributes["minHeight"];
const maxHeight = attributes["maxHeight"];
console.log("Height range:", minHeight, "-", maxHeight);
});

Reads only the specified root property keys of this feature from the data source. More efficient than readFeatureProperties() when only a few properties are needed.

Syntax:

readFilteredFeatureProperties(
keys: string[],
f: (info: FeatureInfo, batchIndex: number) => void
): void

Parameters:

  • keys: An array of root property keys to read. featureId is passed even when keys is empty
  • f: A callback function that receives a FeatureInfo object with only the filtered properties, and the feature’s 0-based index within this feature set

Example:

evaluator.readFilteredFeatureProperties(["height", "name"], ({ batchId, properties }) => {
console.log(`Batch ${batchId}: height=${properties?.["height"]}, name=${properties?.["name"]}`);
});

Evaluates and applies dynamic styles to features based on their properties. The callback is invoked once per feature in this feature set.

Syntax:

evaluate(
f: FeatureEvaluatorCallback,
options?: {
filters?: string[];
}
): void

Parameters:

  • f: A callback function that receives a FeatureInfo object and returns style values
  • options: Optional configuration
    • options.filters: An array of root property keys to read. When specified, only the matched properties are passed to the callback, improving performance for large datasets.

Returns:

The callback function can return an object containing the following properties:

PropertyTypeDescription
colorColorFeature color (using new Color())
showbooleanFeature visibility (show/hide)
heightnumberFeature height (meters)
extrudedHeightnumberPolygon extrusion height (meters)
textstringLabel text content (for text/label features)
widthnumberLine width (pixels, for polyline features)
blurnumberSoftens the edge of the line over this many pixels (for polyline features). Overrides the material’s blur
dashArraynumber[]Dash and gap lengths in line widths (for polyline features). An empty array draws the feature solid. Overrides the material’s dashArray
cap"butt" | "round" | "square"Shape of the ends of each dash (for polyline features). Overrides the material’s cap
sizenumberPoint/text size (meters or pixels, for point/text features)
letterSpacingnumberExtra space between characters in ems (for text features). Overrides the material’s letterSpacing
opacitynumberFeature opacity, range 0.0-1.0 (for polygons/points/billboards/models/text)
declutterPrioritynumberPlacement priority for decluttering. Higher wins an overlap (for points/billboards/text with declutter enabled). Overrides the layer’s declutterPriority, but never the material’s declutterRank, which is compared first
imagestring | nullImage URL (for billboard features). Each distinct URL is loaded once and packed into the layer’s texture atlas. Return null to clear a previous per-feature image and revert to the billboard material’s default url (the feature becomes invisible if the material has no url)
iconstring | nullName of an icon in the billboard material’s sprite (for billboard features), drawn in place of image. A name the sprite does not have hides the feature. Return null to clear a previous per-feature icon and revert to the material’s default image. When both are returned, icon wins
facing"upright" | "flat"Whether the point, billboard, or label lies in the screen plane ("upright") or on the globe surface ("flat") (for points/billboards/text). Overrides the value the material’s pointFacing/billboardFacing/textFacing resolves to
rotateWithCamerabooleanWhether the point, billboard, or label turns with the camera (true) or with the map (false) (for points/billboards/text). Along a line, false makes a label follow the line, and true draws it straight unless spreadGlyphs is set. Overrides the value the material’s rotateWithCamera resolves to
spreadGlyphsbooleanWhether the label places each glyph on its own along its line (for text placed along a line). Overrides the material’s spreadGlyphs, for example to keep cursive scripts or fonts word by word in a layer that spreads the rest
rotationnumberIn-plane rotation, in degrees, clockwise as seen from the front (for points/billboards/text). It turns the feature around its anchor, except that a label following a line spins each glyph about its own center. Lets every feature in one layer point a different way. Overrides the material’s rotation
anchor"center" | "left" | "right" | "top" | "bottom" | "top-left" | "top-right" | "bottom-left" | "bottom-right"Which part of the point, billboard, or label sits on its position (for points/billboards/text). Overrides the material’s anchor (see anchor)
offset{ x: number, y: number }Shift from the anchor point, x right and y down: in ems for text, in the unit of size for points and billboards. Overrides the material’s offset (see offset)
variableAnchors{ anchor: Anchor, offset?: { x: number, y: number } }[]Placements the declutter pass tries in order for this label (for text features), offsets in ems. Overrides the material’s variableAnchors
textAlign"left" | "center" | "right" | "auto"Line justification (for text features). "auto" follows the label’s anchor. Overrides the material’s textAlign
outlineColorColorOutline color (for text features), or halo color of an SDF icon (for billboard features). Overrides the material’s outlineColor (text, billboard)
outlineOpacitynumberOutline or SDF halo opacity, range 0.0-1.0 (for text/billboard features). Overrides the material’s outlineOpacity (text, billboard)
outlineWidthnumberOutline thickness in 1/64 em (for text features), or SDF halo width in screen pixels (for billboard features). Overrides the material’s outlineWidth (text, billboard)
outlineBlurnumberWidth over which the outline fades out, in 1/64 em (for text features) or screen pixels (for billboard features). Overrides the material’s outlineBlur (text, billboard)
emissiveColorEmissive color (for batched polygons/3D Tiles models/points/billboards/text, ignored on models without batch/feature ids). Pairs with emissiveIntensity and drives selective bloom. A feature given neither keeps the layer material’s emissive; one given only emissive glows at intensity 1. On text only the glyph fill glows, while the outline and background stay dark
emissiveIntensitynumberEmissive intensity multiplier (for batched polygons/3D Tiles models/points/billboards/text). A feature given only emissiveIntensity multiplies black, so 0 takes it out of the bloom
transitionEvaluatedTransitionThe timing of each property of the same result that moves to its new value (for polygon, polyline and model features). See Transition

Per-feature facing and rotateWithCamera are not resolved like MapLibre’s "auto". Each replaces only its own half of the orientation the material resolved, so returning only rotateWithCamera: false for a point label keeps it upright, turned with the camera heading. Return facing: "flat" as well for a north-up label on the surface.

Example:

import { Color } from "@navaramap/three";
// Color 3D Tiles buildings by height
layer.on("featureUpdated", ({ evaluator }) => {
evaluator.evaluate(({ properties }) => {
const measuredHeight = properties?.["height"] as number;
const color = (() => {
if (measuredHeight < 30) return new Color().setStyle("#00ff00");
if (measuredHeight < 60) return new Color().setStyle("#ffff00");
if (measuredHeight < 90) return new Color().setStyle("#ff00ff");
return new Color().setStyle("#ff0000");
})();
return {
color,
show: measuredHeight >= 30, // Hide low buildings
};
});
});
// Apply property-based extrusion to GeoJSON polygons
layer.on("featureUpdated", ({ evaluator }) => {
evaluator.evaluate(({ properties }) => {
const height = (properties?.["height"] as number) ?? 0;
const extrudedHeight = (properties?.["extrudedHeight"] as number) ?? 0;
return {
height,
extrudedHeight,
};
});
});
// Color MVT features by category property
layer.on("featureUpdated", ({ evaluator }) => {
evaluator.evaluate(({ properties }) => {
const category = properties?.["category"] as string;
const color = (() => {
if (category === "A") return "#0000ff";
if (category === "B") return "#00ff00";
return "#ff0000";
})();
return {
color: new Color().setStyle(color),
};
});
});
// Filter and style text labels
layer.on("featureUpdated", ({ evaluator }) => {
evaluator.evaluate(({ properties }) => {
const text = properties?.["name"] as string;
return {
text,
show: !!text,
};
});
});
// Set per-feature billboard images based on a property
layer.on("featureUpdated", ({ evaluator }) => {
evaluator.evaluate(
({ properties }) => {
const icon = properties?.["icon"] as string | undefined;
// Features without an icon fall back to the billboard material's
// default url; `image: null` also clears a previously set image
return { image: icon ? `/icons/${icon}.svg` : null };
},
{ filters: ["icon"] },
);
});
// Rank city labels above village labels when decluttering
const TIER_PRIORITY: Record<number, number> = { 1: 3, 2: 2, 3: 1 };
layer.on("featureUpdated", ({ evaluator }) => {
evaluator.evaluate(({ properties }) => ({
text: properties?.["name"] as string,
declutterPriority: TIER_PRIORITY[properties?.["tier"] as number] ?? 0,
}));
});
// Highlight selected feature with pick event
let selectedId: string | undefined;
// Select feature on click
view.on("featureClick", (info) => {
selectedId = info?.properties?.["id"] as string;
layer.forceUpdate(); // Re-evaluate styles
});
// Change color based on selection state
layer.on("featureUpdated", ({ evaluator }) => {
evaluator.evaluate(({ properties }) => {
const id = properties?.["id"] as string;
return {
color: new Color().setHex(selectedId === id ? 0xff0000 : 0xffffff),
};
});
});
// Make features glow per property via selective bloom
// (the layer's material must list the bloom effect in `effectIds`)
layer.on("featureUpdated", ({ evaluator }) => {
evaluator.evaluate(
({ properties }) => ({
emissive: new Color().setStyle("#7fd0ff"),
emissiveIntensity: (properties?.["glow"] as number) ?? 0,
}),
{ filters: ["glow"] },
);
});
// Raise the clicked building over 300 ms
let selectedId: string | undefined;
view.on("featureClick", (info) => {
selectedId = info?.properties?.["id"] as string;
layer.forceUpdate();
});
layer.on("featureUpdated", ({ evaluator }) => {
evaluator.evaluate(
({ properties }) => ({
extrudedHeight: properties?.["id"] === selectedId ? 200 : 50,
transition: { extrudedHeight: { duration: 300, easing: "cubic-out" } },
}),
{ filters: ["id"] },
);
});

Type definition that can be returned from the evaluate() callback:

type EvaluatedValue = {
/** Feature color */
color?: Color;
/** Feature visibility (show/hide) */
show?: boolean;
/** Polygon extrusion height (meters) */
extrudedHeight?: number;
/** Feature height (meters) */
height?: number;
/** Label text content */
text?: string;
/** Line width (pixels, for polyline features) */
width?: number;
/** Softens the line's edge over this many pixels (for polyline
* features). Overrides the material's `blur` */
blur?: number;
/** Point/text size (meters or pixels, for point/text features) */
size?: number;
/** Extra space between characters in ems (for text features). Overrides
* the material's `letterSpacing` */
letterSpacing?: number;
/** Feature opacity, range 0.0-1.0 (for polygons/points/billboards/models/text) */
opacity?: number;
/** Placement priority for decluttering; higher wins an overlap (for
* points/billboards/text with `declutter` enabled). Overrides the
* layer's `declutterPriority` */
declutterPriority?: number;
/** Image URL (for billboard features); each distinct URL is loaded once and
* packed into the layer's texture atlas. `null` clears a previous
* per-feature image, reverting to the billboard material's default url */
image?: string | null;
/** Name of an icon in the billboard material's `sprite`, drawn in place of
* `image`. `null` clears a previous per-feature icon */
icon?: string | null;
/** Whether the point, billboard, or label lies in the screen plane
* ("upright") or on the globe surface ("flat") (for points/billboards/text).
* Overrides the material's facing option */
facing?: "upright" | "flat";
/** Whether the point, billboard, or label turns with the camera (`true`) or
* with the map (`false`) (for points/billboards/text). Along a line, `false`
* makes a label follow the line */
rotateWithCamera?: boolean;
/** Whether the label places each glyph on its own along its line (for
* text placed along a line) */
spreadGlyphs?: boolean;
/** In-plane rotation, in degrees, clockwise as seen from the front (for
* points/billboards/text). A label following a line spins each glyph about
* its own center */
rotation?: number;
/** Which part of the point, billboard, or label sits on its position (for
* points/billboards/text). Overrides the material's `anchor` */
anchor?:
| "center"
| "left"
| "right"
| "top"
| "bottom"
| "top-left"
| "top-right"
| "bottom-left"
| "bottom-right";
/** Shift from the anchor point, `x` right and `y` down: in ems for text, in
* the unit of `size` for points and billboards. Overrides the material's
* `offset` */
offset?: { x: number; y: number };
/** Placements the declutter pass tries in order (for text features),
* offsets in ems. Overrides the material's `variableAnchors` */
variableAnchors?: {
anchor: NonNullable<EvaluatedValue["anchor"]>;
offset?: { x: number; y: number };
}[];
/** Line justification (for text features); `"auto"` follows `anchor`.
* Overrides the material's `textAlign` */
textAlign?: "left" | "center" | "right" | "auto";
/** Outline color (for text features), or SDF halo color (for billboard
* features). Overrides the material's `outlineColor` */
outlineColor?: Color;
/** Outline or SDF halo opacity, range 0.0-1.0 (for text/billboard
* features). Overrides the material's `outlineOpacity` */
outlineOpacity?: number;
/** Outline thickness in 1/64 em (for text features), or SDF halo width in
* screen pixels (for billboard features). Overrides the material's
* `outlineWidth` */
outlineWidth?: number;
/** Width over which the outline fades out, in 1/64 em (for text features)
* or screen pixels (for billboard features). Overrides the material's
* `outlineBlur` */
outlineBlur?: number;
/** Emissive color (for batched polygons/3D Tiles models/points/billboards/
* text; ignored on models without batch/feature ids). Pairs with
* `emissiveIntensity` and drives selective bloom. On text only the glyph
* fill glows, while the outline and background stay dark */
emissive?: Color;
/** Emissive intensity multiplier (for batched polygons/3D Tiles
* models/points/billboards/text) */
emissiveIntensity?: number;
};

How a property returned from the evaluate() callback moves from the value the feature shows to its new value. The two values are blended on the GPU, so a running transition costs no evaluation, however many features move.

type Transition = {
/** Milliseconds the blend takes */
duration: number;
/** Milliseconds from the evaluation to the start of the blend. Default 0 */
delay?: number;
/** Curve of the blend. Default "linear" */
easing?:
| "linear"
| "quad-in"
| "quad-out"
| "quad-in-out"
| "cubic-in"
| "cubic-out"
| "cubic-in-out";
};
type TransitionableProperty =
| "color"
| "opacity"
| "show"
| "height"
| "extrudedHeight"
| "width"
| "emissive"
| "emissiveIntensity";
type PropertyTransition<K extends TransitionableProperty> = Transition & {
/** The value the blend starts from when the feature enters. Default: the
* value the layer draws the feature with */
enter?: EvaluatedValue[K];
/** The value the blend starts from on every evaluation */
from?: EvaluatedValue[K];
};
type EvaluatedTransition = {
[K in TransitionableProperty]?: PropertyTransition<K>;
};

transition gives a timing to each property of the result that moves to its new value. A property without a timing applies at once, and so does a property the feature cannot blend:

PropertyPolygonsPolylines3D Tiles and glTF modelsPoints and billboardsText
color✅✅✅✅✅
opacity✅✅✅✅✅
show✅✅✅❌❌
height✅✅❌❌❌
extrudedHeight✅❌❌❌❌
width❌✅❌❌❌
emissive✅❌✅✅✅
emissiveIntensity✅❌✅✅✅

A model blends the meshes whose features are identified per vertex (_BATCHID, glTF vertex feature IDs) or by a feature ID texture (EXT_mesh_features); the values of a mesh without feature IDs apply at once. Points and billboards place and declutter themselves from show, size, height and their other layout values, so those apply at once; to fade one in or out, give opacity a timing. Their material draws its emissive as the feature’s color plus the emissive color, times the intensity, so an entering emissive starts from the emissive color and intensity alone. A feature that has no emissive or emissiveIntensity of its own draws the layer’s, so its emissive moves from the layer’s emissive color (times the layer’s intensity when the result gives no emissiveIntensity) and its emissiveIntensity from the layer’s intensity. Given only emissiveIntensity, it multiplies black. The bloom of a polygon or a model also adds the feature’s color times the layer’s intensity, which the start value leaves out. Text blends the same values, and applies its show, text, size and other layout values at once for the same reason. A label that draws nothing, while its font loads or while its text is empty or only whitespace, holds the transitions started meanwhile and plays each as if it were started when the label draws, after its own delay; the layer’s events count them from then.

  • Start: every transition of one evaluate() call starts at the moment the call is applied, plus its delay. A negative delay starts the blend part way through.
  • Unchanged values: a property evaluated to the value it already moves to starts nothing, so layer.forceUpdate() leaves the running transitions of unchanged features alone.
  • Interruption: a property that changes again while it is blending starts from the value in between.
  • Entering features: a feature enters when it receives its first value of any property, when its show turns true, and when its tile is shown again after the tiles of another zoom level hid it. Its properties with a timing then move from their enter value, which defaults to the value the layer draws the feature with. With a timing on extrudedHeight, a building rises from the layer’s extrudedHeight when its tile appears. A property whose enter value is its new value applies at once, as do the values of a feature entering hidden.
  • Hidden features: every value of a feature that is hidden and stays hidden applies at once, so a feature shown again does not play a transition started while it was hidden. To fade a feature in when it is shown, give opacity an enter value of 0.
  • from: gives the value the property starts from on every evaluation, instead of the value it shows or its enter value, even when the new value is the one it already moves to. It is for an application that keeps its own timeline: with delay computed from the timeline’s time, each evaluation places the transition at its position on the timeline, after a seek as well.
  • show: the feature stays visible for the whole blend: shown from the start of the blend when it becomes visible, hidden at its end when it becomes hidden.
  • width: a width blends when both widths are given. A change to or from the material’s width switches when the blend starts.
  • Draped layers: a layer drawn with clampToGround redraws its features into the terrain’s textures on every frame while a transition runs.
  • Events: the layer emits transitionStart when the first of its transitions starts to blend, after its delay, and transitionEnd when the last one ends. The view renders every frame in between, and none while the transitions wait for their delay. The features of one glTF material of a model blend apart from those of its other materials, so when their transitions do not overlap in time, the layer emits one pair of events for each, as it does for separate tiles.

The curves are also available as the function ease(easing, t), which takes the linear progress t (clamped to 0-1). An application that pauses its own timeline computes the values the transitions show with it.

Example:

// Raise each building from the layer's extrudedHeight when its tile appears
layer.on("featureUpdated", ({ evaluator }) => {
evaluator.evaluate(
({ properties }) => ({
extrudedHeight: properties?.["height"] as number,
transition: { extrudedHeight: { duration: 1000, easing: "cubic-out" } },
}),
{ filters: ["height"] },
);
});
// Fade features in when they appear, out when their category is hidden,
// and in again when it is shown
const hidden = new Set<string>();
layer.on("featureUpdated", ({ evaluator }) => {
evaluator.evaluate(
({ properties }) => {
const visible = !hidden.has(properties?.["category"] as string);
return {
show: visible,
opacity: visible ? 1 : 0,
transition: {
show: { duration: 250, easing: "quad-out" },
opacity: { duration: 250, easing: "quad-out", enter: 0 },
},
};
},
{ filters: ["category"] },
);
});
import { ease } from "@navaramap/three";
// Raise each building in the year it was built, on a timeline the application keeps
const FIRST_YEAR = 1900;
const MS_PER_YEAR = 100;
const RISE_MS = 1000;
let playing = true;
let startedAt = performance.now();
let pausedAt = 0;
// Milliseconds into the timeline
const timelineNow = () => (playing ? performance.now() - startedAt : pausedAt);
layer.on("featureUpdated", ({ evaluator }) => {
const now = timelineNow();
evaluator.evaluate(
({ properties }) => {
const height = properties?.["height"] as number;
const year = properties?.["year"] as number;
// Milliseconds from now until the building starts to rise
const delay = (year - FIRST_YEAR) * MS_PER_YEAR - RISE_MS - now;
if (!playing) {
// Hold the values the transitions show now
return {
show: delay <= 0,
extrudedHeight: height * ease("quad-out", -delay / RISE_MS),
};
}
return {
show: true,
extrudedHeight: height,
transition: {
show: { duration: RISE_MS, delay, from: false },
extrudedHeight: {
duration: RISE_MS,
delay,
easing: "quad-out",
from: 0,
},
},
};
},
{ filters: ["year", "height"] },
);
});
const pause = () => {
pausedAt = timelineNow();
playing = false;
layer.forceUpdate();
};
const resume = () => {
startedAt = performance.now() - pausedAt;
playing = true;
layer.forceUpdate();
};