Skip to content

Commit 3f81df9

Browse files
authored
refactor(maps): migrate bmap & tmap to BaseMap, delete BaseMapService (#2878)
bmap/map.ts 和 tmap/map.ts 迁移: - extends BaseMapService<X> -> extends BaseMap<X> - $mapContainer -> mapContainer (基类统一命名) - 补全 BaseMap 声明为 abstract 的小方法: - getMapStyle() -> '' (bmap/tmap 无 mapbox getStyle API) - getMapStyleConfig() -> MapTheme (tmap 新增, bmap 已有 styleConfig) - setMaxZoom/setMinZoom -> 兼容可选调用 map.setMaxZoom?.(max) 删除 BaseMapService.ts (466 行 @deprecated 死代码): - 仅剩 bmap/tmap 两个消费者, 迁移完即删除 - utils/index.ts 同步移除导出, 保留 BaseMapWrapper 验证: - tsc --noEmit -p packages/maps 仅 4 个本地 @types 全局错误 (baseline) - prettier format-check 全绿
1 parent fd925f8 commit 3f81df9

4 files changed

Lines changed: 40 additions & 479 deletions

File tree

packages/maps/src/bmap/map.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import type {
1313
import { MapServiceEvent } from '@antv/l7-core';
1414
import { DOM } from '@antv/l7-utils';
1515
import { mat4, vec3 } from 'gl-matrix';
16+
import BaseMap from '../lib/base-map';
1617
import Viewport from '../lib/web-mercator-viewport';
17-
import BaseMapService from '../utils/BaseMapService';
1818
import { toPaddingOptions } from '../utils/utils';
1919
import BMapGLLoader from './bmapglloader';
2020
import './logo.css';
@@ -30,8 +30,7 @@ const EventMap: {
3030

3131
const BMAP_VERSION: string = '1.0';
3232

33-
// TODO: 基于抽象类 BaseMap 实现,补全缺失方法,解决类型问题
34-
export default class BMapService extends BaseMapService<BMapGL.Map> {
33+
export default class BMapService extends BaseMap<BMapGL.Map> {
3534
protected viewport: IViewport;
3635
protected styleConfig: Record<string, any> = {
3736
normal: [],
@@ -119,7 +118,7 @@ export default class BMapService extends BaseMapService<BMapGL.Map> {
119118
if (mapInstance) {
120119
// @ts-ignore
121120
this.map = mapInstance;
122-
this.$mapContainer = this.map.getContainer();
121+
this.mapContainer = this.map.getContainer();
123122
const point = new BMapGL.Point(center[0], center[1]);
124123
// false,表示用户未执行centerAndZoom进行地图初始渲染
125124
// @ts-ignore
@@ -147,10 +146,10 @@ export default class BMapService extends BaseMapService<BMapGL.Map> {
147146
let mapChildNodes = [...mapContainer.childNodes];
148147
// @ts-ignore
149148
const map = new BMapGL.Map(mapContainer, mapConstructorOptions);
150-
this.$mapContainer = map.getContainer();
149+
this.mapContainer = map.getContainer();
151150

152151
mapChildNodes.forEach((child) => {
153-
this.$mapContainer!.appendChild(child);
152+
this.mapContainer!.appendChild(child);
154153
});
155154
// @ts-ignore
156155
mapChildNodes = null;
@@ -271,6 +270,14 @@ export default class BMapService extends BaseMapService<BMapGL.Map> {
271270
return this.map.getMaxZoom();
272271
}
273272

273+
public setMaxZoom(max: number): void {
274+
this.map.setMaxZoom?.(max);
275+
}
276+
277+
public setMinZoom(min: number): void {
278+
this.map.setMinZoom?.(min);
279+
}
280+
274281
// get map params
275282
public getType() {
276283
return 'bmap';
@@ -323,6 +330,10 @@ export default class BMapService extends BaseMapService<BMapGL.Map> {
323330
return this.getMap().getContainer();
324331
}
325332

333+
public getMapStyle(): string {
334+
return '';
335+
}
336+
326337
public getMapStyleConfig(): MapStyleConfig {
327338
return this.styleConfig;
328339
}

packages/maps/src/tmap/map.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import type {
55
IPoint,
66
IStatusOptions,
77
IViewport,
8+
MapStyleConfig,
89
Point,
910
} from '@antv/l7-core';
1011
import { MapServiceEvent } from '@antv/l7-core';
1112
import { MercatorCoordinate } from '@antv/l7-map';
1213
import { DOM } from '@antv/l7-utils';
1314
import { mat4, vec3 } from 'gl-matrix';
15+
import BaseMap from '../lib/base-map';
1416
import Viewport from '../lib/web-mercator-viewport';
15-
import BaseMapService from '../utils/BaseMapService';
17+
import { MapTheme } from '../utils/theme';
1618
import './logo.css';
1719
import TMapLoader from './maploader';
1820

@@ -27,8 +29,7 @@ const EventMap: {
2729
dragging: 'drag',
2830
};
2931

30-
// TODO: 基于抽象类 BaseMap 实现,补全缺失方法,解决类型问题
31-
export default class TMapService extends BaseMapService<TMap.Map> {
32+
export default class TMapService extends BaseMap<TMap.Map> {
3233
// @ts-ignore
3334
protected viewport: IViewport = null;
3435

@@ -102,7 +103,7 @@ export default class TMapService extends BaseMapService<TMap.Map> {
102103
if (mapInstance) {
103104
// If there's already a map instance, maybe not setting any other configurations
104105
this.map = mapInstance as any;
105-
this.$mapContainer = this.map.getContainer();
106+
this.mapContainer = this.map.getContainer();
106107
if (logoVisible === false) {
107108
this.hideLogo();
108109
}
@@ -126,7 +127,7 @@ export default class TMapService extends BaseMapService<TMap.Map> {
126127
// @ts-ignore
127128
this.map = map;
128129
// @ts-ignore
129-
this.$mapContainer = map.getContainer();
130+
this.mapContainer = map.getContainer();
130131
if (logoVisible === false) {
131132
this.hideLogo();
132133
}
@@ -288,6 +289,14 @@ export default class TMapService extends BaseMapService<TMap.Map> {
288289
return this.map.transform._maxZoom;
289290
}
290291

292+
public setMaxZoom(max: number): void {
293+
(this.map as any).setMaxZoom?.(max);
294+
}
295+
296+
public setMinZoom(min: number): void {
297+
(this.map as any).setMinZoom?.(min);
298+
}
299+
291300
// get map params
292301
public getType() {
293302
return 'tmap';
@@ -336,6 +345,14 @@ export default class TMapService extends BaseMapService<TMap.Map> {
336345
this.bgColor = color;
337346
}
338347

348+
public getMapStyle(): string {
349+
return '';
350+
}
351+
352+
public getMapStyleConfig(): MapStyleConfig {
353+
return MapTheme;
354+
}
355+
339356
public setMapStyle(styleId: any): void {
340357
this.map.setMapStyleId(styleId);
341358
}

0 commit comments

Comments
 (0)