fix(ui): вписывать топологию в область карты

This commit is contained in:
Denozordec committed 2026-10-01 03:18:02 +07:00
1 parent 89e48c2424
commit bc83b8dbbf
13 files changed
+91 -88

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
export interface MapPoint {x:number;y:number}
export function fitNetworkMapCamera(points:readonly MapPoint[],width:number,height:number) {
const valid=points.filter(p=>Number.isFinite(p.x)&&Number.isFinite(p.y))
if(!valid.length||width<=0||height<=0)return {pan:{x:0,y:0},zoom:1}
const xs=valid.map(p=>p.x),ys=valid.map(p=>p.y),left=Math.min(...xs)-120,right=Math.max(...xs)+120,top=Math.min(...ys)-100,bottom=Math.max(...ys)+100
const zoom=Math.max(.2,Math.min(3,width/(right-left),height/(bottom-top)))
return {pan:{x:(left+right)/2-width/(2*zoom),y:(top+bottom)/2-height/(2*zoom)},zoom}
}