@wenle_2523097/agri-map 2.0.7 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,6 +4,13 @@
4
4
 
5
5
  ## 更新日志
6
6
 
7
+ ### v2.0.8 (2026-06-01)
8
+ #### 新增
9
+ - **TrackPlayer 时间轴功能**:新增 `onTimelineUpdate` 回调,暴露完整时间轴数据
10
+ - **useTimeline Hook**:提供时间轴数据计算逻辑(progress、时间戳、格式化时间等)
11
+ - **时间轴 UI 交互**:Demo 支持滑块拖动跳转、实时进度显示、时间戳标签
12
+ - **TimelineProgressInfo 类型**:完整的时间轴进度信息接口定义
13
+
7
14
  ### v2.0.7 (2026-05-27)
8
15
  #### 新增
9
16
  - **Panel 面板组件**:新增地图面板组件,支持在地图上渲染 React 内容
@@ -52,11 +59,6 @@ yarn add @wenle_2523097/agri-map
52
59
  ```bash
53
60
  npm install leaflet@^1.9.4 react@>=18.0.0 react-dom@>=18.0.0
54
61
  ```
55
-
56
- > ⚠️ **重要提示:**
57
- >
58
- > - 本库已移除 `react-leaflet` 依赖,直接使用原生 Leaflet API,更轻量、更灵活
59
-
60
62
  ---
61
63
 
62
64
  ## 快速开始
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TrackPlayer 组件单元测试
2
+ * @fileoverview TrackPlayer 组件单元测试
3
3
  * @description 测试轨迹播放组件的渲染、播放控制和状态管理
4
4
  */
5
5
  export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @fileoverview useTimeline hook 单元测试
3
+ * @module components/TrackPlayer/__tests__/useTimeline.test
4
+ */
5
+ export {};
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @fileoverview TrackPlayer 时间轴数据计算 Hook
3
+ * @module components/TrackPlayer/hooks/useTimeline
4
+ */
5
+ import type { TrackPointWithState } from '../types';
6
+ /** 时间轴信息 */
7
+ export interface TimelineInfo {
8
+ /** 起始时间戳 */
9
+ startTime: number | null;
10
+ /** 结束时间戳 */
11
+ endTime: number | null;
12
+ /** 当前时间戳 */
13
+ currentTime: number | null;
14
+ /** 进度百分比 0-1 */
15
+ progress: number;
16
+ /** 格式化起始时间 */
17
+ startTimeStr: string | null;
18
+ /** 格式化结束时间 */
19
+ endTimeStr: string | null;
20
+ /** 格式化当前时间 */
21
+ currentTimeStr: string | null;
22
+ }
23
+ interface UseTimelineOptions {
24
+ allPoints: TrackPointWithState[];
25
+ currentIndex: number;
26
+ }
27
+ /**
28
+ * 格式化时间戳为 HH:MM:SS 字符串
29
+ * @param timestamp 时间戳(毫秒),可为 null
30
+ */
31
+ export declare function formatTimestamp(timestamp: number | null): string | null;
32
+ /**
33
+ * 计算进度对应的索引
34
+ * @param allPointsLength 轨迹点总数
35
+ * @param progress 进度 0-1
36
+ * @returns 对应的索引
37
+ */
38
+ export declare function indexFromProgress(allPointsLength: number, progress: number): number;
39
+ /**
40
+ * 计算时间轴数据
41
+ * @param allPoints 轨迹点数组
42
+ * @param currentIndex 当前索引
43
+ * @returns 时间轴信息
44
+ */
45
+ export declare function useTimeline({ allPoints, currentIndex }: UseTimelineOptions): TimelineInfo;
46
+ /**
47
+ * 计算进度信息(用于 onProgress 回调兼容)
48
+ */
49
+ export declare function calcProgressInfo(allPoints: TrackPointWithState[], currentIndex: number, _distance: number): {
50
+ progress: number;
51
+ startTime: number | null;
52
+ endTime: number | null;
53
+ currentTime: number | null;
54
+ startTimeStr: string | null;
55
+ endTimeStr: string | null;
56
+ currentTimeStr: string | null;
57
+ };
58
+ export {};
@@ -52,6 +52,19 @@ export interface TrackPlayerProps {
52
52
  onStop?: () => void;
53
53
  onProgress?: (currentIndex: number, total: number, point: TrackPoint | null, distance: number, timestamp: number | null, time: string | null) => void;
54
54
  onComplete?: () => void;
55
+ /** 时间轴进度详细回调(提供完整时间轴数据) */
56
+ onTimelineUpdate?: (info: {
57
+ currentIndex: number;
58
+ totalPoints: number;
59
+ progress: number;
60
+ startTime: number | null;
61
+ endTime: number | null;
62
+ currentTime: number | null;
63
+ startTimeStr: string | null;
64
+ endTimeStr: string | null;
65
+ currentTimeStr: string | null;
66
+ distance: number;
67
+ }) => void;
55
68
  }
56
69
  declare const TrackPlayer: import("react").ForwardRefExoticComponent<TrackPlayerProps & import("react").RefAttributes<TrackPlayerHandle>>;
57
70
  export default TrackPlayer;
@@ -2,7 +2,7 @@
2
2
  * @fileoverview TrackPlayer 类型定义
3
3
  * @module components/TrackPlayer/types
4
4
  */
5
- import type { TrackData, TrackPoint, IconConfig } from '../../types';
5
+ import type { TrackData, TrackPoint, IconConfig, PathOptions } from '../../types';
6
6
  export type PlayStatus = 'idle' | 'playing' | 'paused' | 'stopped';
7
7
  /** 轨迹播放控制方法 */
8
8
  export interface TrackPlayerHandle {
@@ -32,6 +32,10 @@ export interface TrackPlayerProps {
32
32
  trailLength?: number;
33
33
  /** 显示轨迹线(完整路径) */
34
34
  showTrack?: boolean;
35
+ /** 播放前轨迹样式(未走过的路径),默认 TRACKPLAYER_STYLE.default */
36
+ path?: PathOptions | null | false;
37
+ /** 播放后轨迹样式(已走过的路径),默认 TRACKPLAYER_STYLE.played */
38
+ playPath?: PathOptions | null | false;
35
39
  /** 当前时刻图标配置,默认使用 TRACKPLAYER_DEFAULT_ICON */
36
40
  icon?: IconConfig | null | false;
37
41
  /** 图标默认朝向角度(度),默认 -90 */
@@ -44,6 +48,31 @@ export interface TrackPlayerProps {
44
48
  onStop?: () => void;
45
49
  onProgress?: (currentIndex: number, total: number, point: TrackPoint | null, distance: number, timestamp: number | null, time: string | null) => void;
46
50
  onComplete?: () => void;
51
+ /** 时间轴进度详细回调(提供完整时间轴数据) */
52
+ onTimelineUpdate?: (info: TimelineProgressInfo) => void;
53
+ }
54
+ /** 时间轴进度信息 */
55
+ export interface TimelineProgressInfo {
56
+ /** 当前索引 */
57
+ currentIndex: number;
58
+ /** 总点数 */
59
+ totalPoints: number;
60
+ /** 进度百分比 0-1 */
61
+ progress: number;
62
+ /** 起始时间戳 */
63
+ startTime: number | null;
64
+ /** 结束时间戳 */
65
+ endTime: number | null;
66
+ /** 当前时间戳 */
67
+ currentTime: number | null;
68
+ /** 格式化起始时间 */
69
+ startTimeStr: string | null;
70
+ /** 格式化结束时间 */
71
+ endTimeStr: string | null;
72
+ /** 格式化当前时间 */
73
+ currentTimeStr: string | null;
74
+ /** 已行进距离(米) */
75
+ distance: number;
47
76
  }
48
77
  /** 内部使用的轨迹点(含 state) */
49
78
  export interface TrackPointWithState extends TrackPoint {
package/dist/index.esm.js CHANGED
@@ -25601,7 +25601,8 @@ var TrackPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
25601
25601
  onPause = _ref.onPause,
25602
25602
  onStop = _ref.onStop,
25603
25603
  onProgress = _ref.onProgress,
25604
- onComplete = _ref.onComplete;
25604
+ onComplete = _ref.onComplete,
25605
+ onTimelineUpdate = _ref.onTimelineUpdate;
25605
25606
  var map = useMap();
25606
25607
  // ==================== 字段名合并 ====================
25607
25608
  var mergedFieldNames = useMemo(function () {
@@ -25736,7 +25737,31 @@ var TrackPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
25736
25737
  var timestamp = currentPoint[2];
25737
25738
  var formattedTime = timestamp !== null ? formatTime(timestamp) : null;
25738
25739
  onProgress === null || onProgress === void 0 || onProgress(currentIndex, totalPoints, currentPoint, distance, timestamp, formattedTime);
25739
- }, [map, currentIndex, allPoints, createMarkerIcon, onProgress, totalPoints]);
25740
+ // 时间轴进度详细回调
25741
+ if (onTimelineUpdate) {
25742
+ var _allPoints$, _allPoints$at;
25743
+ var startTime = (_allPoints$ = allPoints[0]) === null || _allPoints$ === void 0 ? void 0 : _allPoints$[2];
25744
+ var endTime = (_allPoints$at = allPoints.at(-1)) === null || _allPoints$at === void 0 ? void 0 : _allPoints$at[2];
25745
+ var progress = totalPoints > 1 ? currentIndex / (totalPoints - 1) : 0;
25746
+ var formatTimeStr = function formatTimeStr(ts) {
25747
+ if (ts === null) return null;
25748
+ var d = new Date(ts);
25749
+ return "".concat(String(d.getHours()).padStart(2, '0'), ":").concat(String(d.getMinutes()).padStart(2, '0'), ":").concat(String(d.getSeconds()).padStart(2, '0'));
25750
+ };
25751
+ onTimelineUpdate({
25752
+ currentIndex: currentIndex,
25753
+ totalPoints: totalPoints,
25754
+ progress: progress,
25755
+ startTime: startTime,
25756
+ endTime: endTime,
25757
+ currentTime: timestamp,
25758
+ startTimeStr: formatTimeStr(startTime),
25759
+ endTimeStr: formatTimeStr(endTime),
25760
+ currentTimeStr: formattedTime,
25761
+ distance: distance
25762
+ });
25763
+ }
25764
+ }, [map, currentIndex, allPoints, createMarkerIcon, onProgress, onTimelineUpdate, totalPoints]);
25740
25765
  // 轨迹线(已走过部分用 playPath,未走到部分用 path)
25741
25766
  useEffect(function () {
25742
25767
  if (!map || !showTrack || allPoints.length === 0) return;