Constructor
Section titled “Constructor”new CZMLPlugin();Register the plugin with view.addPlugin() before view.init(). The constructor takes no options.
Methods
Section titled “Methods”load(options)
Section titled “load(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:
| Property | Type | Description |
|---|---|---|
url | string | URL of the CZML document to fetch. |
data | readonly 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 withperPositionHeight, 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
urlis 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()
Section titled “dispose()”dispose(): voidRemoves every document this plugin loaded, with its layers and sources.
CZMLDocument
Section titled “CZMLDocument”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.
| Property | Type | Description |
|---|---|---|
interval | { start: Date; stop: Date } | undefined | The 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. |
currentTime | Date | undefined | The time the document starts at. |
multiplier | number | undefined | Milliseconds of the document per millisecond, the default speed of play(). |
range | "UNBOUNDED" | "CLAMPED" | "LOOP_STOP" | undefined | What 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.
sample
Section titled “sample”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.
playing
Section titled “playing”Type: boolean
Description: Whether the document is playing. A document is paused when it loads.
bounds
Section titled “bounds”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, });}layers
Section titled “layers”Type: readonly Layer[]
Description: The Layer handles showing the document, one per group of shapes as load() lists them.
play(options)
Section titled “play(options)”play(options?: CZMLPlayOptions): voidPlays 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’smultiplier, 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 aredoc.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 secondsconst { interval } = doc.clock;if (doc.times.length === 0 && interval) { const span = interval.stop.getTime() - interval.start.getTime(); doc.play({ speed: span / 20_000 });}pause()
Section titled “pause()”pause(): voidStops the document at the time it is shown at.
setTime(time)
Section titled “setTime(time)”setTime(time: Date | number): voidShows 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 intervalconst { interval } = doc.clock;if (interval) doc.setTime(interval.start);setSample(sample)
Section titled “setSample(sample)”setSample(sample: number): voidShows 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 samplesslider.addEventListener("input", () => { doc.setSample(Number(slider.value) * (doc.times.length - 1));});delete()
Section titled “delete()”delete(): voidRemoves the document’s layers and sources from the view.
CZMLLoadOptions
Section titled “CZMLLoadOptions”type CZMLLoadOptions = { url: string } | { data: readonly CZMLPacket[] };CZMLPacket
Section titled “CZMLPacket”type CZMLPacket = Record<string, unknown>;One packet of a CZML document, as parsed from its JSON.
CZMLClock
Section titled “CZMLClock”type CZMLClock = { interval?: { start: Date; stop: Date }; currentTime?: Date; multiplier?: number; range?: "UNBOUNDED" | "CLAMPED" | "LOOP_STOP";};CZMLPlayOptions
Section titled “CZMLPlayOptions”type CZMLPlayOptions = { speed?: number } | { sampleDuration: number };CZMLBounds
Section titled “CZMLBounds”type CZMLBounds = { west: number; south: number; east: number; north: number;};