---
title: "MapboxTrail"
description: "Animated trail effect with a line-gradient comet tail looping along a line feature."
canonical_url: "https://mapbox.mhaibaraai.cn/en/docs/effects/trail"
---
# MapboxTrail

> Animated trail effect with a line-gradient comet tail looping along a line feature.

## Introduction

`MapboxTrail` renders an animated trail on line features: a `line-gradient` comet-tail window loops along the line (the source automatically enables `lineMetrics`); `color` / `lineWidth` / `trailLength` / `duration` / `baseLine` control the appearance and timing.

## Usage

Switch the primary color to preview the comet tail flowing along the line:

```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](https://mapbox.mhaibaraai.cn/sitemap.md) for all pages.
