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

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

## Introduction

`MaplibreTrail` 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">
    <MaplibreMap :options="{ style: 'https://tiles.openfreemap.org/styles/dark', center: [116.41, 39.90], zoom: 11 }">
      <MaplibreTrail :data="data" :color="color" />
    </MaplibreMap>
  </div>
</template>
```

## API

### Props

```ts
/**
 * Props for the MaplibreTrail component
 */
interface MaplibreTrailProps {
  /**
   * 线要素数据（GeoJSON 或其 URL）
   */
  data: string | GeoJSON.Point | GeoJSON.MultiPoint | GeoJSON.LineString | GeoJSON.MultiLineString | GeoJSON.Polygon | GeoJSON.MultiPolygon | GeoJSON.GeometryCollection<GeoJSON.Geometry> | GeoJSON.Feature<GeoJSON.Geometry, GeoJSON.GeoJsonProperties> | GeoJSON.FeatureCollection<GeoJSON.Geometry, GeoJSON.GeoJsonProperties>;
  /**
   * 图层 id 前缀；省略时自动生成，变更需配合 `:key` 重建
   */
  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-maplibre/commits/main/src/runtime/components/effects/Trail.vue).


## Sitemap

See the full [sitemap](https://maplibre.mhaibaraai.cn/sitemap.md) for all pages.
