Skip to content

Commit

Permalink
wip: all map split
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed May 27, 2024
1 parent 74900b0 commit 2050651
Show file tree
Hide file tree
Showing 37 changed files with 529 additions and 862 deletions.
2 changes: 1 addition & 1 deletion examples/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export const MAP_TYPES: TestCaseBasemap[] = [
'MapLibre',
'BaiduMap',
'TencentMap',
'TMap',
'TdtMap',
'GoogleMap',
] as const;
2 changes: 1 addition & 1 deletion examples/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type TestCaseBasemap =
| 'MapLibre'
| 'TencentMap'
| 'Mapbox'
| 'TMap'
| 'TdtMap'
| 'GoogleMap';

export type TestCaseOptions = GUIOptions & {
Expand Down
22 changes: 21 additions & 1 deletion examples/utils/scene.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
import { Scene } from '@antv/l7';
import type { IMapConfig } from '@antv/l7-core';
import * as Maps from '@antv/l7-maps';
import {
BaiduMap,
GaodeMap,
GoogleMap,
MapLibre,
Mapbox,
TdtMap,
TencentMap,
} from '@antv/l7-extension-maps';
import { Map } from '@antv/l7-maps';
import type { TestCaseOptions } from '../types';

const Maps = {
Map,
BaiduMap,
GaodeMap,
GoogleMap,
MapLibre,
Mapbox,
TdtMap,
TencentMap,
};

type CaseSceneOptions = TestCaseOptions & {
mapConfig?: Partial<IMapConfig>;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/component/src/control/mapTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class MapTheme extends SelectControl<ISelectControlOption> {

public getStyleOptions(): ControlOptionItem[] {
const mapStyleConfig =
this.mapsService.getType() === 'mapbox' ? MapboxMapStyleConfig : GaodeMapStyleConfig;
this.mapsService.type === 'Mapbox' ? MapboxMapStyleConfig : GaodeMapStyleConfig;
return Object.entries(this.mapsService.getMapStyleConfig())
.filter(([key, value]) => typeof value === 'string' && key !== 'blank')
.map(([key, value]) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/component/src/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export default class Marker extends EventEmitter {
*/
private touchStartTime: number;
private polyfillEvent(e: MouseEvent | TouchEvent) {
if (!this.mapsService || this.mapsService.getType() !== 'amap') {
if (!this.mapsService || this.mapsService.type !== 'AMap') {
return;
}
if (!isPC()) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/services/interaction/PickingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ export default class PickingService implements IPickingService {
public handleCursor(layer: ILayer, type: string) {
const { cursor = '', cursorEnabled } = layer.getLayerConfig();
if (cursorEnabled) {
const mapType = this.mapService.getType();
const mapType = this.mapService.type;
const domContainer =
mapType === 'amap'
mapType === 'AMap'
? this.mapService.getMapContainer()
: this.mapService.getMarkerContainer();
// const domContainer = this.mapService.getMarkerContainer();
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/services/map/IMapService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface IMapWrapper {
export interface IMapService<RawMap = {}> {
map: RawMap;
type: string;
version?: string;
bgColor: string;
setBgColor(color: string): void;
init(): void;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/scene/SceneService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default class Scene extends EventEmitter implements ISceneService {
*/
this.hooks.init.tapPromise('initMap', async () => {
this.debugService.log('map.mapInitStart', {
type: this.map.version,
type: this.map.type,
});
// 等待首次相机同步
await new Promise<void>((resolve) => {
Expand Down
1 change: 0 additions & 1 deletion packages/extension-maps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@antv/l7-core": "workspace:*",
"@antv/l7-utils": "workspace:*",
"@babel/runtime": "^7.7.7",
"eventemitter3": "^4.0.0",
"gl-matrix": "^3.1.0",
"mapbox-gl": "^1.2.1",
"maplibre-gl": "^3.5.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-maps/src/amap/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
MapStyleName,
} from '@antv/l7-core';
import { BaseMapService, MapServiceEvent, WebMercatorViewport } from '@antv/l7-core';
import { DOM, amap2Project, lodashUtil } from '@antv/l7-utils';
import { DOM, amap2Project } from '@antv/l7-utils';
import { mat4, vec3 } from 'gl-matrix';
import { toPaddingOptions } from '../utils';
import './logo.css';
Expand Down Expand Up @@ -137,7 +137,7 @@ export default class AMapService extends BaseMapService<AMap.Map> {
height: 100%;
width: 100%;
`;
amapdiv.id = lodashUtil.uniqueId('l7_amap_div');
amapdiv.id = 'l7_amap_div';
wrapper.appendChild(amapdiv);
return amapdiv;
}
Expand Down
52 changes: 33 additions & 19 deletions packages/extension-maps/src/bmap/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const MapEvent: Record<string, string> = {
zoomchange: 'zoomend',
};

const BMAP_API_KEY: string = 'zLhopYPPERGtpGOgimcdKcCimGRyyIsh';
const BMAP_VERSION: string = '1.0';
const BMAP_API_KEY = 'zLhopYPPERGtpGOgimcdKcCimGRyyIsh';
const BMAP_VERSION = '1.0';
const ZOOM_OFFSET = 1.75;

export default class BMapService extends BaseMapService<BMapGL.Map> {
Expand Down Expand Up @@ -86,7 +86,7 @@ export default class BMapService extends BaseMapService<BMapGL.Map> {
throw Error('No container id specified');
}

const mapContainer = DOM.getContainer(id);
const mapContainer = this.creatMapContainer(id);

// 存储控件等容器,百度地图实例会被卸载掉,所以实例化后需要重新挂载
// @ts-ignore
Expand Down Expand Up @@ -158,10 +158,30 @@ export default class BMapService extends BaseMapService<BMapGL.Map> {
this.bgColor = color;
}

public destroy(): void {
super.destroy();
this.mapContainer?.parentNode?.removeChild(this.mapContainer);
this.getMap().destroy();
protected creatMapContainer(id: string | HTMLDivElement) {
const wrapper = super.creatMapContainer(id);
const amapdiv = document.createElement('div');
amapdiv.style.cssText += `
position: absolute;
top: 0;
height: 100%;
width: 100%;
`;
amapdiv.id = 'l7_baidu_div';
wrapper.appendChild(amapdiv);
return amapdiv;
}

public getContainer(): HTMLElement | null {
return this.getMap().getContainer();
}

public getMapContainer(): HTMLElement {
return this.getMap().getContainer();
}

public getMapCanvasContainer(): HTMLElement {
return this.getMap().getContainer();
}

// tslint:disable-next-line:no-empty
Expand Down Expand Up @@ -224,10 +244,6 @@ export default class BMapService extends BaseMapService<BMapGL.Map> {
this.eventEmitter.once(type, handler);
}

public getContainer(): HTMLElement | null {
return this.getMap().getContainer();
}

public getSize(): [number, number] {
const size = this.getMap().getSize();
return [size.width, size.height];
Expand Down Expand Up @@ -282,14 +298,6 @@ export default class BMapService extends BaseMapService<BMapGL.Map> {
];
}

public getMapContainer(): HTMLElement {
return this.getMap().getContainer();
}

public getMapCanvasContainer(): HTMLElement {
return this.getMap().getContainer();
}

public getMapStyleConfig(): MapStyleConfig {
return this.styleConfig;
}
Expand Down Expand Up @@ -550,4 +558,10 @@ export default class BMapService extends BaseMapService<BMapGL.Map> {
this.hideLogo();
}
}

public destroy(): void {
super.destroy();
this.mapContainer?.parentNode?.removeChild(this.mapContainer);
this.getMap().destroy();
}
}
2 changes: 1 addition & 1 deletion packages/extension-maps/src/gmap/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseMapWrapper } from '@antv/l7-core';
import GMapService from './map';

export default class GMapWrapper extends BaseMapWrapper<any> {
export default class GMapWrapper extends BaseMapWrapper<google.maps.Map> {
protected getServiceConstructor() {
return GMapService;
}
Expand Down
7 changes: 4 additions & 3 deletions packages/extension-maps/src/gmap/logo.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
img[src*='//mapapi.qq.com/web/jsapi/logo/logo_def.png'],.logo-text
{
display: none !important;
.googlemap-contianer--hide-logo {
img[alt='Google'] {
/* display: none !important; */
}
}
Loading

0 comments on commit 2050651

Please sign in to comment.