Commit 90ad625
committed
refactor(maps): DRY creatMapContainer getElementById 解析,复用 super 调用
## 背景
`BaseMap.creatMapContainer` 已封装 id-or-element 的解析逻辑(string 走
getElementById,HTMLDivElement 直接用)。map/mapbox/maplibre/tdtmap 四个适配器
的 `creatMapContainer` 重写各自重复实现了一遍同样的解析,与基类逻辑冗余。
## 改动
将 4 个文件中重复的 id/element 解析分支替换为 `super.creatMapContainer(id)`
调用:
- packages/maps/src/map/map.ts
- packages/maps/src/mapbox/map.ts
- packages/maps/src/maplibre/map.ts
- packages/maps/src/tdtmap/map.ts
每个文件其余逻辑(创建内部 div、注入 cssText、设置 id 前缀如 l7_mapbox_div /
l7_tdt_div、mapdivCount 自增)保持不变,行为与改动前完全一致。
amap-next/map.ts 早已正确通过 super.creatMapContainer(id) 调用基类,无需改动。
## 为何不把内部 div 创建也抽到 MapboxBaseMap
- tdtmap 继承 BaseMap 而非 MapboxBaseMap,无法复用 MapboxBaseMap 上的方法;
- 各适配器 id 前缀、变量命名不同($amapdiv / $tdtmapdiv / container),统一
抽取会引入少量行为或样式调整的风险,收益有限;
- 本次只消除最明显的重复(id/element 解析),保留各适配器现有的差异点,
行为完全等价。
## 验证
- 本地 tsc --noEmit -p packages/maps/tsconfig.json 通过(除已知 @types 噪声外)
- prettier --check 4 个改动文件通过
净 -12 行(+4 / -16)1 parent 3f81df9 commit 90ad625
4 files changed
Lines changed: 4 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
| 116 | + | |
120 | 117 | | |
121 | 118 | | |
122 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
| 194 | + | |
198 | 195 | | |
199 | 196 | | |
200 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
| 192 | + | |
196 | 193 | | |
197 | 194 | | |
198 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
| 530 | + | |
534 | 531 | | |
535 | 532 | | |
536 | 533 | | |
| |||
0 commit comments