Skip to content

Commit

Permalink
feat: 地图底图支持高德V2 (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Nov 11, 2022
1 parent a084c74 commit 24b6291
Show file tree
Hide file tree
Showing 36 changed files with 100 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class ChoroplethLayer extends CompositeLayer<ChoroplethLayerOptions> {
};

const options = {
visible,
visible: visible && Boolean(lineWidth) && Boolean(strokeColor),
zIndex,
minZoom,
maxZoom,
Expand Down
4 changes: 2 additions & 2 deletions packages/composite-layers/src/core/composite-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ export abstract class CompositeLayer<O extends CompositeLayerOptions> extends Ev
/**
* 事件代理: 绑定事件
*/
public on(name: string, callback: (...args: any[]) => void) {
public on(name: string, callback: (...args: any[]) => void, once?: boolean) {
if (OriginLayerEventList.indexOf(name) !== -1) {
this.layer.on(name, callback);
} else {
super.on(name, callback);
super.on(name, callback, once);
}
return this;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/composite-layers/src/core/core-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,11 @@ export abstract class CoreLayer<O extends CoreLayerOptions> extends EventEmitter
/**
* 事件代理: 绑定事件
*/
public on(name: string, callback: (...args: any[]) => void) {
public on(name: string, callback: (...args: any[]) => void, once?: boolean) {
if (OriginLayerEventList.indexOf(name) !== -1) {
this.layer.on(name, callback);
} else {
super.on(name, callback);
super.on(name, callback, once);
}
return this;
}
Expand Down
62 changes: 19 additions & 43 deletions packages/composite-layers/src/types/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,14 @@ export interface ILayerGroup {
}

/**
* 核心图层的基类接口
* 图层的基础接口
*/
export interface ICoreLayer {
interface IBaseLayer {
options: Record<string, any>;
name: string;
id: string;
type: string;
interaction: boolean;
layer: ILayer;
inited: boolean;
source: ISource;
isComposite: boolean;

addTo(scene: Scene): void;
remove(): void;
Expand All @@ -45,8 +42,6 @@ export interface ICoreLayer {
updateOption(options: unknown): void;

changeData(data: SourceOptions): void;
setSource(source: ISource): void;
getSource(): ISource;
render(): void;

show(): void;
Expand All @@ -59,59 +54,40 @@ export interface ICoreLayer {
setMaxZoom(maxZoom: number): void;
setBlend(blend: LayerBlend): void;

boxSelect(bounds: [number, number, number, number], callback: (...args: any[]) => void): void;

fitBounds(fitBoundsOptions?: unknown): void;
getLegend(name: string): ILegend;
getLegendItems(type: string): Record<string, any>[];

destroy(): void;

on(name: string, callback: (...args: any[]) => void): this;
on(name: string, callback: (...args: any[]) => void, once?: boolean): this;
once(name: string, callback: (...args: any[]) => void): this;
off(name: string, callback: (...args: any[]) => void): this;
}

/**
* 复合图层的基类接口
* 核心图层的基类接口
*/
export interface ICompositeLayer {
options: Record<string, any>;
name: string;
id: string;
type: string;

subLayers: ILayerGroup;

addTo(scene: Scene): void;
remove(): void;
export interface ICoreLayer extends IBaseLayer {
interaction: boolean;

update(options: unknown): void;
updateOption(options: unknown): void;
layer: ILayer;
inited: boolean;
source: ISource;

changeData(data: SourceOptions): void;
render(): void;
setSource(source: ISource): void;
getSource(): ISource;

show(): void;
hide(): void;
toggleVisible(): void;
isVisible(): boolean;
boxSelect(bounds: [number, number, number, number], callback: (...args: any[]) => void): void;
}

setIndex(zIndex: number): void;
setMinZoom(minZoom: number): void;
setMaxZoom(maxZoom: number): void;
setBlend(blend: LayerBlend): void;
/**
* 复合图层的基类接口
*/
export interface ICompositeLayer extends IBaseLayer {
subLayers: ILayerGroup;

fitBounds(fitBoundsOptions?: unknown): void;
getLegend(name: string): ILegend;
getLegendItems(type: string): Record<string, any>[];
getColorLegendItems(): Record<string, any>[];

getInteractionSubLayers(): ICoreLayer[];

destroy(): void;

on(name: string, callback: (...args: any[]) => void): this;
once(name: string, callback: (...args: any[]) => void): this;
off(name: string, callback: (...args: any[]) => void): this;
}
2 changes: 1 addition & 1 deletion packages/l7plot/__tests__/unit/adaptor/layer/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Source } from '@antv/l7';
import { getLayerStyleAttribute } from '../../../helper/layer';
import { DotLayer } from '../../../../src/layers/dot-layer';
import { Source } from '../../../../src/types';
import { DotLayerOptions } from '../../../../src/layers/dot-layer';
import { LinesLayer, LinesLayerOptions } from '../../../../src/layers/lines-layer';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Source } from '@antv/l7';
import { getLayerStyleAttribute } from '../../../helper/layer';
import { ColumnLayer } from '../../../../src/layers/column-layer';
import { Source } from '../../../../src/types';

describe('column layer', () => {
const layer = new ColumnLayer({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Source } from '@antv/l7';
import { getLayerStyleAttribute } from '../../../helper/layer';
import { DotLayer } from '../../../../src/layers/dot-layer';
import { Source } from '../../../../src/types';

describe('dot layer', () => {
const layer = new DotLayer({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Source } from '@antv/l7';
import { getLayerStyleAttribute } from '../../../helper/layer';
import { HeatmapLayer } from '../../../../src/layers/heatmap-layer';
import { Source } from '../../../../src/types';

describe('heatmap layer', () => {
const layer = new HeatmapLayer({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Source } from '@antv/l7';
import { getLayerStyleAttribute } from '../../../helper/layer';
import { IconLayer } from '../../../../src/layers/icon-layer';
import { Source } from '../../../../src/types';
import { registerImages } from '../../../../src';

describe('icon layer', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Source } from '@antv/l7';
import { getLayerStyleAttribute } from '../../../helper/layer';
import { TextLayer } from '../../../../src/layers/text-layer';
import { Source } from '../../../../src/types';

describe('text layer', () => {
const layer = new TextLayer({
Expand Down
4 changes: 2 additions & 2 deletions packages/l7plot/src/component/legend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IControlOption } from '@antv/l7';
import { Control } from '@antv/l7-component';
import type { IControlOption } from '@antv/l7';
import { Control } from '@antv/l7';
import { CategoryLegendOptions, ContinueLegendOptions, CategoryLegend, ContinueLegend } from '@antv/l7plot-component';

export type LegendItem =
Expand Down
15 changes: 3 additions & 12 deletions packages/l7plot/src/component/tooltip.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Scene } from '@antv/l7-scene';
import { Marker } from '@antv/l7-component';
import { Scene, Marker } from '@antv/l7';
import EventEmitter from '@antv/event-emitter';
import { isString, isEqual } from '@antv/util';
import {
Expand All @@ -8,16 +7,8 @@ import {
TooltipListItem,
} from '@antv/l7plot-component';
import { get as getValueByPath } from 'lodash-es';
import {
IPlotLayer,
ILngLat,
TooltipAnchorType,
Event,
TooltipOptions,
MouseEvent,
TooltipItem,
TooltipEvent,
} from '../types';
import type { IPlotLayer, ILngLat, Event, TooltipOptions, MouseEvent, TooltipItem, TooltipEvent } from '../types';
import { TooltipAnchorType } from '../types';
import { deepAssign } from '../utils';

const TRIGGER_LIST = ['mousemove', 'click'];
Expand Down
2 changes: 1 addition & 1 deletion packages/l7plot/src/core/layer/plot-layer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isEqual, isUndefined, pick } from '@antv/util';
import Source from '@antv/l7-source';
import { Source } from '@antv/l7';
import EventEmitter from '@antv/event-emitter';
import { LayerType, IPlotLayer, PlotLayerOptions, LayerBlend } from '../../types/layer';
import { Scene, ILayer, ILayerConfig, SourceOptions } from '../../types';
Expand Down
23 changes: 16 additions & 7 deletions packages/l7plot/src/core/map/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Scene } from '@antv/l7-scene';
import { Mapbox, GaodeMap } from '@antv/l7-maps';
import { Scale, Zoom } from '@antv/l7-component';
import { Scene, Mapbox, GaodeMap, GaodeMapV2, Map as L7Map, Scale, Zoom } from '@antv/l7';
import EventEmitter from '@antv/event-emitter';
import { isObject, isBoolean, isUndefined, isEqual } from '@antv/util';
import { Tooltip } from '../../component/tooltip';
import { Legend, LegendItem } from '../../component/legend';
import { deepAssign } from '../../utils';
import {
BaseMapType,
import { BaseMapType } from '../../types';
import type {
MapOptions,
MapInstance,
AMapInstance,
MapboxInstance,
ZoomControlOptions,
Expand Down Expand Up @@ -147,7 +146,13 @@ export abstract class Map<O extends MapOptions> extends EventEmitter {
const { type, ...config } = mapConfig;
const options = Object.assign({ style: this.theme['mapStyle'] }, config);

return type === BaseMapType.Amap ? new GaodeMap(options) : new Mapbox(options);
return type === BaseMapType.Amap
? new GaodeMap(options)
: type === BaseMapType.AmapV2
? new GaodeMapV2(options)
: type === BaseMapType.Mapbox
? new Mapbox(options)
: new L7Map(options);
}

/**
Expand Down Expand Up @@ -322,11 +327,15 @@ export abstract class Map<O extends MapOptions> extends EventEmitter {
/**
* 获取 map 实例
*/
public getMap(): MapboxInstance | AMapInstance | unknown {
public getMap(): MapboxInstance | AMapInstance | MapInstance | unknown {
if (this.options.map?.type === BaseMapType.Amap) {
return this.scene.map as AMapInstance;
} else if (this.options.map?.type === BaseMapType.AmapV2) {
return this.scene.map as AMapInstance;
} else if (this.options.map?.type === BaseMapType.Mapbox) {
return this.scene.map as MapboxInstance;
} else if (this.options.map?.type === BaseMapType.Map) {
return this.scene.map as MapInstance;
} else {
return this.scene.map;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/l7plot/src/core/plot/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Source } from '@antv/l7';
import { Map } from '../map';
import { deepAssign } from '../../utils';
import { TextLayer } from '../../layers/text-layer';
import { PlotType, PlotOptions, LabelOptions, Source, SourceOptions, Scene, PlotLayerOptions } from '../../types';
import { PlotType } from '../../types';
import type { PlotOptions, LabelOptions, SourceOptions, Scene, PlotLayerOptions } from '../../types';
import { LayerGroup } from '../layer/layer-group';
import { MappingSource } from '../../adaptor/source';
import { isEqual } from '@antv/util';
Expand Down
2 changes: 1 addition & 1 deletion packages/l7plot/src/layers/area-layer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { uniqueId, clone, isEqual, isUndefined } from '@antv/util';
import { PolygonLayer, LineLayer } from '@antv/l7-layers';
import { PolygonLayer, LineLayer } from '@antv/l7';
import { PlotLayer } from '../../core/layer/plot-layer';
import { getDefaultState, mappingLayer } from './adaptor';
import { AreaLayerOptions, AreaLayerSourceOptions } from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/l7plot/src/layers/dot-layer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { uniqueId } from '@antv/util';
import { PointLayer } from '@antv/l7-layers';
import { PointLayer } from '@antv/l7';
import { PlotLayer } from '../../core/layer/plot-layer';
import { mappingLayer } from './adaptor';
import { DotLayerOptions } from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/l7plot/src/layers/grid-layer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { uniqueId } from '@antv/util';
import { HeatmapLayer as Heatmap } from '@antv/l7-layers';
import { HeatmapLayer as Heatmap } from '@antv/l7';
import { PlotLayer } from '../../core/layer/plot-layer';
import { mappingLayer } from './adaptor';
import { GridLayerOptions } from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/l7plot/src/layers/heatmap-layer/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IColorRamp } from '@antv/l7-utils';
import type { IColorRamp } from '@antv/l7';
import { MappingLayer } from '../../adaptor/layer';
import { HeatmapLayerStyleOptions } from '../../types/layer';
import { ILayer } from '../../types';
Expand Down
2 changes: 1 addition & 1 deletion packages/l7plot/src/layers/heatmap-layer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { uniqueId } from '@antv/util';
import { HeatmapLayer as Heatmap } from '@antv/l7-layers';
import { HeatmapLayer as Heatmap } from '@antv/l7';
import { PlotLayer } from '../../core/layer/plot-layer';
import { mappingLayer } from './adaptor';
import { HeatmapLayerOptions } from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/l7plot/src/layers/hexbin-layer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { uniqueId } from '@antv/util';
import { HeatmapLayer as Heatmap } from '@antv/l7-layers';
import { HeatmapLayer as Heatmap } from '@antv/l7';
import { PlotLayer } from '../../core/layer/plot-layer';
import { mappingLayer } from './adaptor';
import { HexbinLayerOptions } from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/l7plot/src/layers/lines-layer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { uniqueId } from '@antv/util';
import { LineLayer } from '@antv/l7-layers';
import { LineLayer } from '@antv/l7';
import { PlotLayer } from '../../core/layer/plot-layer';
import { mappingLayer } from './adaptor';
import { LinesLayerOptions } from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/l7plot/src/layers/prism-layer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { uniqueId } from '@antv/util';
import { PolygonLayer } from '@antv/l7-layers';
import { PolygonLayer } from '@antv/l7';
import { PlotLayer } from '../../core/layer/plot-layer';
import { mappingLayer } from './adaptor';
import { PrismLayerOptions } from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/l7plot/src/layers/text-layer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { uniqueId } from '@antv/util';
import { PointLayer } from '@antv/l7-layers';
import { PointLayer } from '@antv/l7';
import { PlotLayer } from '../../core/layer/plot-layer';
import { TextLayerConfig } from '../../types/layer';
import { mappingLayer } from './adaptor';
Expand Down
3 changes: 2 additions & 1 deletion packages/l7plot/src/plots/choropleth/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Source } from '@antv/l7';
import { pick, isEqual } from '@antv/util';
import { Plot } from '../../core/plot';
import { deepAssign } from '../../utils';
Expand All @@ -15,7 +16,7 @@ import { GEO_DATA_URL, GEO_AREA_URL, DEFAULT_AREA_GRANULARITY, DEFAULT_OPTIONS }
import { AreaLayer } from '../../layers/area-layer';
import { PathLayer } from '../../layers/path-layer';
import { TextLayer } from '../../layers/text-layer';
import { LabelOptions, LegendOptions, MouseEvent, Source } from '../../types';
import type { LabelOptions, LegendOptions, MouseEvent } from '../../types';
import { LayerGroup } from '../../core/layer/layer-group';
import { createCountryBoundaryLayer } from './layer';
import { getCacheArea, registerCacheArea } from './cache';
Expand Down
2 changes: 1 addition & 1 deletion packages/l7plot/src/types/attr.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IAnimateOption, IActiveOption } from '@antv/l7-core';
import type { IAnimateOption, IActiveOption } from '@antv/l7';
import { ScaleConfig } from './common';

export type Callback<T> = (data: Record<string, any>) => T | T[];
Expand Down

0 comments on commit 24b6291

Please sign in to comment.