Skip to content

TrailLayer

Example

Example Source Code
vue
<template>
  <div class="map-container">
    <mb-map :zoom="8" :pitch="40">
      <mb-path-layer
        :data="pathData"
        :get-path="getPath"
        :get-width="100"
        :get-color="[128, 128, 93, 0.2]"
        :width-min-pixels="1"
        :opacity="0.3"
      />
      <mb-trail-layer
        :data="pathData"
        :get-path="getPath"
        :get-color="getColor"
        :get-width="100"
        :speed="3"
        :trail-length="3"
        :interval="5"
      />
    </mb-map>
  </div>
</template>

<script setup lang="ts">
const pathData = `${__RESOURCE_URL__}json/beijing-bus-lines.json`
const getPath = (data) => {
  let prevPt
  const points: number[][] = []
  for (let i = 0; i < data.length; i += 2) {
    let pt = [data[i], data[i + 1]]
    if (i > 0) {
      pt = [prevPt[0] + pt[0], prevPt[1] + pt[1]]
    }
    prevPt = pt

    points.push([pt[0] / 1e4, pt[1] / 1e4])
  }
  return points
}
const getColor = () => [Math.random() * 150 + 100, Math.random() * 100 + 28, 93]
</script>

API

PROPS

NameDescriptionTypeDefault
idLayer IDstring-
speedSpeed of movement/animation.number1
trail-lengthLength of the trail (e.g., in number of segments or time units).number10
intervalTime interval between updates/frames (e.g., in milliseconds).number5
dataSource data for the layer.string / IndexAny / AnyArr / Promise<any>''
showWhether the layer is visible.booleantrue
opacityThe opacity of the layer (0-1).number1
pickableWhether the layer responds to mouse events. If false, the component will not emit mouse-related events.booleanfalse
auto-highlightWhen true and pickable is also true, the hovered object will be highlighted.booleanfalse
highlight-colorThe color to blend with the original color of the highlighted object.string / number[][255, 255, 128, 1]
highlighted-object-indexThe index of the highlighted element.number-1
on-data-loadCallback function invoked after data loading is complete.AnyFunc-
data-transformFunction to transform the data before rendering.AnyFunc-
transitionsTransition settings for the layer.IndexAny{}
get-colorColor information.string / AnyFunc / number[]black
get-pathPath information.AnyFuncobject => object.path
get-widthWidth information.number / AnyNumberFunc100
miter-limitMiter limit (used when cap-rounded is false).number4
cap-roundedWhether the line caps are rounded.booleanfalse
joint-roundedWhether the line joints are rounded.booleanfalse
width-max-pixelsMaximum width in pixels.numberNumber.MAX_SAFE_INTEGER
width-min-pixelsMinimum width in pixels.number0
width-scaleScaling factor for the width.number1
width-unitsUnits for the width (pixels or meters).string ('pixels' / 'meters')'meters'

EVENTS

NameDescriptionParameters

SLOTS

NameDescription

METHODS

NameDescriptionDefinition