轨迹线路图层(TripsLayer)
示例
示例源码
vue
<template>
<div style="height: 400px">
<mb-map :zoom="10" :pitch="40" :center="[-73.9, 40.7]">
<mb-trips-layer
:data="__RESOURCE_URL__ + 'json/trips.json'"
:get-path="(d) => d.path"
:get-timestamps="(d) => d.timestamps"
:trail-length="200"
:current-time="currentTime"
/>
</mb-map>
</div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
const currentTime = ref(0)
const loop = 1900
const animate = (timestamp: number) => {
currentTime.value = (timestamp / 10) % loop
requestAnimationFrame(animate)
}
onMounted(() => {
animate(0)
})
</script>API
PROPS
| 名称 | 描述 | 类型 | 默认值 |
|---|---|---|---|
| id | 图层Id | string | - |
| auto-highlight | 本属性为true且pickable为true时,则会将鼠标悬浮选中的对象设为高亮 | boolean | false |
| current-time | 当前时间 | number | 0 |
| data | 图层源数据 | string / IndexAny / AnyArr / Promise<any> | '' |
| get-color | 颜色信息 | string / AnyFunc / number[] | black |
| get-timestamps | 时间片信息 | AnyFunc | - |
| get-path | 路径信息 | AnyFunc | object => object.path |
| get-width | 宽度信息 | number / AnyNumberFunc | 100 |
| highlight-color | 要与高亮对象原始颜色进行混合(blend)的颜色值 | string / number[] | [255, 255, 128, 1] |
| highlighted-object-index | 高亮元素序号 | number | -1 |
| miter-limit | rounded为false时生效 | number | 4 |
| cap-rounded | - | boolean | false |
| joint-rounded | - | boolean | false |
| opacity | 透明度 | number | 1 |
| pickable | 图层是否会响应鼠标事件,若为false,则组件不会emit鼠标相关事件 | boolean | false |
| show | 是否显示 | boolean | true |
| trail-length | - | number | 120 |
| width-max-pixels | - | number | Number.MAX_SAFE_INTEGER |
| width-min-pixels | - | number | 0 |
| width-scale | - | number | 1 |
| width-units | - | string(pixels / meters) | meters |
EVENTS
| 名称 | 描述 | 参数 |
|---|---|---|
| created | 初始化完成事件 | - |
| mousemove | - | { object: any; coordinates: mapboxgl.LngLat; pixel: [number, number] } |
| mouseleave | - | - |
| click | - | { object: any; coordinates: mapboxgl.LngLat; pixel: [number, number] } |
SLOTS
| 名称 | 描述 |
|---|
METHODS
| 名称 | 描述 | 定义 |
|---|
