【类 型】:test

【原  因】:测试集群 重心点 中心点 单元测试
【过  程】:
【影  响】:

# 类型 包含:
# feat:新功能(feature)
# fix:修补bug
# docs:文档(documentation)
# style: 格式(不影响代码运行的变动)
# refactor:重构(即不是新增功能,也不是修改bug的代码变动)
# test:增加测试
# chore:构建过程或辅助工具的变动
This commit is contained in:
air 2025-06-23 21:38:47 +08:00
parent 356ea21847
commit bcffe48c50
2 changed files with 90 additions and 0 deletions

View File

@ -1089,6 +1089,65 @@ export default {
this.map.resize()
}, 200)
}
},
drawTestPoints (positions, center) {
//
if (this.map.getSource('test-points')) this.map.removeSource('test-points')
if (this.map.getLayer('test-points')) this.map.removeLayer('test-points')
if (this.map.getSource('center-point')) this.map.removeSource('center-point')
if (this.map.getLayer('center-point')) this.map.removeLayer('center-point')
// GeoJSON
const features = positions.map(pos => ({
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [pos[0], pos[1]]
}
}))
this.map.addSource('test-points', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: features
}
})
this.map.addLayer({
id: 'test-points',
type: 'circle',
source: 'test-points',
paint: {
'circle-radius': 6,
'circle-color': '#3399ff' //
}
})
//
this.map.addSource('center-point', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [center.lon, center.lat]
}
}]
}
})
this.map.addLayer({
id: 'center-point',
type: 'circle',
source: 'center-point',
paint: {
'circle-radius': 8,
'circle-color': '#ff3333' //
}
})
}
},
beforeDestroy () {

View File

@ -68,6 +68,37 @@ export default {
}
},
mounted () {
setTimeout(() => {
//
const centerLng = 100.0000
const centerLat = 40.0000
// 10
const testPositions = Array.from({ length: 10 }, () => {
const offsetLng = centerLng + (Math.random() - 0.5) * 0.001 // ±0.0005
const offsetLat = centerLat + (Math.random() - 0.5) * 0.001
const alt = 100 + Math.floor(Math.random() * 100) // 100~200
return [offsetLng, offsetLat, alt]
})
//
const center = testPositions.reduce((acc, pos) => {
acc.lon += pos[0]
acc.lat += pos[1]
acc.alt += pos[2]
return acc
}, { lon: 0, lat: 0, alt: 0 })
const count = testPositions.length
const centerPoint = {
lon: center.lon / count,
lat: center.lat / count,
alt: center.alt / count
}
// mapbox
this.$refs.mapbox.drawTestPoints(testPositions, centerPoint)
}, 3000)
},
watch: {
/**