---
title: "MapboxTrail"
description: "动态轨迹，line-gradient 彗尾沿线循环平移。"
seo_title: "MapboxTrail Component"
seo_description: "Animated trail effect with a line-gradient comet tail looping along a line feature."
canonical_url: "https://mapbox.mhaibaraai.cn/docs/effects/trail"
---
# MapboxTrail

> 动态轨迹，line-gradient 彗尾沿线循环平移。

## 简介

`MapboxTrail` 在线要素上渲染动态轨迹：`line-gradient` 彗尾窗口沿线循环平移（source 自动开启 `lineMetrics`）；`color` / `lineWidth` / `trailLength` / `duration` / `baseLine` 控制外观与节奏。

## 用法

切换主色查看彗尾沿线流动：

```vue [TrailExample.vue]
<script setup lang="ts">
import type { FeatureCollection } from 'geojson'

withDefaults(defineProps<{ color?: string }>(), {
  color: '#8b5cf6'
})

const data: FeatureCollection = {
  type: 'FeatureCollection',
  features: [{
    type: 'Feature',
    properties: {},
    geometry: {
      type: 'LineString',
      coordinates: [[116.30, 39.90], [116.40, 39.94], [116.50, 39.91], [116.46, 39.85], [116.36, 39.87]]
    }
  }]
}
</script>

<template>
  <div class="h-115 w-full overflow-hidden rounded-(--ui-radius) border border-default">
    <MapboxMap :options="{ style: 'mapbox://styles/mapbox/dark-v11', center: [116.41, 39.90], zoom: 11 }">
      <MapboxTrail :data="data" :color="color" />
    </MapboxMap>
  </div>
</template>
```

## API

### Props

```ts
/**
 * Props for the MapboxTrail component
 */
interface MapboxTrailProps {
  /**
   * 线要素数据（GeoJSON 或其 URL）
   */
  data: string | GeoJSON.GeoJSON<GeoJSON.Geometry, GeoJSON.GeoJsonProperties> | undefined;
  /**
   * 图层 id 前缀；省略时自动生成
   */
  layerId?: string | undefined;
  /**
   * 主色
   * @default "\"#8b5cf6\""
   */
  color?: string | undefined;
  /**
   * 线宽（像素）
   * @default "4"
   */
  lineWidth?: number | undefined;
  /**
   * 彗尾长度（line-progress 占比 0-1）
   * @default "0.25"
   */
  trailLength?: number | undefined;
  /**
   * 跑完全程的周期（毫秒）
   * @default "3000"
   */
  duration?: number | undefined;
  /**
   * 是否同时绘制半透明底线
   * @default "true"
   */
  baseLine?: boolean | undefined;
  /**
   * 插入到该图层之前
   */
  beforeId?: string | undefined;
}
```

## Changelog

See commit history for [src/runtime/components/effects/Trail.vue](https://github.com/mhaibaraai/movk-mapbox/commits/main/src/runtime/components/effects/Trail.vue).


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
