Skip to content

API

new CZMLPlugin();

Register the plugin with view.addPlugin() before view.init(). The constructor takes no options.

load(options: CZMLLoadOptions): Promise<CZMLDocument>

Reads a CZML document and shows its polygons, polylines, labels, points and billboards. Must be called after view.init(). Otherwise the call rejects.

options is one of:

PropertyTypeDescription
urlstringURL of the CZML document to fetch.
datareadonly CZMLPacket[]The packets of an already parsed CZML document.

The shapes of a document become vector layers, one per group of shapes drawn the same way:

  • Polygons with an extrudedHeight, polygons with perPositionHeight, and polygons with both
  • Polylines at the heights of their positions, and polylines with clampToGround
  • Labels, one group per font family and background color
  • Points
  • Billboards, and billboards with sizeInMeters

A packet with several of polygon, polyline, label, point and billboard adds a shape to each of their groups. What the plugin cannot show is left out, with one console.warn per reason stating how many packets it was left out of. A packet whose availability or sample times cannot be parsed is left out the same way, and so is a clock interval or currentTime that cannot be parsed.

The call rejects when:

  • the document cannot be fetched
  • two sampled values of the document use different sample times
  • the sample times do not increase
  • the plugin is disposed before a document given by url is fetched

Returns the CZMLDocument. The document shows its clock.currentTime at first. Without one it shows the start of its clock.interval, and without an interval its first sample time.

dispose(): void

Removes every document this plugin loaded, with its layers and sources.

A CZML document shown on the view, returned by load().

Type: string | undefined

Description: The name of the document packet.

Type: CZMLClock

Description: The clock of the document packet, which play() follows.

PropertyTypeDescription
interval{ start: Date; stop: Date } | undefinedThe time range the clock runs over. When the document packet gives none, the range from the earliest start to the latest stop of the availabilities of the packets shown.
currentTimeDate | undefinedThe time the document starts at.
multipliernumber | undefinedMilliseconds of the document per millisecond, the default speed of play().
range"UNBOUNDED" | "CLAMPED" | "LOOP_STOP" | undefinedWhat playing does at the end of interval: start over (LOOP_STOP, the default), pause (CLAMPED), or play on (UNBOUNDED).

Type: readonly Date[]

Description: The times the document’s values are sampled at, in increasing order. They are not necessarily evenly spaced. Empty when nothing in the document is sampled.

Type: Date | undefined

Description: The time the document is shown at, which moves while it plays. undefined before the first setTime() when the document has neither a clock, a sample nor an availability.

Type: number | undefined

Description: The fractional index into times the document is shown at: 2.5 is halfway between the third and the fourth sample time. undefined when nothing in the document is sampled.

Type: boolean

Description: Whether the document is playing. A document is paused when it loads.

Type: CZMLBounds | undefined

Description: The extent of the document’s shapes as { west, south, east, north } in degrees. undefined when the document has no shape the plugin shows.

Example:

const doc = await czml.load({ url: "https://example.com/population.czml" });
if (doc.bounds) {
const { west, south, east, north } = doc.bounds;
view.setCamera({
lng: (west + east) / 2,
lat: (south + north) / 2,
height: 0,
distance: 5000,
heading: 0,
pitch: -45,
roll: 0,
});
}

Type: readonly Layer[]

Description: The Layer handles showing the document, one per group of shapes as load() lists them.

play(options?: CZMLPlayOptions): void

Plays the document from the time it is shown at, at one of two rates:

  • { speed }: milliseconds of the document per millisecond. Defaults to the clock’s multiplier, or 1. At 0 or below no transition starts: the features take the values of the time they are evaluated at.
  • { sampleDuration }: milliseconds from one sample time to the next, however far apart they are. Use it when the sample times are unevenly spaced. It needs a document with samples.

At the end of the clock’s interval (with sampleDuration, at the last sample), the clock’s range decides whether the playback starts over, pauses, or plays on. Calling play() while playing changes the rate.

Example:

// Two samples per second, however far apart the sample times are
doc.play({ sampleDuration: 500 });
// A document without samples, whose packets are shown one after the other by
// their availability, plays through its clock interval in 20 seconds
const { interval } = doc.clock;
if (doc.times.length === 0 && interval) {
const span = interval.stop.getTime() - interval.start.getTime();
doc.play({ speed: span / 20_000 });
}
pause(): void

Stops the document at the time it is shown at.

setTime(time: Date | number): void

Shows the document as it is at time, given as a Date or as milliseconds since the Unix epoch. Values are interpolated linearly between the two samples around time. A time before the first sample shows the first sample, and a time after the last shows the last. A packet with an availability is hidden outside its interval, and shown at its start and stop times. A playing document plays on from time.

Example:

// Jump to the start of the clock's interval
const { interval } = doc.clock;
if (interval) doc.setTime(interval.start);
setSample(sample: number): void

Shows the document as it is at sample, a fractional index into times: 2.5 is halfway between the third and the fourth sample time. An index below 0 shows the first sample, and an index above the last shows the last. A document without samples ignores the call. A playing document plays on from there.

Example:

// A slider from 0 to 1 that moves through the samples
slider.addEventListener("input", () => {
doc.setSample(Number(slider.value) * (doc.times.length - 1));
});
delete(): void

Removes the document’s layers and sources from the view.

type CZMLLoadOptions = { url: string } | { data: readonly CZMLPacket[] };
type CZMLPacket = Record<string, unknown>;

One packet of a CZML document, as parsed from its JSON.

type CZMLClock = {
interval?: { start: Date; stop: Date };
currentTime?: Date;
multiplier?: number;
range?: "UNBOUNDED" | "CLAMPED" | "LOOP_STOP";
};
type CZMLPlayOptions = { speed?: number } | { sampleDuration: number };
type CZMLBounds = {
west: number;
south: number;
east: number;
north: number;
};