Overlay Methods & Properties
Methods and properties available on an instance of the GmRouteReplayOverlay class.
Methods
play(): voidStarts or resumes playback from the current position.pause(): voidPauses playback at the current position.stop(): voidStops playback and resets the playback position to the start of the route.seek(timeMs: number): voidMoves the playback position to the specified timestamp (in milliseconds, relative to the route start time).setSpeed(speed: number): voidSets the playback speed multiplier.1is normal speed,2is double speed.setCameraMode(mode: CameraMode, options?: CameraOptions): voidSets the camera follow mode. SeeCameraModefor details. Optionally,CameraOptionscan be provided to update specific settings for the mode.setMap(map: google.maps.Map | null): voidSets or removes the map for the overlay. This is the standard method inherited fromOverlayView. Use this to associate the overlay with a map if you didn't providemapin the constructor. Passingnullremoves it from the map.addEventListener<K extends keyof PlayerEventMap>(type: K, listener: (ev: PlayerEventMap[K]) => any): voidSubscribes to player events. See theEventspage for event types and payloads.removeEventListener<K extends keyof PlayerEventMap>(type: K, listener: (ev: PlayerEventMap[K]) => any): voidRemoves a previously registered event listener.destroy(): voidDestroys the overlay instance. Removes associated elements from the map, stops animations, and removes event listeners. It's recommended to callsetMap(null)or this method when the instance is no longer needed.
Properties (Read-only)
isReady: booleanWhether the player is initialized and ready for operations.durationMs: numberThe total playback duration of the route in milliseconds.currentTimeMs: numberThe current playback time in milliseconds.currentProgress: numberThe current playback progress (from 0 to 1).currentSpeed: numberThe current playback speed.currentCameraMode: CameraModeThe current camera mode.
Example
typescript
import { GmRouteReplayOverlay } from 'route-replay-googlemaps-core';
const overlay = new GmRouteReplayOverlay(options);
overlay.setMap(map);
overlay.addEventListener('ready', () => {
document.getElementById('playButton').addEventListener('click', () => overlay.play());
document.getElementById('pauseButton').addEventListener('click', () => overlay.pause());
document.getElementById('speedSlider').addEventListener('input', (event) => {
const speed = parseFloat((event.target as HTMLInputElement).value);
overlay.setSpeed(speed);
});
overlay.addEventListener('frame', (payload) => {
console.log(`Frame at progress: ${overlay.currentProgress.toFixed(2)}`);
});
overlay.addEventListener('finish', () => {
console.log('Playback finished!');
});
});
window.addEventListener('beforeunload', () => {
overlay.setMap(null);
});