Socket
Book a DemoInstallSign in
Socket

leaflet-trackplayer-xiaoai

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leaflet-trackplayer-xiaoai

一个 Leaflet 轨迹播放插件,可以根据实际行进方向自动旋转标记图标,动态调整已行进和未行进路径的颜色以清晰显示当前进度。支持自定义行驶速度等功能,并提供完整的 TypeScript 类型定义。

latest
Source
npmnpm
Version
2.0.12
Version published
Maintainers
1
Created
Source

Leafelt.TrackPlayer

language: English / 简体中文

A Leaflet track playback plugin, enabling you to swiftly create stunning track replay functionality.
一个leaflet轨迹回放插件,帮助你快速构建出精美的轨迹回放功能。

🎨Live Demo

https://weijun-lab.github.io/Leaflet.TrackPlayer/

Installation

  • npm install leaflet-trackplayer
  • Or download the repository

Usage

ESM(ECMAScript Modules)

import  "leaflet-trackplayer";

UMD(Universal Module Definition)

<script src="Leaflet.TrackPlayer/dist/leaflet-trackplayer.umd.cjs"></script>
let track = new L.TrackPlayer(latlngs, options).addTo(map)

Code Example

let latlngs = [
       [
           34.291120985630914,
           108.91770583134237
       ],
       [
           34.29428596006031,
           108.9177058265846
       ],
];
let track = new L.TrackPlayer(latlngs, {
        markerIcon: L.icon({
          iconUrl: "Your image url",
        }),
        markerRotation: false,
}).addTo(map);
track.start();
track.on("progress",(progress, { lng, lat },index)=>{{
    console.log(`progress:${progress} - position:${lng},${lat} - trackIndex:${index}`)
})

Documentation

Latlngs

An array of latitude and longitude data for the trajectory, which is the same as the first parameter for L.polyline.

Options

OptionsTypeDefaultDescription
speedNumber600Travel speed (km/h)
weightNumber8Width of the trajectory line
markerIconL.icon-The icon of the moving marker during playback has a value equivalent to the 'icon' property of the L.marker.
polylineDecoratorOptionsObject{...}Arrowhead styles for the trajectory line, seeLeaflet.PolylineDecorator
passedLineColorString#0000ffColor of the traveled portion of the trajectory line
notPassedLineColorString#ff0000Color of the untraveled portion of the trajectory line
panToBooleantrueWhether the map view follows the moving marke
markerRotationBooleantrueWhether the marker auto-rotates according to the direction of movement
markerRotationOriginStringcenterThe rotation origin of the marker, follows the CSS transform-origin rule
markerRotationOffsetNumber0The angle offset for marker rotation

Methods

MethodsReturnDescription
start()-Start playback
pause()-Pause playback
setSpeed(<Number> speed,<Number> debounceTimeout?)-Set the playback speed (km/h)
setProgress(<Number> progress)-Set the playback progress value to 0-1
addTo(<Map> map)thisAdds the track player to the map
remove()-Removes the track player from the map
on(<String> type,<Function> fn)-Adds a listener function to the specified event type
off(<String> type,<Function> fn?)-Removes the passed-in listener function. If no function is specified, removes all listeners for the event type.

Event

EventDescription
startTriggered when playback starts
pauseTriggered when playback is paused
finishedTriggered when playback completes
progressTriggered during playback; receives the progress(0-1) and current location and track array index in the callback function

Properties

PropertiesTypeDescription
markerL.markerMoving marker on the trajectory
passedLineL.polylineThe traveled part of the trajectory line
notPassedLineL.polylineThe untraveled part of the trajectory line
polylineDecoratorL.polylineDecoratorThe arrowhead-decorated polyline
optionsObjectConfiguration options

🎉Acknowledgements & References

I gratitude to the following open-source plugins, which have provided essential support for the functionality.

Keywords

gis

FAQs

Package last updated on 01 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts