forked from zhouruizhe/gmTouringMiniApp
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import type { MapViewport } from '@/domain/poi'
|
|||
|
|
import { describe, expect, it } from 'vitest'
|
||
|
|
import { isSignificantViewportChange } from '@/services/map'
|
||
|
|
|
||
|
|
const current: MapViewport = { longitude: 113.935, latitude: 22.748, scale: 13 }
|
||
|
|
|
||
|
|
function shifted(delta: Partial<MapViewport>): MapViewport {
|
||
|
|
return {
|
||
|
|
longitude: current.longitude + (delta.longitude ?? 0),
|
||
|
|
latitude: current.latitude + (delta.latitude ?? 0),
|
||
|
|
scale: current.scale + (delta.scale ?? 0),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
describe('isSignificantViewportChange', () => {
|
||
|
|
it('丢弃地图回传中心点的量化噪声', () => {
|
||
|
|
expect(isSignificantViewportChange(current, shifted({}))).toBe(false)
|
||
|
|
expect(isSignificantViewportChange(current, shifted({ longitude: 1e-6 }))).toBe(false)
|
||
|
|
expect(isSignificantViewportChange(current, shifted({ latitude: -1e-6 }))).toBe(false)
|
||
|
|
expect(isSignificantViewportChange(current, shifted({ scale: 0.001 }))).toBe(false)
|
||
|
|
})
|
||
|
|
|
||
|
|
it('接受真实拖动与缩放', () => {
|
||
|
|
expect(isSignificantViewportChange(current, shifted({ longitude: 0.01 }))).toBe(true)
|
||
|
|
expect(isSignificantViewportChange(current, shifted({ latitude: -0.01 }))).toBe(true)
|
||
|
|
expect(isSignificantViewportChange(current, shifted({ scale: 1 }))).toBe(true)
|
||
|
|
})
|
||
|
|
|
||
|
|
it('单个维度超阈值就算变化', () => {
|
||
|
|
const next = shifted({ longitude: 1e-6, latitude: 1e-6, scale: 2 })
|
||
|
|
expect(isSignificantViewportChange(current, next)).toBe(true)
|
||
|
|
})
|
||
|
|
})
|