Skip to content

API reference / @zaes/tactical-graphics/maplibre / NativeLayerRenderer

Class: NativeLayerRenderer ​

Defined in: components/maplibre/native/NativeLayerRenderer.ts:278

Constructors ​

Constructor ​

ts
new NativeLayerRenderer(map, options?): NativeLayerRenderer;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:379

Parameters ​

map ​

Map$1

options? ​

NativeLayerRendererOptions = {}

Returns ​

NativeLayerRenderer

Properties ​

lastFeatureCount ​

ts
lastFeatureCount: number = 0;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:306

GeoJSON features uploaded on that realization.


lastRealizeBreakdown ​

ts
lastRealizeBreakdown: object;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:315

Where the last realization's time went, in milliseconds.

Kept because "realize costs 26 ms" is not actionable and "22 of the 26 are in setData" is. Three numbers, taken from a clock that is already running.

bucket ​

ts
bucket: number;

paint ​

ts
paint: number;

upload ​

ts
upload: number;

lastRealizeMs ​

ts
lastRealizeMs: number = 0;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:304

Milliseconds the last geometry realization took. The number the spike is for.


lastVisibleCount ​

ts
lastVisibleCount: number = 0;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:317

How many graphics survived the cull on the last realization.


realizeCount ​

ts
realizeCount: number = 0;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:308

How many times the geometry has been rebuilt since construction.

Accessors ​

count ​

Get Signature ​

ts
get count(): number;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:575

Returns ​

number


selection ​

Get Signature ​

ts
get selection(): string | null;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:771

The currently selected graphic's id, or null.

Returns ​

string | null

Methods ​

add() ​

ts
add(graphic): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:471

Parameters ​

graphic ​

PaintedGraphic

Returns ​

void


centerHandleOf() ​

ts
centerHandleOf(graphic): number;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:1155

Which of a graphic's handles is its center, or -1.

Found by position, not by index: the documented order for the point-anchored family is [edge, center], but a range fan emits one handle per band and the corridors emit one per turning point, so an index would be right for one family and wrong for the rest. A handle sitting on the base point is the center in every family that has one.

Parameters ​

graphic ​

PaintedGraphic

Returns ​

number


clear() ​

ts
clear(): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:531

Returns ​

void


destroy() ​

ts
destroy(): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:1221

Returns ​

void


find() ​

ts
find(id): PaintedGraphic | undefined;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:1084

The graphic with this id, or undefined.

Parameters ​

id ​

string

Returns ​

PaintedGraphic | undefined


flush() ​

ts
flush(): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:501

Runs any pending rebuild now. For a caller that cannot wait a microtask.

Returns ​

void


hitTest() ​

ts
hitTest(point, radiusPx?): PaintedGraphic | undefined;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:1127

The graphic under a screen point, or undefined.

radiusPx widens the query into a box, because most of these symbols are line work: a one-pixel query against a two-pixel line asks the operator to be more accurate than the symbol is wide.

Parameters ​

point ​
x ​

number

y ​

number

radiusPx? ​

number = 5

Returns ​

PaintedGraphic | undefined


hitTestHandle() ​

ts
hitTestHandle(point, radiusPx?): 
  | {
  graphic: PaintedGraphic;
  index: number;
}
  | undefined;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:1165

The handle index under a screen point, or -1.

Queried ahead of the graphic body, because a handle sits on the graphic it belongs to and the body would otherwise always win.

Parameters ​

point ​
x ​

number

y ​

number

radiusPx? ​

number = 8

Returns ​

| { graphic: PaintedGraphic; index: number; } | undefined


opacityOf() ​

ts
opacityOf(id): number;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:571

A graphic's opacity, 1 unless setOpacity dimmed it.

Parameters ​

id ​

string

Returns ​

number


realize() ​

ts
realize(): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:586

Rebuilds every graphic's geometry at the current resolution and uploads it.

This is the whole of path B's per-zoom cost: run the paint functions, bucket the marks, reproject every coordinate to lon/lat, and hand MapLibre new GeoJSON. Timed end to end.

Returns ​

void


remove() ​

ts
remove(id): boolean;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:544

Takes one graphic off the map. True when there was one to take.

Its opacity goes with it, and so does the selection if it held it. A host that hides a graphic rather than deleting it removes it here and adds it back later: hidden is not drawn, so there is no separate hidden state to keep in step.

Parameters ​

id ​

string

Returns ​

boolean


replace() ​

ts
replace(id, next): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:1113

Swaps a graphic for a rebuilt version of itself, keeping its place in the draw order.

Order matters because the paint list is emitted in graphic order and MapLibre draws a source's features in the order they arrive: moving an edited graphic to the end would lift it above whatever it used to sit under.

Parameters ​

id ​

string

next ​

PaintedGraphic

Returns ​

void


select() ​

ts
select(id): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:764

Shows the given graphic's handles, or none.

Separate from realize because selection changes far more often than geometry does — a click that only moves the selection has no reason to repaint 200 graphics.

Parameters ​

id ​

string | null

Returns ​

void


setHandleMode() ​

ts
setHandleMode(active, selectionScoped?): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:1076

Whether a handle-bearing mode is selected, and whether that mode scopes handles to the selection. Set by the interaction layer, because the mode is its state; the renderer only needs to know whether to draw chrome, and for which graphics.

Parameters ​

active ​

boolean

selectionScoped? ​

boolean = false

Returns ​

void


setMeasure() ​

ts
setMeasure(
   line, 
   caption?, 
   parts?
): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:787

Shows the radius read-out, or clears it.

A hashed line from the center to the rim with the distance on it, drawn while a circular graphic is sized — the same chrome as OpenLayers' measure feature, and deliberately the same words: both call formatDistance, so the read-out, the other renderer's read-out and the properties dialog cannot disagree about a number the operator is comparing.

Editor chrome, so it lives in its own source rather than in the paint buckets: it must never reach snapshot, a sample sweep or a restored map.

Parameters ​

line ​

| [ProjectedPosition, ProjectedPosition] | null

caption? ​

string

parts? ​

MeasurePart[]

Returns ​

void


setOpacity() ​

ts
setOpacity(id, opacity): boolean;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:561

Draws one graphic at opacity, 0 to 1: lines, fills, labels and center symbol fade together. 1 draws it fully opaque again. True when the graphic is on the map.

View state, not part of the graphic: it never reaches snapshot, survives edits and rebuilds, and goes with remove and clear.

Parameters ​

id ​

string

opacity ​

number

Returns ​

boolean


setPreview() ​

ts
setPreview(graphic): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:1099

The graphic being drawn, painted but not owned.

Held apart from graphics on purpose. It is not a graphic the map has — it is a picture of the one the next click would create — so it must not appear in a snapshot, in count, or under a hit test, all of which read graphics. Passing it through add/remove would have put it in all three, and a save taken mid-gesture would have persisted a symbol the operator never committed to.

Parameters ​

graphic ​

PaintedGraphic | null

Returns ​

void

See ​

MapLibreInteractions.previewDraw


setSketch() ​

ts
setSketch(points): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:830

Sets the line being drawn, or clears it. Repaints only the editor chrome.

Parameters ​

points ​

ProjectedPosition[] | null

Returns ​

void


setVertexHint() ​

ts
setVertexHint(position): void;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:821

Marks where a drag would add a vertex, or clears the mark.

Called on every pointer move in modify mode, so it returns early when nothing changed: repainting the editor marks on each mousemove would rebuild the handle source hundreds of times a second for a dot that has not moved.

Parameters ​

position ​

ProjectedPosition | null

Returns ​

void


snapshot() ​

ts
snapshot(): FeatureCollection;

Defined in: components/maplibre/native/NativeLayerRenderer.ts:518

Every graphic as a plain GeoJSON FeatureCollection — one base feature each, the same shape serializeTacticalGraphics produces on the OpenLayers side.

The base is all that is saved because everything else is derived: the geometry, the decorations and the labels all regenerate from properties.tacticalGraphic, which is the portable description any renderer consumes. Saving the drawn output instead would produce a picture rather than a graphic.

Returns ​

FeatureCollection

Released under the MIT License.