Leaflet地图数据迁徙 + 飞线效果
效果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d331b45f3088f5bfc5f42f25e9210c68.gif)
代码
export function classifyPointData(arr, color = "rgb(101, 169, 249)", centerName, centerNameProp, value = 6) {
const { jd: centerJD, wd: centerWD } = arr.find((i) => i[centerNameProp] === centerName);
return arr.filter((i) => i.name !== centerName).map(({ jd, wd }) => ({
color,
from: [centerJD, centerWD],
to: [jd, wd],
value,
}));
}
migrationOptions = {
marker: {
radius: [5, 10],
pulse: false,
textVisible: false
},
line: {
width: 1,
order: false,
icon: {
type: 'arrow',
imgUrl: '',
size: 10
},
},
}
initPoint() {
this.markerLayer && this.map.removeLayer(this.markerLayer);
const migrationData = classifyPointData(this.pointList, "rgb(101, 169, 249)", "分指挥部", "name");
this.migrationGymLayer = L.migrationLayer(migrationData, migrationOptions);
this.migrationGymLayer.addTo(this.map);
let markericon = []
this.pointList.forEach(item => {
const myIcon = L.divIcon({
html: `<div class="marker-box flex flex-col items-center">
<div class="board-box flex flex-col items-center">
<div class="board">
${ item.name }
${ item.distance ? `<div>距离分指挥部:${ item.distance }</div>` : '' }
<div class="logo">
<img src="${ pointLogo }"/>
</div>
</div>
<img class="line" src="${ pointLine }"/>
</div>
${JSON.parse(item.image).length ? `<img src="${ '/sys/sysFile/download?fileId=' + JSON.parse(item?.image)[0]?.id }"/>` : ''}
<div class="circle-box">
<div class="circle1"></div>
<div class="circle2" style="animation-delay: 0.5s;"></div>
<div class="circle3" style="animation-delay: 1.5s;></div>
</div>
</div>
`,
});
const m = L.marker([item.wd, item.jd], { icon: myIcon });
markericon.push(m);
})
this.markerLayer = L.layerGroup(markericon);
this.map.addLayer(this.markerLayer);
},