Skip to content

Commit

Permalink
wip: refactor split tripartite map
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed May 26, 2024
1 parent 9060f49 commit 995fc79
Show file tree
Hide file tree
Showing 59 changed files with 690 additions and 539 deletions.
11 changes: 7 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BasePostProcessingPass from './services/renderer/passes/BasePostProcessingPass';
import { removeDuplicateUniforms } from './utils/shader-module';
import { packCircleVertex } from './utils/vertex-compression';
export { default as BasePostProcessingPass } from './services/renderer/passes/BasePostProcessingPass';
export { removeDuplicateUniforms } from './utils/shader-module';
export { packCircleVertex } from './utils/vertex-compression';

export * from './services/asset/IFontService';
export * from './services/asset/IIconService';
Expand Down Expand Up @@ -34,4 +34,7 @@ export * from './services/renderer/IUniform';
export * from './services/scene/ISceneService';
export * from './services/shader/IShaderModuleService';
export * from './services/source/ISourceService';
export { BasePostProcessingPass, packCircleVertex, removeDuplicateUniforms };
/** 地图类基类 */
export * from './services/map/base-map';
export * from './services/map/base-map-wrapper';
export * from './services/map/web-mercator-viewport';
12 changes: 0 additions & 12 deletions packages/core/src/services/map/IMapService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@ export interface IMapWrapper {
setContainer(container: L7Container, id: string | HTMLDivElement): void;
}

interface ISimpleMapCoord {
setSize(size: number): void;
getSize(): [number, number];
project(lnglat: [number, number]): [number, number];
unproject(xy: [number, number]): [number, number];
}

export interface IMapService<RawMap = {}> {
version?: string;
simpleMapCoord: ISimpleMapCoord;
map: RawMap;
bgColor: string;
setBgColor(color: string): void;
Expand All @@ -70,7 +61,6 @@ export interface IMapService<RawMap = {}> {
getMinZoom(): number;
getMaxZoom(): number;
// get map params
getType(): string;
getZoom(): number;
getCenter(option?: ICameraOptions): ILngLat;
getPitch(): number;
Expand Down Expand Up @@ -131,7 +121,6 @@ export interface IMapService<RawMap = {}> {
}

export interface IEarthService<RawMap = {}> {
version?: string;
map: RawMap;
bgColor: string;
setBgColor(color: string): void;
Expand All @@ -153,7 +142,6 @@ export interface IEarthService<RawMap = {}> {
getMinZoom(): number;
getMaxZoom(): number;
// get map params
getType(): string;
getZoom(): number;
getCenter(option?: ICameraOptions): ILngLat;
getPitch(): number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type {
IGlobalConfigService,
IMapConfig,
IMapService,
IMapWrapper,
L7Container,
} from '@antv/l7-core';
export default class BaseMapWrapper<RawMap> implements IMapWrapper {
import type { L7Container } from '../../inversify.config';
import type { IGlobalConfigService } from '../config/IConfigService';
import type { IMapConfig, IMapWrapper } from './IMapService';
import type { BaseMapService } from './base-map';

/**
* BaseMapWrapper
*/
export class BaseMapWrapper<RawMap> implements IMapWrapper {
protected configService: IGlobalConfigService;

protected config: Partial<IMapConfig>;
Expand All @@ -24,7 +25,7 @@ export default class BaseMapWrapper<RawMap> implements IMapWrapper {
sceneContainer.mapService = new (this.getServiceConstructor())(sceneContainer);
}

protected getServiceConstructor(): new (...args: any[]) => IMapService<RawMap> {
protected getServiceConstructor(): new (...args: any[]) => BaseMapService<RawMap> {
throw new Error('Method not implemented.');
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import type { EventEmitterStatic } from 'eventemitter3';
import { EventEmitter } from 'eventemitter3';
import type { L7Container } from '../../inversify.config';
import type { IViewport } from '../camera/ICameraService';
import type { IGlobalConfigService } from '../config/IConfigService';
import type { ICoordinateSystemService } from '../coordinate/ICoordinateSystemService';
import { CoordinateSystem } from '../coordinate/ICoordinateSystemService';
import type {
Bounds,
ICoordinateSystemService,
IGlobalConfigService,
ILngLat,
IMapCamera,
IMapConfig,
IMapService,
IMercator,
IPoint,
IStatusOptions,
IViewport,
L7Container,
MapStyleConfig,
MapStyleName,
} from '@antv/l7-core';
import { CoordinateSystem } from '@antv/l7-core';
import type { EventEmitterStatic } from 'eventemitter3';
import { EventEmitter } from 'eventemitter3';
import { SimpleMapCoord } from '../utils/simpleMapCoord';
} from './IMapService';

const LNGLAT_OFFSET_ZOOM_THRESHOLD = 12;

export default abstract class BaseMap<T> implements IMapService<T> {
/**
* BaseMapService
*/
export abstract class BaseMapService<T> implements IMapService<T> {
/**
* 地图实例
*/
public map: T;

/**
* @deprecated
* TODO: 基类型不需要实现,只是自定义 Map 使用非地理坐标系才会用到
* 地图类型
*/
public simpleMapCoord = new SimpleMapCoord();
public abstract type: string;

/**
* 背景色
Expand Down Expand Up @@ -94,15 +94,15 @@ export default abstract class BaseMap<T> implements IMapService<T> {
}

protected creatMapContainer(id: string | HTMLDivElement) {
let $wrapper: HTMLDivElement;
let wrapper: HTMLDivElement;

if (typeof id === 'string') {
$wrapper = document.getElementById(id) as HTMLDivElement;
wrapper = document.getElementById(id) as HTMLDivElement;
} else {
$wrapper = id;
wrapper = id;
}

return $wrapper;
return wrapper;
}

public abstract getMapStyle(): string;
Expand All @@ -113,8 +113,6 @@ export default abstract class BaseMap<T> implements IMapService<T> {
return this.getMapStyleConfig()[name] ?? name;
}

public abstract getType(): string;

public setBgColor(color: string) {
this.bgColor = color;
}
Expand Down Expand Up @@ -145,14 +143,14 @@ export default abstract class BaseMap<T> implements IMapService<T> {

public abstract off(type: string, handle: (...args: any[]) => void): void;

public emit(name: string, ...args: any[]) {
this.eventEmitter.emit(name, ...args);
}

public once(name: string, handler: (...args: any[]) => void) {
this.eventEmitter.once(name, handler);
}

public emit(name: string, ...args: any[]) {
this.eventEmitter.emit(name, ...args);
}

public abstract getSize(): [number, number];

public abstract getZoom(): number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { IMapCamera, IViewport } from '@antv/l7-core';
import WebMercatorViewport from 'viewport-mercator-project';
import { default as WMViewport } from 'viewport-mercator-project';
import type { IViewport } from '../camera/ICameraService';
import type { IMapCamera } from './IMapService';

export default class Viewport implements IViewport {
public viewport = new WebMercatorViewport();
export class WebMercatorViewport implements IViewport {
public viewport = new WMViewport();

public syncWithMapCamera(mapCamera: Partial<IMapCamera>) {
const { center, zoom, pitch, bearing, viewportHeight, viewportWidth } = mapCamera;
Expand All @@ -17,7 +18,7 @@ export default class Viewport implements IViewport {
bearing: this.viewport.bearing,
};

this.viewport = new WebMercatorViewport({
this.viewport = new WMViewport({
...preView,
width: viewportWidth,
height: viewportHeight,
Expand Down
48 changes: 48 additions & 0 deletions packages/extension-maps/.fatherrc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { IFatherConfig } from 'father';
import { defineConfig } from 'father';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';

const isProduction = process.env.NODE_ENV === 'production';

const umdConfig: IFatherConfig['umd'] = {
name: 'L7ExtensionMaps',
output: {
path: './dist',
filename: 'l7-extension-maps.min.js',
},
platform: 'browser',
targets: { ie: 11 },
externals: {
'mapbox-gl': {
root: 'mapboxgl',
commonjs: 'mapbox-gl',
commonjs2: 'mapbox-gl',
amd: 'mapbox-gl',
},
'maplibre-gl': {
root: 'maplibregl',
commonjs: 'maplibre-gl',
commonjs2: 'maplibre-gl',
amd: 'maplibre-gl',
},
},
chainWebpack(memo) {
// 关闭压缩方便调试,默认开启
// memo.optimization.minimize(false);

// 打包体积分析
memo
.plugin('webpack-bundle-analyzer')
.use(BundleAnalyzerPlugin, [{ analyzerMode: 'static', openAnalyzer: false }]);

return memo;
},
};

export default defineConfig({
extends: '../../.fatherrc.base.ts',
// 使用 babel 编译 esm/cjs 产物,启用 transform-import-css-l7 插件完成 CSS 内联打包
esm: { transformer: 'babel' },
cjs: isProduction ? { transformer: 'babel' } : undefined,
umd: isProduction ? umdConfig : undefined,
});
3 changes: 3 additions & 0 deletions packages/extension-maps/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/lib
/es
/dist
1 change: 1 addition & 0 deletions packages/extension-maps/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Change Log
52 changes: 52 additions & 0 deletions packages/extension-maps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@antv/l7-extension-maps",
"version": "2.21.11-beta.2",
"description": "Extension Maps for L7",
"license": "MIT",
"author": "https://github.com/orgs/antvis/people",
"sideEffects": [
"**/*.css"
],
"main": "lib/index.js",
"unpkg": "dist/l7-extension-maps.min.js",
"module": "es/index.js",
"types": "es/index.d.ts",
"files": [
"dist",
"lib",
"es",
"!dist/report.html"
],
"scripts": {
"dev": "father dev",
"build": "npm run clean && father build",
"check-deps": "father doctor",
"lint": "eslint src",
"clean": "rimraf dist es lib"
},
"dependencies": {
"@amap/amap-jsapi-loader": "^1.0.1",
"@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",
"viewport-mercator-project": "^6.2.1"
},
"devDependencies": {
"@map-component/tmap-types": "^0.1.3",
"@types/amap-js-api": "^1.4.6",
"@types/bmapgl": "^0.0.7",
"@types/gl-matrix": "^2.4.5",
"@types/google.maps": "^3.54.10",
"@types/mapbox-gl": "^1.11.2",
"@types/viewport-mercator-project": "^6.1.0"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"repository": "[email protected]:antvis/L7.git"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BaseMapWrapper from '../utils/BaseMapWrapper';
import { BaseMapWrapper } from '@antv/l7-core';
import MapService from './map';

export default class AMap2Wrapper extends BaseMapWrapper<AMap.Map> {
Expand Down
File renamed without changes.
Loading

0 comments on commit 995fc79

Please sign in to comment.