import test from 'node:test' import assert from 'node:assert/strict' import { mergeMapPoints } from '../src/utils/gisMapClustering.js' function projectPoint({ lng, lat }) { return { x: lng * 100, y: lat * 100 } } test('mergeMapPoints keeps distant points as individual markers', () => { const points = [ { id: 'a', lng: 110.3, lat: 28.4 }, { id: 'b', lng: 111, lat: 29 } ] const merged = mergeMapPoints(points, projectPoint, 48) assert.equal(merged.length, 2) assert.deepEqual(merged.map(item => item.type), ['point', 'point']) assert.deepEqual(merged.map(item => item.point.id), ['a', 'b']) }) test('mergeMapPoints combines nearby points into one countable cluster', () => { const points = [ { id: 'a', lng: 110.3, lat: 28.4, iconUrl: 'green.png' }, { id: 'b', lng: 110.3005, lat: 28.4004, iconUrl: 'red.png' } ] const merged = mergeMapPoints(points, projectPoint, 48) assert.equal(merged.length, 1) assert.equal(merged[0].type, 'cluster') assert.equal(merged[0].count, 2) assert.deepEqual(merged[0].points.map(point => point.id), ['a', 'b']) }) test('mergeMapPoints keeps the average render position for a cluster', () => { const merged = mergeMapPoints([ { id: 'a', lng: 110.3, lat: 28.4 }, { id: 'b', lng: 110.301, lat: 28.402 } ], projectPoint, 48) assert.equal(merged[0].position.lng, 110.3005) assert.equal(merged[0].position.lat, 28.401) }) test('mergeMapPoints ignores invalid coordinates', () => { const merged = mergeMapPoints([ { id: 'valid', lng: 110.3, lat: 28.4 }, { id: 'bad-lng', lng: Number.NaN, lat: 28.4 }, { id: 'bad-lat', lng: 110.3, lat: Number.NaN } ], projectPoint, 48) assert.equal(merged.length, 1) assert.equal(merged[0].type, 'point') assert.equal(merged[0].point.id, 'valid') })