• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

antvis / L7Plot / 9478568050

12 Jun 2024 07:33AM UTC coverage: 56.968% (-2.6%) from 59.55%
9478568050

push

github

web-flow
chore: type mis (#356)

* chore: type mis

* chore: compiler options target

960 of 2222 branches covered (43.2%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

916 existing lines in 53 files now uncovered.

2768 of 4322 relevant lines covered (64.04%)

234.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.14
/packages/l7plot/src/core/layer/plot-layer.ts
1
import { isEqual, isUndefined, pick } from '@antv/util';
2
import { Source } from '@antv/l7';
254✔
3
import EventEmitter from '@antv/event-emitter';
254✔
4
import { LayerType, IPlotLayer, PlotLayerOptions, LayerBlend } from '../../types/layer';
254✔
5
import { Scene, ILayer, ILayerConfig, SourceOptions } from '../../types';
254✔
6
import { MappingSource } from '../../adaptor/source';
254✔
7
import { LayerEventList } from '../map/constants';
254✔
8
import { deepAssign } from '../../utils';
254✔
9

254✔
10
const LayerConfigkeys = ['name', 'zIndex', 'visible', 'minZoom', 'maxZoom', 'pickingBuffer', 'autoFit', 'blend'];
254✔
11

254✔
12
export abstract class PlotLayer<O extends PlotLayerOptions> extends EventEmitter implements IPlotLayer<O> {
254✔
13
  /**
14
   * 地图图表类型
15
   */
679✔
16
  static LayerType = LayerType;
679✔
17
  /**
679✔
18
   * 图层属性配置项 Keys
19
   */
20
  static LayerConfigkeys = LayerConfigkeys;
21
  /**
22
   * layer 的 schema 配置
UNCOV
23
   */
×
24
  public options: O;
25
  /**
26
   * layer 上一次的 schema 配置
679✔
27
   */
679✔
28
  public lastOptions: O;
29
  /**
30
   * layer 实例
383✔
31
   */
32
  public abstract readonly layer: ILayer;
33
  /**
32✔
34
   * layer 名称
35
   */
36
  public abstract readonly name: string;
37
  /**
38
   * layer 类型
39
   */
170✔
40
  public abstract readonly type: LayerType | string;
170✔
41
  /**
42
   * layer 是否具有交互效果,用于 tooltip
43
   */
44
  public abstract readonly interaction: boolean;
45

46
  constructor(options: O) {
170✔
47
    super();
170✔
48
    this.options = deepAssign({}, this.getDefaultOptions(), options);
49
    this.lastOptions = this.options;
50
  }
51

170!
UNCOV
52
  /**
×
53
   * 获取默认配置
54
   */
170!
UNCOV
55
  protected getDefaultOptions(): Partial<O> {
×
56
    return {};
57
  }
170!
UNCOV
58

×
59
  public pickLayerConfig<T extends PlotLayerOptions>(params: T): Partial<ILayerConfig> {
60
    const config = pick<any>(params, LayerConfigkeys);
170!
UNCOV
61
    return config;
×
62
  }
63

170!
UNCOV
64
  public addTo(scene: Scene) {
×
65
    scene.addLayer(this.layer);
66
  }
67

UNCOV
68
  public remove(scene: Scene) {
×
69
    scene.removeLayer(this.layer);
70
  }
71

679✔
72
  /**
590✔
73
   * 更新
74
   */
75
  public update(options: Partial<O>) {
89✔
76
    this.updateOption(options);
89✔
77
    this.updateConfig(options);
89✔
78
  }
89!
UNCOV
79

×
80
  /**
81
   * 更新: 更新配置
82
   */
89✔
83
  public updateOption(options: Partial<O>) {
84
    this.lastOptions = this.options;
85
    this.options = deepAssign({}, this.options, options);
86
  }
UNCOV
87

×
88
  // 更新: 更新图层属性配置
89
  public updateConfig(options: Partial<PlotLayerOptions>) {
UNCOV
90
    if (!isUndefined(options.zIndex) && !isEqual(this.lastOptions.zIndex, this.options.zIndex)) {
×
91
      this.setIndex(options.zIndex);
92
    }
UNCOV
93

×
94
    if (!isUndefined(options.blend) && !isEqual(this.lastOptions.blend, this.options.blend)) {
95
      this.setBlend(options.blend);
UNCOV
96
    }
×
97

98
    if (!isUndefined(options.minZoom) && !isEqual(this.lastOptions.minZoom, this.options.minZoom)) {
UNCOV
99
      this.setMinZoom(options.minZoom);
×
100
    }
101

102
    if (!isUndefined(options.maxZoom) && !isEqual(this.lastOptions.maxZoom, this.options.maxZoom)) {
30✔
103
      this.setMinZoom(options.maxZoom);
104
    }
105

30✔
106
    if (!isUndefined(options.visible) && !isEqual(this.lastOptions.visible, this.options.visible)) {
107
      options.visible ? this.show() : this.hide();
108
    }
20✔
109
  }
110

111
  public render() {
20!
112
    this.layer.renderLayers();
113
  }
UNCOV
114

×
115
  protected setSource(source: SourceOptions | Source) {
116
    if (source instanceof Source) {
117
      this.layer.setSource(source);
118
    } else {
119
      const { data, aggregation, ...option } = source;
120
      aggregation && MappingSource.aggregation(option, aggregation);
80!
121
      const layerSource = this.layer.getSource();
80✔
122
      if (layerSource) {
123
        this.layer.setData(data, option);
UNCOV
124
      } else {
×
125
        this.layer.source(data, option);
126
      }
80✔
127
    }
128
  }
129

130
  public changeData(source: SourceOptions | Source) {
131
    this.setSource(source);
132
  }
383!
133

383✔
134
  public setIndex(zIndex: number) {
135
    this.layer.setIndex(zIndex);
UNCOV
136
  }
×
137

138
  public setBlend(blend: LayerBlend) {
383✔
139
    this.layer.setBlend(blend);
140
  }
141

142
  public setMinZoom(minZoom: number) {
143
    this.layer.setMinZoom(minZoom);
UNCOV
144
  }
×
UNCOV
145

×
146
  public setMaxZoom(maxZoom: number) {
147
    this.layer.setMaxZoom(maxZoom);
UNCOV
148
  }
×
149

150
  public show() {
×
151
    this.layer.inited && this.layer.show();
152
  }
153

254✔
154
  public hide() {
155
    this.layer.inited && this.layer.hide();
156
  }
157

254✔
158
  public toggleVisible() {
159
    this.isVisible() ? this.hide() : this.show();
160
  }
161

254✔
162
  public isVisible() {
163
    return this.layer.inited ? this.layer.isVisible() : this.options.visible;
164
  }
165

166
  public fitBounds(fitBoundsOptions?: unknown) {
167
    this.layer.fitBounds(fitBoundsOptions);
168
  }
169

170
  /**
171
   * 事件代理: 绑定事件
172
   */
173
  public on(name: string, callback: (...args: any[]) => void) {
174
    if (LayerEventList.indexOf(name) !== -1) {
175
      this.layer.on(name, callback);
176
    } else {
177
      super.on(name, callback);
178
    }
179
    return this;
180
  }
181

182
  /**
183
   * 事件代理: 绑定一次事件
184
   */
185
  public once(name: string, callback: (...args: any[]) => void) {
186
    if (LayerEventList.indexOf(name) !== -1) {
187
      this.layer.once(name, callback);
188
    } else {
189
      super.once(name, callback);
190
    }
191
    return this;
192
  }
193

194
  /**
195
   * 事件代理: 解绑事件
196
   */
197
  public off(name: string, callback: (...args: any[]) => void) {
198
    if (LayerEventList.indexOf(name) !== -1) {
199
      this.layer.off(name, callback);
200
    } else {
201
      super.off(name, callback);
202
    }
203
    return this;
204
  }
205
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc