烟火(SparkLayer)
示例
示例源码
vue
<template>
<div class="map-container">
<mb-map
:zoom="14"
:center="[116.17381, 39.92155464]"
:pitch="60"
background-color="black"
>
<mb-gradient-building-layer
:data="__RESOURCE_URL__ + 'json/building.geojson'"
:data-transform="(d) => d.features"
:get-polygon="(d) => d.geometry.coordinates[0]"
:get-elevation="(d) => d.properties.Floor * 60"
/>
<mb-spark-layer
:data="sparkData"
:get-position="(d) => d.coordinates"
:get-height="(d) => d.properties.height"
:get-color="(d) => d.properties.color"
:trail-length="100"
:speed="5"
/>
</mb-map>
</div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
const sparkData = ref<
Array<{ coordinates: number[]; properties: Record<string, any> }>
>([])
onMounted(() => {
for (let i = 0; i < 100; i++) {
sparkData.value.push({
coordinates: [
116.168 + Math.random() * 0.014,
39.917 + Math.random() * 0.007,
],
properties: {
height: 400 + Math.random() * 500,
color: [255, 100 + Math.random() * 150, 100 + Math.random() * 150],
},
})
}
})
</script>
API
PROPS
名称 | 描述 | 类型 | 默认值 |
---|---|---|---|
id | 图层Id | string | - |
get-position | - | AnyFunc | - |
get-height | - | number / AnyNumberFunc | 1000 |
trail-length | - | number | 100 |
speed | - | number | 10 |
get-Color | - | string / AnyFunc | black |
data | 图层源数据 | string / IndexAny / AnyArr / Promise<any> | '' |
show | 是否显示 | boolean | true |
opacity | 透明度 | number | 1 |
pickable | 图层是否会响应鼠标事件,若为false,则组件不会emit鼠标相关事件 | boolean | false |
auto-highlight | 本属性为true且pickable为true时,则会将鼠标悬浮选中的对象设为高亮 | boolean | false |
highlight-color | 要与高亮对象原始颜色进行混合(blend)的颜色值 | string / number[] | [255, 255, 128, 1] |
highlighted-object-index | 高亮元素序号 | number | -1 |
on-data-load | - | AnyFunc | - |
data-transform | - | AnyFunc | - |
transitions | - | IndexAny | {} |
EVENTS
名称 | 描述 | 参数 |
---|
SLOTS
名称 | 描述 |
---|
METHODS
名称 | 描述 | 定义 |
---|