feat(map): add province city district vehicle drilldown

This commit is contained in:
lingniu
2026-08-03 22:03:38 +08:00
parent dc5f88cf16
commit b6f1e89e4f
5 changed files with 256 additions and 91 deletions
+33 -9
View File
@@ -20,22 +20,46 @@ const areaNode = {
];
}
};
vehicleProvinceSummary = aggregateVehicleProvinces(areaNode);
const summary = buildVehicleProvinceNodes();
assert.equal(summary.nodes.length, 2);
assert.equal(summary.unassigned, 2);
const guangdong = summary.nodes.find(node => node.nameZh === '广东');
const partition = partitionVehiclesByArea(areaNode, locatedVehicles(), 'province');
assert.equal(partition.groups.length, 2);
assert.equal(partition.unmatched.length, 0);
const provinceNodes = regionNodesFromGroups(partition.groups, 'province');
assert.equal(provinceNodes.length, 2);
const guangdong = provinceNodes.find(node => node.nameZh === '广东');
assert.equal(guangdong.count, 1);
assert.equal(guangdong.online, 1);
assert.equal(guangdong.dist, 10);
assert.equal(hierarchyLevelForZoom(4.8), 'province');
assert.equal(hierarchyLevelForZoom(7), 'city');
assert.equal(hierarchyLevelForZoom(9.5), 'district');
assert.equal(hierarchyLevelForZoom(12), 'vehicle');
vehicleRegionSummary = { level: 'province', nodes: provinceNodes, unassigned: 2, loading: false };
map = { getZoom: () => 4.8 };
assert.equal(vehicleNodes().length, 2);
assert.ok(vehicleNodes().every(node => node.kind === 'vehicleProvince'));
map = { getZoom: () => 8 };
assert.ok(vehicleNodes().every(node => node.kind === 'vehicleCluster'));
assert.equal(vehicleNodes().reduce((sum, node) => sum + node.count, 0), 2);
const cityPartition = partitionVehiclesByArea({
groupByPosition(points) {
return [{ subFeatureIndex: 0, subFeature: { properties: { adcode: '440100', name: '广州市', center: [113.3, 23.1] } }, points }];
}
}, [dashboard.vehicles[0]], 'city');
const cityNodes = regionNodesFromGroups(cityPartition.groups, 'city');
assert.equal(cityNodes[0].kind, 'vehicleCity');
assert.equal(cityNodes[0].nameZh, '广州');
map = {
getZoom: () => 12,
getBounds: () => ({
getSouthWest: () => ({ getLng: () => 100, getLat: () => 20 }),
getNorthEast: () => ({ getLng: () => 125, getLat: () => 35 })
})
};
const points = vehiclePointNodes();
assert.equal(points.length, 2);
assert.ok(points.every(node => node.kind === 'vehiclePoint'));
assert.equal(points.find(node => node.nameZh === '粤A00001').online, 1);
`;
const sandbox = {
@@ -47,4 +71,4 @@ const sandbox = {
clearInterval() {}
};
vm.runInNewContext(`${source}\n${checks}`, sandbox, { filename: 'app.js' });
console.log('vehicle province aggregation tests: ok');
console.log('vehicle hierarchy aggregation tests: ok');