MapboxTrail

View source
动态轨迹,line-gradient 彗尾沿线循环平移。

简介

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

用法

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

<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.3, 39.9],
          [116.4, 39.94],
          [116.5, 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.9], zoom: 11 }"
    >
      <MapboxTrail :data="data" :color="color" />
    </MapboxMap>
  </div>
</template>

API

Props

Prop Default Type
datastring | GeoJSON.Point | GeoJSON.MultiPoint | GeoJSON.LineString | GeoJSON.MultiLineString | GeoJSON.Polygon | GeoJSON.MultiPolygon | GeoJSON.GeometryCollection<GeoJSON.Geometry> | GeoJSON.Feature<GeoJSON.Geometry, { [name: string]: any; }> | GeoJSON.FeatureCollection<GeoJSON.Geometry, { [name: string]: any; }>

线要素数据(GeoJSON 或其 URL)

layerIdstring

图层 id 前缀;省略时自动生成

color'#8b5cf6'string

主色

lineWidth4number

线宽(像素)

trailLength0.25number

彗尾长度(line-progress 占比 0-1)

duration3000number

跑完全程的周期(毫秒)

beforeIdstring

插入到该图层之前

baseLinetrueboolean

是否同时绘制半透明底线

Changelog

No recent changes
Copyright © 2026 - 2026 YiXuan - MIT License