maplibregl-recorder
    Preparing search index...

    Class Recorder

    Records every call an application makes into MapLibre GL JS, as a timeline that emitScript writes back out as the JavaScript that would make them.

    This is the engine and nothing else: it has no user interface and touches no files. The panel that drives it is RecorderControl, a MapLibre control that uses this class through its public API.

    Experimental. This reaches into MapLibre's own classes, which are not a stable interface: a MapLibre release can break it at any time. It is a debugging aid for producing bug reports, not something to ship.

    Most of the time you want the shared MaplibreRecorder instance rather than one of your own.

    import * as maplibre from 'maplibre-gl';
    import { MaplibreRecorder } from 'maplibregl-recorder';

    // A module namespace is read-only, so the recorder patches a copy - and the
    // application has to build its map from that same copy.
    const maplibregl = {...maplibre};

    MaplibreRecorder.attach(maplibregl); // before any map is created
    // ... reproduce the problem in the application ...
    MaplibreRecorder.mark('markers are oversized here');

    // Exporting is the control's job - see {@link RecorderControl} - or, without
    // any user interface, `buildReproPage(MaplibreRecorder.toJSON())`.
    Index
    version: string = RECORDER_VERSION

    Version of the recorder, written into every recording.

    • get isRecording(): boolean

      Whether the recorder is currently capturing calls.

      Returns boolean

    • get logCalls(): boolean

      Whether every entry is printed to the console as it is recorded. The RecorderOptions.logCalls option sets the same thing up front; this turns it on and off in the middle of a session.

      Returns boolean

      MaplibreRecorder.logCalls = true;   // watch the calls come in
      
    • set logCalls(enabled: boolean): void

      Parameters

      • enabled: boolean

      Returns void

    • Patches a MapLibre namespace and starts recording. Call this before the application creates any map.

      Parameters

      • Optionalnamespace: any

        the MapLibre namespace. It has to be writable, because the constructors are replaced on it: pass {...maplibre} rather than the module namespace itself, and have the application use that same copy. Defaults to window.maplibregl.

      • Optionaloptions: RecorderOptions

        recorder options

      Returns this

      the recorder, for chaining

    • Fallback for applications that bundle MapLibre and do not expose the namespace. Only Map calls are captured - marker and popup calls are not, because their classes cannot be reached from a map instance.

      Parameters

      • map: any

        a live Map instance

      • Optionaloptions: RecorderOptions

        recorder options

      Returns this

      the recorder, for chaining

    • Discards everything recorded so far and restarts the clock.

      Returns this

    • Notes what is on screen right now, at this point in the timeline.

      A recording is a few hundred calls with no indication of which one matters. A mark becomes a comment at exactly this place in the exported script, so whoever reads the reproduction knows which line to look at. It is an annotation and never a call - nothing else about the recording changes.

      Parameters

      • label: string

        what is on screen right now, e.g. 'markers are oversized'

      Returns this

      the recorder, for chaining

    • Subscribes to state changes - a call recorded, recording paused, the timeline cleared. This is how a front end such as RecorderControl follows the recorder without the recorder knowing anything about it.

      Parameters

      • listener: () => void

        called after every change

      Returns () => void

      a function that removes the listener

    • Prints everything recorded so far to the console, one line per entry, so what has been captured can be read without exporting anything.

      The calls MapLibre made into itself are indented under the call that caused them and marked with . They never reach the exported script, so this is the only place they show up - marker.addTo(map) is one line, and the remove and setDraggable MapLibre reaches it through sit under it.

      Returns this

      the recorder, for chaining

    • Pauses recording. Patches stay in place, so recording can be resumed.

      Returns this