gis-view-webgl2 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +17 -14
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.d.ts +252 -37
  4. package/dist/index.js +1 -1
  5. package/docs/AI/345/257/271/350/257/235/346/261/207/346/200/273.md +79 -0
  6. package/docs/GisView.md +53 -53
  7. package/docs/ai/06-/344/274/232/350/257/235/347/264/242/345/274/225/344/270/216/345/244/215/346/237/245/346/226/271/346/263/225.md +66 -0
  8. package/docs/api/index.html +22 -8
  9. package/docs/demos/ApiCoverageDemo.vue +1 -1
  10. package/docs/demos/ConnectDemo.vue +114 -3
  11. package/docs/demos/ExtensionDemo.vue +69 -12
  12. package/docs/demos/MinimapDemo.vue +62 -16
  13. package/docs/demos/SearchFilterDemo.vue +13 -11
  14. package/docs/demos/api-index.js +26 -21
  15. package/docs/demos/demos.js +1 -1
  16. package/docs/demos/gis-view-demo/GisViewDemoCardHeader.vue +1 -0
  17. package/docs/demos/gis-view-demo/GisViewDemoStage.vue +25 -16
  18. package/docs/demos/gis-view-demo/panels/OpsPanels.vue +2 -2
  19. package/docs/demos/gis-view-demo/useGisViewDemo.js +36 -25
  20. package/docs/index.html +41 -4
  21. package/docs/internals/13-/351/271/260/347/234/274/345/233/276.md +6 -5
  22. package/docs/internals/16-01-/344/274/230/345/214/226/344/270/216/345/217/226/350/210/215-/344/270/212.md +5 -3
  23. package/docs/internals/18-/346/200/247/350/203/275/345/256/236/346/265/213/344/270/216WebGPU/350/257/204/344/274/260.md +12 -0
  24. package/docs/manual/03-/351/205/215/347/275/256/351/241/271.md +29 -6
  25. package/docs/manual/04-/344/272/213/344/273/266/344/270/216/345/233/236/350/260/203.md +7 -6
  26. package/docs/manual/08-/351/200/211/344/270/255/344/270/216/346/213/220/347/202/271.md +24 -3
  27. package/docs/manual/09-/351/200/232/351/201/223/344/270/216/345/244/232/345/233/236/347/272/277.md +1 -1
  28. package/docs/manual/10-/351/200/232/351/201/223/347/274/226/350/276/221/344/270/216/346/226/260/345/242/236.md +423 -3
  29. package/docs/manual/14-/350/247/206/345/233/276/344/270/216/347/255/233/351/200/211.md +169 -62
  30. package/docs/manual/15-/345/257/274/345/207/272/344/270/216/351/233/206/346/210/220.md +32 -3
  31. package/docs/manual/16-/345/256/236/344/276/213/346/226/271/346/263/225/346/200/273/350/241/250.md +12 -8
  32. package/docs/manual/17-/345/217/202/346/225/260/351/200/237/346/237/245.md +13 -9
  33. package/docs/manual/18-/351/200/220/346/226/271/346/263/225/347/244/272/344/276/213.md +156 -12
  34. package/docs/manual/19-/350/257/273/346/225/260/344/270/216/346/213/226/346/213/275/351/242/204/350/247/210.md +3 -3
  35. package/docs/manual/21-/350/257/264/346/230/216/344/270/216/345/270/270/350/247/201/351/227/256/351/242/230.md +11 -5
  36. package/docs/steps/README.md +8 -8
  37. package/docs/steps/selftest-demos.html +173 -12
  38. package/docs/steps/selftest-docs.html +33 -4
  39. package/docs/steps/selftest-features.html +91 -10
  40. package/docs/steps/selftest-full.html +315 -12
  41. package/docs/steps/selftest-perf.html +39 -1
  42. package/docs/steps/selftest-scale.html +98 -0
  43. package/docs/steps/selftest-select.html +90 -0
  44. package/package.json +1 -1
@@ -1765,9 +1765,59 @@
1765
1765
  faView.selectFeatures('fa-around')
1766
1766
  const faWaypointCleared = faView.getWaypoints().filter(item => item.lineIndex === 5).every(item => !item.selected)
1767
1767
  check('selectWaypoint:按线路 + 下标选中拐点并带选线路,selectFeatures 会清掉拐点选中', faWaypointSelected && faWaypointLineSelected && faWaypointCleared, JSON.stringify({ selected: faWaypointSelected, line: faWaypointLineSelected, cleared: faWaypointCleared, all: faView.getWaypoints(), lines: faView.getData().lines }))
1768
+ // search 也认 focusOn 的四种目标;分组命中可以直接交给 focusOn / selectFeatures
1769
+ const faGroupSearch = faView.search({ keyword: 'fa-high', scope: 'group', limit: 10 })
1770
+ const faGroupHit = faGroupSearch.groups[0]
1771
+ faView.focusOn(faGroupHit)
1772
+ const faGroupSearchCenter = faView.getCamera().center
1773
+ faView.selectFeatures(faGroupHit)
1774
+ const faGroupHitSelected = faView.getSelections().filter(item => item.type === 'line').map(item => item.item.id).sort()
1775
+ const faDefaultGroupSearch = await faView.searchAsync({ keyword: 'fa-high', limit: 10 })
1776
+ check('search:单数 group 范围返回分组命中,命中可直接 focusOn / selectFeatures', faGroupSearch.scope.length === 1 && faGroupSearch.scope[0] === 'groups' && faGroupHit?.kind === 'group' && faGroupHit.channelIndex === 1 && faGroupHit.groupId === 'fa-high' && faGroupHit.groupIndex === 0 && Math.abs(faGroupSearchCenter[1] - 40) < 0.01 && faGroupHitSelected.join(',') === 'fa-l3,fa-l4', JSON.stringify({ scope: faGroupSearch.scope, hit: faGroupHit, center: faGroupSearchCenter, selected: faGroupHitSelected }))
1777
+ check('searchAsync:缺省范围包含 groups,Worker / 同步回落都带 groups 结果', faDefaultGroupSearch.groups.length === 1 && faDefaultGroupSearch.hits.some(hit => hit.kind === 'group' && hit.groupId === 'fa-high'), JSON.stringify({ scope: faDefaultGroupSearch.scope, groups: faDefaultGroupSearch.groups.length, worker: faDefaultGroupSearch.worker }))
1778
+ // 线路 / 通道 / 分组都只在 zoom: true 时适配:与显式 zoomToBounds 的比例逐位一致,没有类型专属放大倍率
1779
+ const faLineHit = faView.search({ keyword: 'fa-around', scope: 'line', limit: 1 }).lines[0]
1780
+ const faChannelHit = faView.search({ keyword: 'fa-low-ch', scope: 'channel', limit: 1 }).channels[0]
1781
+ const faFocusScales = [faLineHit, faChannelHit, faGroupHit].map((hit) => {
1782
+ faView.zoomToBounds(hit.bounds)
1783
+ const expected = faView.getCamera().scale
1784
+ faView.focusOn(hit, { zoom: true })
1785
+ return [expected, faView.getCamera().scale]
1786
+ })
1787
+ check('focusOn({ zoom: true }):线路 / 通道 / 分组适配后的比例与同一份 bounds 的 zoomToBounds 完全一致', faFocusScales.every(([expected, actual]) => Math.abs(expected - actual) < 1e-9), JSON.stringify(faFocusScales))
1768
1788
  faView.destroy()
1769
1789
  faHost.remove()
1770
1790
 
1791
+ /* 筛选是隐藏、不是删除:选中的要素被筛掉时保留在选中集里,条件清空后原样恢复 */
1792
+ const fsHost = document.createElement('div')
1793
+ fsHost.style.cssText = 'width:320px;height:200px'
1794
+ document.body.appendChild(fsHost)
1795
+ const fsChanges = []
1796
+ const fsView = createGisView(fsHost, {
1797
+ points: [
1798
+ { id: 'fs-a', x: -30, y: 0, level: 0 },
1799
+ { id: 'fs-b', x: 30, y: 0, level: 1 }
1800
+ ],
1801
+ lines: [{ id: 'fs-l1', from: 'fs-a', to: 'fs-b' }],
1802
+ initialView: { center: [0, 0], scale: 1 },
1803
+ showGrid: false,
1804
+ onSelectChange: payload => fsChanges.push(payload)
1805
+ })
1806
+ await settle(100)
1807
+ fsView.selectFeatures(['fs-a', 'fs-l1'])
1808
+ const fsChangesBeforeFilter = fsChanges.length
1809
+ fsView.setFilter({ points: { level: 1 }, cascade: false })
1810
+ await settle(100)
1811
+ const fsHiddenIds = fsView.getSelections().map(item => String(item.item.id)).sort().join(',')
1812
+ const fsHiddenVisible = fsView.getVisibleData().points.some(point => point.id === 'fs-a')
1813
+ const fsChangesAfterFilter = fsChanges.length
1814
+ fsView.setFilter(null)
1815
+ await settle(100)
1816
+ const fsRestoredIds = fsView.getSelections().map(item => String(item.item.id)).sort().join(',')
1817
+ check('setFilter 只隐藏要素:选中项保留,条件清空后仍选中且不额外发选中变更', fsHiddenIds === 'fs-a,fs-l1' && fsHiddenVisible === false && fsChangesAfterFilter === fsChangesBeforeFilter && fsRestoredIds === 'fs-a,fs-l1', JSON.stringify({ hidden: fsHiddenIds, visible: fsHiddenVisible, changes: [fsChangesBeforeFilter, fsChangesAfterFilter], restored: fsRestoredIds }))
1818
+ fsView.destroy()
1819
+ fsHost.remove()
1820
+
1771
1821
  /* lineFollowsNode: false:隐藏 / 筛选 / 删除只动节点,回线与通道停在最后坐标 */
1772
1822
  const lfHost = document.createElement('div')
1773
1823
  lfHost.style.cssText = 'width:360px;height:220px'
@@ -3405,13 +3455,13 @@
3405
3455
  showGrid: false
3406
3456
  })
3407
3457
  await settle(160)
3408
- fitView.focusOn('fl1', { padding: 220 })
3458
+ fitView.focusOn('fl1', { zoom: true, padding: 220 })
3409
3459
  await settle(80)
3410
3460
  const fitStart = fitView.project(0, 0)
3411
3461
  const fitEnd = fitView.project(300, 200)
3412
3462
  const fitSpan = Math.hypot(fitStart[0] - fitEnd[0], fitStart[1] - fitEnd[1])
3413
3463
  check('适应视图的留白比画布还大时:内容不会被挤成一个点(至少留给它 48px)', fitSpan > 40, `跨度 ${fitSpan.toFixed(1)}px / 画布 ${fitView.getStats().cssWidth}×${fitView.getStats().cssHeight}`)
3414
- fitView.focusOn('fl1', { padding: 20 })
3464
+ fitView.focusOn('fl1', { zoom: true, padding: 20 })
3415
3465
  await settle(80)
3416
3466
  const fitPadStart = fitView.project(0, 0)
3417
3467
  const fitPadEnd = fitView.project(300, 200)
@@ -3921,13 +3971,17 @@
3921
3971
  apiSend('pointerup', [apiRight, apiBottom], { button: 0, buttons: 0, shiftKey: true })
3922
3972
  await settle()
3923
3973
  check('框选的结果用同一份读数读回来(Shift + 拖动)', apiIds() === 'api-a,api-b,api-c' && apiView.getSelectionData().count === 3, apiIds())
3924
- // focusOn 一批目标:数组取整体包围盒 —— 这三个点的中心(200, 20)当屏幕中心、按这一批的范围适配
3974
+ // focusOn 一批目标:缺省只居中;显式 zoom: true 才按整体包围盒适配
3975
+ const apiDefaultScale = apiView.getCamera().scale
3925
3976
  apiView.focusOn(['api-a', 'api-b', 'api-c'])
3977
+ const apiCenteredBatch = apiView.getCamera()
3978
+ check('focusOn(一批目标):缺省只把中心挪到 (200, 20),比例一点不动', Math.abs(apiCenteredBatch.center[0] - 200) < 1e-6 && Math.abs(apiCenteredBatch.center[1] - 20) < 1e-6 && apiCenteredBatch.scale === apiDefaultScale, JSON.stringify({ scale: [apiDefaultScale, apiCenteredBatch.scale], center: apiCenteredBatch.center }))
3979
+ apiView.focusOn(['api-a', 'api-b', 'api-c'], { zoom: true })
3926
3980
  const apiBatch = apiView.getCamera()
3927
3981
  const apiStats = apiView.getStats()
3928
3982
  const apiCorners = [[0, 0], [400, 40]].map(spot => apiView.project(spot[0], spot[1]))
3929
3983
  const apiInside = apiCorners.every(spot => spot[0] >= 0 && spot[0] <= apiStats.cssWidth && spot[1] >= 0 && spot[1] <= apiStats.cssHeight)
3930
- check('focusOn(一批目标):整体包围盒居中(三个点的中心当屏幕中心,三个点都在视口里)', Math.abs(apiBatch.center[0] - 200) < 1e-6 && Math.abs(apiBatch.center[1] - 20) < 1e-6 && apiBatch.scale > 0 && apiInside, JSON.stringify({ center: apiBatch.center, corners: apiCorners }))
3984
+ check('focusOn(一批目标, { zoom: true }):整体包围盒居中,三个点都在视口里', Math.abs(apiBatch.center[0] - 200) < 1e-6 && Math.abs(apiBatch.center[1] - 20) < 1e-6 && apiBatch.scale > 0 && apiInside, JSON.stringify({ center: apiBatch.center, corners: apiCorners }))
3931
3985
  // center: true 是原来 centerOn 的语义:只挪中心,比例一点不动
3932
3986
  apiView.focusOn(['api-a', 'api-b'], { center: true })
3933
3987
  const apiCenter1 = apiView.getCamera()
@@ -3938,9 +3992,11 @@
3938
3992
  apiView.focusOn('api-b', { center: true })
3939
3993
  const apiCenter3 = apiView.getCamera().center
3940
3994
  check('focusOn(id, { center: true }):中心挪到这个要素上', Math.abs(apiCenter3[0] - 200) < 1e-6 && Math.abs(apiCenter3[1] - 40) < 1e-6, JSON.stringify(apiCenter3))
3941
- apiView.focusOn({ type: 'channel', channelId: 'api-ch' }, { center: true })
3942
- const apiCenter4 = apiView.getCamera().center
3943
- check('focusOn(通道写法, { center: true }):取这条通道范围的中心', Math.abs(apiCenter4[0] - 100) < 5 && Math.abs(apiCenter4[1] - 20) < 5, JSON.stringify(apiCenter4))
3995
+ const apiChannelScale = apiView.getCamera().scale
3996
+ apiView.focusOn({ type: 'channel', channelId: 'api-ch' })
3997
+ const apiChannelCamera = apiView.getCamera()
3998
+ const apiCenter4 = apiChannelCamera.center
3999
+ check('focusOn(通道写法) 缺省只居中,线路 / 通道不再自动放大', Math.abs(apiCenter4[0] - 100) < 5 && Math.abs(apiCenter4[1] - 20) < 5 && apiChannelCamera.scale === apiChannelScale, JSON.stringify({ center: apiCenter4, scale: [apiChannelScale, apiChannelCamera.scale] }))
3944
4000
  apiView.focusOn('没有这个 id', { center: true })
3945
4001
  const apiCenter5 = apiView.getCamera().center
3946
4002
  check('focusOn:认不出来的目标什么都不做(视角停在原处)', apiCenter5[0] === apiCenter4[0] && apiCenter5[1] === apiCenter4[1], JSON.stringify(apiCenter5))
@@ -3949,16 +4005,41 @@
3949
4005
  check('focusOn(一段范围, { center: true }):取中心', Math.abs(apiCenter6[0] - 200) < 1e-6 && Math.abs(apiCenter6[1] - 20) < 1e-6, JSON.stringify(apiCenter6))
3950
4006
  // select: true:被聚焦的要素同时变成选中状态(与接口选中同一份 state);mode 决定怎么并进当前选中集
3951
4007
  const apiBeforeFocusSelect = apiView.getSelectionData().ids.join(',')
3952
- apiView.focusOn(['api-a', 'api-b', 'api-c'], { select: true, padding: 20 })
4008
+ apiView.focusOn(['api-a', 'api-b', 'api-c'], { select: true, zoom: true, padding: 20 })
3953
4009
  check('focusOn(一批, { select: true }):被聚焦的这一批同时选中(整份选中集换成这三个)', apiView.getSelectionData().ids.join(',') === 'api-a,api-b,api-c' && apiBeforeFocusSelect === 'api-a,api-b,api-c' && apiView.getSelectionData().count === 3, `${apiBeforeFocusSelect} -> ${apiView.getSelectionData().ids.join(',')}`)
3954
4010
  apiView.focusOn('api-a', { select: true, mode: 'remove' })
3955
4011
  check("focusOn(..., { select: true, mode: 'remove' }):只把聚焦的这个从选中集里去掉", apiView.getSelectionData().ids.join(',') === 'api-b,api-c', apiView.getSelectionData().ids.join(','))
3956
4012
  apiView.selectFeatures(null)
3957
4013
  const apiAreaScale = apiView.getCamera().scale
3958
- apiView.focusOn('api-b', { maxZoom: 12 })
4014
+ apiView.focusOn('api-b', { zoom: true, maxZoom: 12 })
3959
4015
  const apiZoomCamera = apiView.getCamera()
3960
- check('focusOn(单个节点, { maxZoom }):零面积目标撑出最小范围,放大并居中', apiZoomCamera.scale > apiAreaScale && Math.abs(apiZoomCamera.center[0] - 200) < 1e-6 && Math.abs(apiZoomCamera.center[1] - 40) < 1e-6, JSON.stringify({ scale: apiZoomCamera.scale, center: apiZoomCamera.center }))
4016
+ check('focusOn(单个节点, { zoom: true, maxZoom }):零面积目标撑出最小范围,放大并居中', apiZoomCamera.scale > apiAreaScale && Math.abs(apiZoomCamera.center[0] - 200) < 1e-6 && Math.abs(apiZoomCamera.center[1] - 40) < 1e-6, JSON.stringify({ scale: apiZoomCamera.scale, center: apiZoomCamera.center }))
4017
+ // 实例命令:注册 / 执行 / 同名覆盖 / 幂等卸载;名字与 handler 非法时只提醒、不动注册表
4018
+ let commandPayload = null
4019
+ let commandContext = null
4020
+ const disposeEcho = apiView.registerCommand(' demo:echo ', (payload, context) => {
4021
+ commandPayload = payload
4022
+ commandContext = context
4023
+ return { doubled: Number(payload?.value ?? 0) * 2 }
4024
+ })
4025
+ const echoResult = apiView.executeCommand('demo:echo', { value: 21 })
4026
+ check('registerCommand / executeCommand:名字规范化、payload 与冻结上下文可用,handler 的返回值原样带回', apiView.listCommands().join(',') === 'demo:echo' && echoResult.ok === true && echoResult.name === 'demo:echo' && echoResult.value?.doubled === 42 && commandPayload?.value === 21 && commandContext?.view === apiView && commandContext?.name === 'demo:echo' && Object.isFrozen(commandContext), JSON.stringify({ commands: apiView.listCommands(), result: echoResult, context: commandContext?.name }))
4027
+ const disposeReplacement = apiView.registerCommand('demo:echo', payload => `replacement:${payload}`)
4028
+ disposeEcho()
4029
+ const replacementResult = apiView.executeCommand('demo:echo', 'still-here')
4030
+ check('registerCommand:同名后注册覆盖先生效,旧卸载函数不会误删新命令', apiView.listCommands().join(',') === 'demo:echo' && replacementResult.ok === true && replacementResult.value === 'replacement:still-here', JSON.stringify({ commands: apiView.listCommands(), result: replacementResult }))
4031
+ disposeReplacement()
4032
+ const invalidDispose = apiView.registerCommand(' ', () => 'never')
4033
+ const invalidResult = apiView.executeCommand('', {})
4034
+ const missingResult = apiView.executeCommand('demo:missing', {})
4035
+ check('实例命令:非法名 / 未注册 / 空名字都返回 ok: false,注册表不受影响', typeof invalidDispose === 'function' && invalidResult.ok === false && missingResult.ok === false && apiView.listCommands().length === 0, JSON.stringify({ invalid: invalidResult, missing: missingResult, commands: apiView.listCommands() }))
4036
+ apiView.registerCommand('demo:throw', () => { throw new Error('命令执行失败') })
4037
+ const thrownResult = apiView.executeCommand('demo:throw', null)
4038
+ check('实例命令:handler 抛错收成 ok: false + reason,不把异常甩给调用方', thrownResult.ok === false && thrownResult.name === 'demo:throw' && thrownResult.reason === '命令执行失败', JSON.stringify(thrownResult))
4039
+ apiView.registerCommand('demo:destroyed', () => 'never')
3961
4040
  apiView.destroy()
4041
+ const afterDestroy = apiView.executeCommand('demo:destroyed', null)
4042
+ check('destroy:实例命令表清空,销毁后执行返回 ok: false', apiView.listCommands().length === 0 && afterDestroy.ok === false, JSON.stringify({ commands: apiView.listCommands(), result: afterDestroy }))
3962
4043
  apiHost.remove()
3963
4044
  }
3964
4045
  /* ---------------- 线路 zIndex:电压高的线压在上面(见 15.47) ---------------- */
@@ -192,8 +192,8 @@
192
192
  await settleFrames()
193
193
  const fillAuto = minimapFill()
194
194
  check('鹰眼图 extent: auto 把远离数据的 GeoJSON 一起框进来', fillAuto > 100 && fillAuto > fillData + 100, `data=${fillData} auto=${fillAuto}`)
195
- // 反过来:底图小到在合并范围里只剩一两个像素、而相机正好落在里面时,auto 以它为准 ——
196
- // 正在看的主体不该因为另一套坐标离得远就被压成一个点(数据还没映射到底图时常是这种情况)
195
+ // 反过来:底图小到在合并范围里只剩一两个像素、而相机正好落在里面时,默认仍按并集铺;
196
+ // 显式打开 extentFollowCamera 后,auto 才以正在看的那一份为准。
197
197
  const tinyHost = document.createElement('div')
198
198
  tinyHost.style.cssText = 'position:fixed;left:-9999px;top:0;width:420px;height:320px'
199
199
  document.body.appendChild(tinyHost)
@@ -210,12 +210,20 @@
210
210
  minimap: { width: 200, height: 160, extent: 'auto' }
211
211
  })
212
212
  await settleFrames()
213
- const fillSquashed = minimapFill(tinyHost)
214
- tinyView.zoomToBounds({ minX: 100, minY: 20, maxX: 101, maxY: 21 })
215
- await settleFrames()
216
- const fillFocused = minimapFill(tinyHost)
217
- check('鹰眼图 extent: auto 在相机落进小范围时以它为准', fillFocused > 200 && fillFocused > fillSquashed + 200, `squashed=${fillSquashed} focused=${fillFocused}`)
218
- // 这一轮:沿用主图规则取描边色(不再是白点)、小图尺寸跟随主视图地图倍数、框与框选矩形的样式
213
+ const fillSquashed = minimapFill(tinyHost)
214
+ tinyView.zoomToBounds({ minX: 100, minY: 20, maxX: 101, maxY: 21 })
215
+ await settleFrames()
216
+ const fillDefault = minimapFill(tinyHost)
217
+ check('鹰眼图 extent: auto 默认不随相机收窄(外围内容消失后包围盒保持并集)',
218
+ (tinyView.getOptions().minimap.extentFollowCamera ?? false) === false && fillDefault > 0 && Math.abs(fillDefault - fillSquashed) < 40,
219
+ `squashed=${fillSquashed} default=${fillDefault}`)
220
+ tinyView.updateOptions({ minimap: { ...tinyView.getOptions().minimap, extentFollowCamera: true } })
221
+ await settleFrames()
222
+ const fillFocused = minimapFill(tinyHost)
223
+ check('鹰眼图 extent: 打开 extentFollowCamera 后,相机落进小范围时 auto 以它为准',
224
+ tinyView.getOptions().minimap.extentFollowCamera === true && fillFocused > 200 && fillFocused > fillSquashed + 200,
225
+ `squashed=${fillSquashed} focused=${fillFocused}`)
226
+ // 这一轮:沿用主图规则取描边色(不再是白点)、继承尺寸不受主视图地图倍数影响、框与框选矩形的样式
219
227
  const ruleHost = document.createElement('div')
220
228
  ruleHost.style.cssText = 'position:fixed;left:-9999px;top:0;width:420px;height:320px'
221
229
  document.body.appendChild(ruleHost)
@@ -254,7 +262,11 @@
254
262
  ruleView.zoomTo(ruleView.getCamera().scale * 3, [210, 160])
255
263
  await settleFrames()
256
264
  const redZoomed = minimapRed()
257
- check('鹰眼图节点跟随主视图地图倍数放大', redZoomed > redBefore * 2, `${redBefore} → ${redZoomed}`)
265
+ check(
266
+ '鹰眼图沿用主图规则时主图放大不改变节点尺寸(pointMapZoomScale 也不参与继承)',
267
+ redBefore > 0 && Math.abs(redZoomed - redBefore) <= 2,
268
+ `${redBefore} → ${redZoomed}`
269
+ )
258
270
  const boxElement = ruleHost.querySelector('.gis-view__minimap-box')
259
271
  const boxComputed = getComputedStyle(boxElement)
260
272
  check(
@@ -319,9 +331,113 @@
319
331
  bgRedBefore > 0 && Math.abs(bgRedAfter - bgRedBefore) <= Math.max(bgRedBefore * 0.2, 2),
320
332
  `主图放大 3 倍前后小图红点像素 ${bgRedBefore} → ${bgRedAfter}`
321
333
  )
322
- bgView.destroy()
323
- bgHost.remove()
324
- // 这一轮:小图自身倍数的联动指数(pointZoomScale)真的生效 —— 放大鹰眼图 6 倍,节点半径按 6^指数 长
334
+ bgView.destroy()
335
+ bgHost.remove()
336
+ // 这一轮:沿用主图规则时线路线宽也只跟视口比例走 —— 主图放大不变,小图自身放大才按 lineZoomScale 变
337
+ const lineHost = document.createElement('div')
338
+ lineHost.style.cssText = 'position:fixed;left:-9999px;top:0;width:420px;height:320px'
339
+ document.body.appendChild(lineHost)
340
+ const lineView = createGisView(lineHost, {
341
+ points: [{ id: 'a', x: 0, y: 50 }, { id: 'b', x: 100, y: 50 }],
342
+ lines: [{ id: 'l', from: 'a', to: 'b' }],
343
+ background: false,
344
+ pointStyle: { size: 1, color: '#00aa00' },
345
+ lineStyle: { width: 8, color: '#ff3200', opacity: 1 },
346
+ minimap: {
347
+ width: 200,
348
+ height: 160,
349
+ background: false,
350
+ lineStyle: { color: '#ff3200', width: 1, opacity: 1 },
351
+ inheritRules: true,
352
+ pointMapZoomScale: 1,
353
+ lineMapZoomScale: 1,
354
+ lineZoomScale: 1,
355
+ maxZoom: 8
356
+ }
357
+ })
358
+ await settleFrames()
359
+ const lineBefore = minimapRedIn(lineHost)
360
+ lineView.zoomTo(lineView.getCamera().scale * 3, [210, 160])
361
+ await settleFrames()
362
+ const lineAfterMainZoom = minimapRedIn(lineHost)
363
+ check(
364
+ '鹰眼图沿用主图线宽时主图放大不改变线路宽度(lineMapZoomScale 也不参与继承)',
365
+ lineBefore > 20 && Math.abs(lineAfterMainZoom - lineBefore) <= 2,
366
+ `${lineBefore} → ${lineAfterMainZoom}`
367
+ )
368
+ lineView.updateOptions({ minimap: { ...lineView.getOptions().minimap, lineWidthScale: 2 } })
369
+ await settleFrames()
370
+ const lineWidthScaled = minimapRedIn(lineHost)
371
+ check(
372
+ '鹰眼图线路整体倍数 lineWidthScale 对继承线路生效',
373
+ lineWidthScaled > lineAfterMainZoom * 1.5,
374
+ `${lineAfterMainZoom} → ${lineWidthScaled}`
375
+ )
376
+ lineView.updateOptions({ minimap: { ...lineView.getOptions().minimap, lineWidthScale: 1 } })
377
+ await settleFrames()
378
+ lineView.setMinimapZoom(2)
379
+ await settleFrames()
380
+ const lineAfterMiniZoom = minimapRedIn(lineHost)
381
+ check(
382
+ '鹰眼图自身放大时沿用主图的线路按 lineZoomScale 变粗',
383
+ lineAfterMiniZoom > lineAfterMainZoom * 1.6,
384
+ `${lineAfterMainZoom} → ${lineAfterMiniZoom}`
385
+ )
386
+ lineView.destroy()
387
+ lineHost.remove()
388
+ // 沿用主图的节点:主图放大不变,小图自身放大时按 pointZoomScale 变大(pointMapZoomScale 不参与继承)
389
+ const inheritedPointHost = document.createElement('div')
390
+ inheritedPointHost.style.cssText = 'position:fixed;left:-9999px;top:0;width:420px;height:320px'
391
+ document.body.appendChild(inheritedPointHost)
392
+ const inheritedPointView = createGisView(inheritedPointHost, {
393
+ points: [{ id: 'a', x: 45, y: 50 }, { id: 'b', x: 55, y: 50 }],
394
+ lines: [{ id: 'l', from: 'a', to: 'b' }],
395
+ background: false,
396
+ pointStyle: { size: 10, color: '#ff3200' },
397
+ lineStyle: { width: 1.5, color: '#00aa00' },
398
+ minimap: {
399
+ width: 200,
400
+ height: 160,
401
+ background: false,
402
+ extent: { minX: 0, minY: 0, maxX: 100, maxY: 100 },
403
+ inheritRules: true,
404
+ pointZoomScale: 1,
405
+ pointMapZoomScale: 1,
406
+ zoomable: true,
407
+ maxZoom: 8
408
+ }
409
+ })
410
+ await settleFrames()
411
+ const inheritedPointBefore = minimapRedIn(inheritedPointHost)
412
+ inheritedPointView.zoomTo(inheritedPointView.getCamera().scale * 3, [210, 160])
413
+ await settleFrames()
414
+ const inheritedPointAfterMainZoom = minimapRedIn(inheritedPointHost)
415
+ check(
416
+ '鹰眼图沿用主图节点时主图放大不改变节点大小(pointMapZoomScale 也不参与继承)',
417
+ inheritedPointBefore > 10 && Math.abs(inheritedPointAfterMainZoom - inheritedPointBefore) <= 2,
418
+ `${inheritedPointBefore} → ${inheritedPointAfterMainZoom}`
419
+ )
420
+ inheritedPointView.updateOptions({ minimap: { ...inheritedPointView.getOptions().minimap, pointSizeScale: 2 } })
421
+ await settleFrames()
422
+ const inheritedPointSizeScaled = minimapRedIn(inheritedPointHost)
423
+ check(
424
+ '鹰眼图节点整体倍数 pointSizeScale 对继承节点生效',
425
+ inheritedPointSizeScaled > inheritedPointAfterMainZoom * 2,
426
+ `${inheritedPointAfterMainZoom} → ${inheritedPointSizeScaled}`
427
+ )
428
+ inheritedPointView.updateOptions({ minimap: { ...inheritedPointView.getOptions().minimap, pointSizeScale: 1 } })
429
+ await settleFrames()
430
+ inheritedPointView.setMinimapZoom(2)
431
+ await settleFrames()
432
+ const inheritedPointAfterMiniZoom = minimapRedIn(inheritedPointHost)
433
+ check(
434
+ '鹰眼图自身放大时沿用主图的节点按 pointZoomScale 变大',
435
+ inheritedPointAfterMiniZoom > inheritedPointAfterMainZoom * 2,
436
+ `${inheritedPointAfterMainZoom} → ${inheritedPointAfterMiniZoom}`
437
+ )
438
+ inheritedPointView.destroy()
439
+ inheritedPointHost.remove()
440
+ // 这一轮:小图自身倍数的联动指数(pointZoomScale)真的生效 —— 放大鹰眼图 6 倍,节点半径按 6^指数 长
325
441
  const zoomHost = document.createElement('div')
326
442
  zoomHost.style.cssText = 'position:fixed;left:-9999px;top:0;width:420px;height:320px'
327
443
  document.body.appendChild(zoomHost)
@@ -458,6 +574,193 @@
458
574
  )
459
575
  extraView.destroy()
460
576
  extraHost.remove()
577
+ // 本轮鹰眼图五项:回线居中、动态位移、backgroundStyle、主图尺寸 / 图标、外部挂载
578
+ const circuitHost = document.createElement('div')
579
+ circuitHost.style.cssText = 'position:fixed;left:-9999px;top:0;width:420px;height:320px'
580
+ document.body.appendChild(circuitHost)
581
+ let circuitLines = []
582
+ const circuitView = createGisView(circuitHost, {
583
+ points: [{ id: 'ca', x: 0, y: 0 }, { id: 'cb', x: 100, y: 0 }],
584
+ lines: [
585
+ { id: 'cl1', from: 'ca', to: 'cb' },
586
+ { id: 'cl2', from: 'ca', to: 'cb' }
587
+ ],
588
+ channels: [{ id: 'cch', from: 'ca', to: 'cb', lineIds: ['cl1', 'cl2'] }],
589
+ background: false,
590
+ minimap: {
591
+ width: 200,
592
+ height: 150,
593
+ background: false,
594
+ channelCircuits: true,
595
+ boxStyle: { fillOpacity: 0, strokeWidth: 0 },
596
+ draw: info => { circuitLines = info.data.lines }
597
+ }
598
+ })
599
+ await settleFrames()
600
+ const allCircuitPaths = circuitLines.map(line => line.path)
601
+ circuitLines = []
602
+ circuitView.updateOptions({ minimap: { ...circuitView.getOptions().minimap, channelCircuits: false } })
603
+ await settleFrames()
604
+ const representativePath = circuitLines[0]?.path ?? []
605
+ const expectedCenter = allCircuitPaths.length === 2
606
+ ? allCircuitPaths[0].map((coordinate, index) => [
607
+ (coordinate[0] + allCircuitPaths[1][index][0]) / 2,
608
+ (coordinate[1] + allCircuitPaths[1][index][1]) / 2
609
+ ])
610
+ : []
611
+ const centeredRepresentative = representativePath.length === expectedCenter.length && representativePath.every((coordinate, index) =>
612
+ Math.abs(coordinate[0] - expectedCenter[index][0]) < 1e-6 && Math.abs(coordinate[1] - expectedCenter[index][1]) < 1e-6
613
+ )
614
+ check(
615
+ '鹰眼图关闭回线后双回线取居中代表线',
616
+ allCircuitPaths.length === 2 && circuitLines.length === 1 && centeredRepresentative,
617
+ `原回线 ${allCircuitPaths.length} 条,代表线 ${circuitLines.length} 条,路径 ${JSON.stringify(representativePath)}`
618
+ )
619
+ circuitView.destroy()
620
+ circuitHost.remove()
621
+ const styleHost = document.createElement('div')
622
+ styleHost.style.cssText = 'position:fixed;left:-9999px;top:0;width:360px;height:260px'
623
+ document.body.appendChild(styleHost)
624
+ const styleView = createGisView(styleHost, {
625
+ points: [],
626
+ lines: [],
627
+ background: { color: '#ffffff' },
628
+ minimap: {
629
+ width: 140,
630
+ height: 90,
631
+ background: 'inherit',
632
+ backgroundStyle: 'rgb(20, 40, 60)',
633
+ boxStyle: { fillOpacity: 0, strokeWidth: 0 }
634
+ }
635
+ })
636
+ await settleFrames()
637
+ const styledRoot = styleView.getMinimapElement()
638
+ const styledCanvas = styledRoot?.querySelector('.gis-view__minimap-canvas')
639
+ const styledPixels = styledCanvas?.getContext('2d').getImageData(0, 0, styledCanvas.width, styledCanvas.height).data ?? []
640
+ let opaqueBackgroundPixels = 0
641
+ for (let index = 3; index < styledPixels.length; index += 4) {
642
+ if (styledPixels[index] > 0) {
643
+ opaqueBackgroundPixels += 1
644
+ }
645
+ }
646
+ const styledColor = styledRoot ? getComputedStyle(styledRoot).backgroundColor : ''
647
+ check(
648
+ '鹰眼图显式 backgroundStyle 接管容器底色且画布让出底色',
649
+ styledColor === 'rgb(20, 40, 60)' && opaqueBackgroundPixels === 0,
650
+ `容器=${styledColor},画布不透明像素 ${opaqueBackgroundPixels}`
651
+ )
652
+ styleView.destroy()
653
+ styleHost.remove()
654
+ const minimapErrors = []
655
+ const captureMinimapError = event => minimapErrors.push(String(event.error?.stack ?? event.message))
656
+ window.addEventListener('error', captureMinimapError)
657
+ const pointHost = document.createElement('div')
658
+ pointHost.style.cssText = 'position:fixed;left:-9999px;top:0;width:360px;height:260px'
659
+ document.body.appendChild(pointHost)
660
+ const pointView = createGisView(pointHost, {
661
+ points: [
662
+ { id: 'square-node', x: 0, y: 0 },
663
+ { id: 'circle-node', x: 100, y: 0 },
664
+ { id: 'icon-node', x: 200, y: 0 }
665
+ ],
666
+ lines: [],
667
+ pointRules: [
668
+ { name: '小图方点', when: { id: 'square-node' }, style: { size: 64, symbol: 'square', color: '#0088ff', strokeColor: '#0088ff' } },
669
+ { name: '小图圆点', when: { id: 'circle-node' }, style: { size: 64, symbol: 'circle', color: '#00cc66', strokeColor: '#00cc66' } },
670
+ { name: '小图图标', when: { id: 'icon-node' }, style: { size: 64, symbol: { type: 'svg', path: 'M0 0H20V20H0Z', viewBox: [0, 0, 20, 20], fill: '#ff00ff' }, color: '#0088ff', strokeColor: '#0088ff' } }
671
+ ],
672
+ background: false,
673
+ minimap: {
674
+ width: 220,
675
+ height: 120,
676
+ background: false,
677
+ extent: { minX: -20, minY: -20, maxX: 220, maxY: 20 },
678
+ boxStyle: { fillOpacity: 0, strokeWidth: 0 }
679
+ }
680
+ })
681
+ let pointInk = { blue: 0, green: 0, magenta: 0 }
682
+ for (let attempt = 0; attempt < 15; attempt += 1) {
683
+ await new Promise(resolve => setTimeout(resolve, 60))
684
+ const pointCanvas = pointView.getMinimapElement()?.querySelector('.gis-view__minimap-canvas')
685
+ const pointPixels = pointCanvas?.getContext('2d').getImageData(0, 0, pointCanvas.width, pointCanvas.height).data ?? []
686
+ pointInk = { blue: 0, green: 0, magenta: 0 }
687
+ for (let index = 0; index < pointPixels.length; index += 4) {
688
+ const red = pointPixels[index]
689
+ const green = pointPixels[index + 1]
690
+ const blue = pointPixels[index + 2]
691
+ if (red < 60 && green > 80 && green < 190 && blue > 200) {
692
+ pointInk.blue += 1
693
+ }
694
+ if (red < 60 && green > 150 && blue < 140) {
695
+ pointInk.green += 1
696
+ }
697
+ if (red > 220 && green < 50 && blue > 220) {
698
+ pointInk.magenta += 1
699
+ }
700
+ }
701
+ if (pointInk.magenta > 500 && pointInk.blue > 500 && pointInk.green > 500) {
702
+ break
703
+ }
704
+ }
705
+ const circleSquareRatio = pointInk.blue ? pointInk.green / pointInk.blue : 0
706
+ check(
707
+ '鹰眼图沿用主图规则后尺寸与 SVG 图标一致',
708
+ pointInk.blue > 500 && pointInk.green > 500 && pointInk.magenta > 500 && circleSquareRatio > 0.85 && circleSquareRatio < 1.15 && minimapErrors.length === 0,
709
+ '方点 ' + pointInk.blue + 'px,圆点 ' + pointInk.green + 'px(比值 ' + circleSquareRatio.toFixed(2) + '),图标 ' + pointInk.magenta + 'px,错误 ' + (minimapErrors[0] ?? '无')
710
+ )
711
+ pointView.destroy()
712
+ pointHost.remove()
713
+ window.removeEventListener('error', captureMinimapError)
714
+ const externalHostId = 'minimap-ext-' + Math.random().toString(36).slice(2)
715
+ const alternateHostId = 'minimap-alt-' + Math.random().toString(36).slice(2)
716
+ const externalHost = document.createElement('div')
717
+ externalHost.id = externalHostId
718
+ externalHost.style.cssText = 'position:fixed;left:-9999px;top:340px;width:280px;height:200px;background:#eef4fb'
719
+ const alternateHost = document.createElement('div')
720
+ alternateHost.id = alternateHostId
721
+ alternateHost.style.cssText = 'position:fixed;left:-9999px;top:560px;width:280px;height:200px;background:#f7eefb'
722
+ const externalViewHost = document.createElement('div')
723
+ externalViewHost.style.cssText = 'position:fixed;left:-9999px;top:0;width:360px;height:260px'
724
+ document.body.append(externalHost, alternateHost, externalViewHost)
725
+ const externalView = createGisView(externalViewHost, {
726
+ points: [{ id: 'ext-a', x: 0, y: 0 }, { id: 'ext-b', x: 30, y: 20 }],
727
+ lines: [{ id: 'ext-l', from: 'ext-a', to: 'ext-b' }],
728
+ background: false,
729
+ minimap: {
730
+ width: 140,
731
+ height: 90,
732
+ margin: 10,
733
+ background: false,
734
+ container: externalHost,
735
+ boxStyle: { fillOpacity: 0, strokeWidth: 0 }
736
+ }
737
+ })
738
+ await settleFrames()
739
+ const externalRoot = externalView.getMinimapElement()
740
+ const beforeMoveRect = externalRoot?.getBoundingClientRect()
741
+ externalView.updateOptions({ minimap: { ...externalView.getOptions().minimap, offset: [30, 20] } })
742
+ await settleFrames()
743
+ const afterMoveRect = externalRoot?.getBoundingClientRect()
744
+ const moved = Boolean(beforeMoveRect && afterMoveRect &&
745
+ Math.abs(afterMoveRect.left - beforeMoveRect.left - 30) < 0.75 &&
746
+ Math.abs(afterMoveRect.top - beforeMoveRect.top - 20) < 0.75)
747
+ check(
748
+ '鹰眼图能挂到外部 div,并用 offset 动态移动整张图',
749
+ externalRoot?.parentElement === externalHost && externalViewHost.querySelector('.gis-view__minimap') === null && moved,
750
+ '父元素 ' + (externalRoot?.parentElement?.id ?? 'null') + ',位移 ' + (beforeMoveRect ? Math.round(afterMoveRect.left - beforeMoveRect.left) + ',' + Math.round(afterMoveRect.top - beforeMoveRect.top) : 'null')
751
+ )
752
+ externalView.updateOptions({ minimap: { ...externalView.getOptions().minimap, container: '#' + alternateHostId } })
753
+ await settleFrames()
754
+ const movedHost = externalView.getMinimapElement() === externalRoot && externalRoot?.parentElement === alternateHost
755
+ externalView.destroy()
756
+ check(
757
+ '鹰眼图换外部容器复用同一根节点,destroy 后一并清理',
758
+ movedHost && !externalRoot?.isConnected && !alternateHost.querySelector('.gis-view__minimap'),
759
+ '换容器 ' + movedHost + ',销毁后 connected=' + (externalRoot?.isConnected ?? false)
760
+ )
761
+ externalHost.remove()
762
+ alternateHost.remove()
763
+ externalViewHost.remove()
461
764
  // 宿主缩放(CSS zoom / 祖先的 transform: scale):引擎的 CSS 像素按布局像素算、画布备份仍是设备像素、
462
765
  // DOM 标签与指针换算同除显示比例;三样对不上时,标签会飞出节点、指针也点不中
463
766
  const plainScaleHost = document.createElement('div')
@@ -2178,8 +2178,46 @@
2178
2178
  clusterView.destroy()
2179
2179
  clusterHost.remove()
2180
2180
 
2181
+ /* ---------------- 同一批点线数据原样回灌:两半都没换时别白解析 ---------------- */
2182
+ // 组件把同一批对象原样再交一次是常规写法(刷新配置 / 只换别的选项时顺带带上 data)。
2183
+ // 这里量 5 次取中位;每次回灌之后数据、线路实例数与相机都必须原样。
2184
+ big.fitView(0)
2185
+ big.refresh()
2186
+ big.refresh()
2187
+ const refeedPoints = big.getData().points
2188
+ const refeedLines = big.getData().lines
2189
+ const refeedInstances = big.getStats().lineInstances
2190
+ const refeedStarted = now()
2191
+ const refeedSamples = []
2192
+ for (let round = 0; round < 5; round += 1) {
2193
+ const started = now()
2194
+ big.updateOptions({ points: refeedPoints, lines: refeedLines })
2195
+ refeedSamples.push(now() - started)
2196
+ }
2197
+ refeedSamples.sort((left, right) => left - right)
2198
+ const refeedMs = refeedSamples[Math.floor(refeedSamples.length / 2)]
2199
+ const refeedData = big.getData()
2200
+ check('同一批点线原样回灌:条数 / 线路实例数都不变(解析结果可以整半沿用)',
2201
+ refeedData.points.length === pointCount && refeedData.lines.length === lineCount && big.getStats().lineInstances === refeedInstances,
2202
+ JSON.stringify({ points: refeedData.points.length, lines: refeedData.lines.length, instances: big.getStats().lineInstances, expected: refeedInstances }))
2203
+ diag(`同一批点线原样回灌(${pointCount} 点 / ${lineCount} 线)`, `中位 ${refeedMs.toFixed(1)} ms(5 次:${refeedSamples.map(value => value.toFixed(1)).join(' / ')};总观测 ${(now() - refeedStarted).toFixed(1)} ms)`)
2204
+ // 同一批数据回灌不能让通道几何停在上一轮:声明没换时沿用,换了骨架必须照常重推
2205
+ big.updateOptions({ channels: [{ id: 'reuse-guard', from: 'p0', to: 'p1', lineIds: ['l0', 'l1'], path: [[20, 20]] }] })
2206
+ const guardBefore = big.getChannelGroupWaypoints('reuse-guard')
2207
+ big.updateOptions({ points: refeedPoints, lines: refeedLines })
2208
+ const guardAfter = big.getChannelGroupWaypoints('reuse-guard')
2209
+ check('同一批点线回灌:通道声明没换时,回线派生折线原样保留',
2210
+ JSON.stringify(guardBefore?.lines?.map(line => line.path)) === JSON.stringify(guardAfter?.lines?.map(line => line.path)),
2211
+ JSON.stringify({ before: guardBefore?.lines?.map(line => line.waypoints), after: guardAfter?.lines?.map(line => line.waypoints) }))
2212
+ big.updateOptions({ channels: [{ id: 'reuse-guard', from: 'p0', to: 'p1', lineIds: ['l0', 'l1'], path: [[80, 80]] }] })
2213
+ const guardChanged = big.getChannelGroupWaypoints('reuse-guard')
2214
+ check('同一批点线回灌:换通道骨架时线路那一半不能沿用旧几何',
2215
+ JSON.stringify(guardChanged?.lines?.map(line => line.waypoints)) !== JSON.stringify(guardAfter?.lines?.map(line => line.waypoints)),
2216
+ JSON.stringify({ before: guardAfter?.lines?.map(line => line.waypoints), after: guardChanged?.lines?.map(line => line.waypoints) }))
2217
+ big.updateOptions({ channels: [] })
2218
+
2181
2219
  thinView.destroy()
2182
- thinHost.remove()
2220
+ thinHost.remove()
2183
2221
  big.destroy()
2184
2222
  bigHost.remove()
2185
2223
  small.destroy()