Skip to content

Commit 62a3593

Browse files
feedback
1 parent 030d1e8 commit 62a3593

6 files changed

Lines changed: 40 additions & 72 deletions

File tree

x-pack/plugins/maps/public/layers/layer.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ export class AbstractLayer implements ILayer {
4646
getMaxZoom(): number;
4747
getMinSourceZoom(): number;
4848
getQuery(): MapQuery;
49+
_removeStaleMbSourcesAndLayers(mbMap: unknown): void;
50+
_requiresPrevSourceCleanup(mbMap: unknown): boolean;
4951
}

x-pack/plugins/maps/public/layers/layer.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,26 @@ export class AbstractLayer {
219219
return this._source.getMinZoom();
220220
}
221221

222+
_requiresPrevSourceCleanup() {
223+
return false;
224+
}
225+
226+
_removeStaleMbSourcesAndLayers(mbMap) {
227+
if (this._requiresPrevSourceCleanup(mbMap)) {
228+
const mbStyle = mbMap.getStyle();
229+
mbStyle.layers.forEach(mbLayer => {
230+
if (this.ownsMbLayerId(mbLayer.id)) {
231+
mbMap.removeLayer(mbLayer.id);
232+
}
233+
});
234+
Object.keys(mbStyle.sources).some(mbSourceId => {
235+
if (this.ownsMbSourceId(mbSourceId)) {
236+
mbMap.removeSource(mbSourceId);
237+
}
238+
});
239+
}
240+
}
241+
222242
getAlpha() {
223243
return this._descriptor.alpha;
224244
}

x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@
66

77
import React from 'react';
88
import { EuiIcon } from '@elastic/eui';
9-
import { IVectorStyle, VectorStyle } from './styles/vector/vector_style';
9+
import { VectorStyle } from './styles/vector/vector_style';
1010
import { SOURCE_DATA_ID_ORIGIN, LAYER_TYPE } from '../../common/constants';
1111
import { VectorLayer, VectorLayerArguments } from './vector_layer';
1212
import { canSkipSourceUpdate } from './util/can_skip_fetch';
13-
import { ITiledSingleLayerVectorSource, IVectorSource } from './sources/vector_source';
13+
import { ITiledSingleLayerVectorSource } from './sources/vector_source';
1414
import { SyncContext } from '../actions/map_actions';
1515
import { ISource } from './sources/source';
16-
import {
17-
MapFilters,
18-
VectorLayerDescriptor,
19-
VectorSourceRequestMeta,
20-
} from '../../common/descriptor_types';
16+
import { VectorLayerDescriptor, VectorSourceRequestMeta } from '../../common/descriptor_types';
2117
import { MVTSingleLayerVectorSourceConfig } from './sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor';
2218

2319
export class TiledVectorLayer extends VectorLayer {
@@ -51,24 +47,6 @@ export class TiledVectorLayer extends VectorLayer {
5147
};
5248
}
5349

54-
// _getSearchFilters(
55-
// mapFilters: MapFilters,
56-
// source: IVectorSource,
57-
// style: IVectorStyle
58-
// ): VectorSourceRequestMeta {
59-
// const fieldNames = [...source.getFieldNames(), ...style.getSourceFieldNames()];
60-
//
61-
// const requestMeta: VectorSourceRequestMeta = {
62-
// ...mapFilters,
63-
// applyGlobalQuery: this._source.getApplyGlobalQuery(),
64-
// sourceMeta: this._source.getSyncMeta(),
65-
// fieldNames,
66-
// sourceQuery: this.getQuery(),
67-
// };
68-
//
69-
// return requestMeta;
70-
// }
71-
7250
async _syncMVTUrlTemplate({ startLoading, stopLoading, onLoadError, dataFilters }: SyncContext) {
7351
const requestToken: symbol = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`);
7452
const searchFilters: VectorSourceRequestMeta = this._getSearchFilters(
@@ -147,13 +125,12 @@ export class TiledVectorLayer extends VectorLayer {
147125
return;
148126
}
149127
const sourceMeta: MVTSingleLayerVectorSourceConfig = sourceDataRequest.getData() as MVTSingleLayerVectorSourceConfig;
150-
const options = { mvtSourceLayer: sourceMeta.layerName };
151128

152-
this._setMbPointsProperties(mbMap, options);
153-
this._setMbLinePolygonProperties(mbMap, options);
129+
this._setMbPointsProperties(mbMap, sourceMeta.layerName);
130+
this._setMbLinePolygonProperties(mbMap, sourceMeta.layerName);
154131
}
155132

156-
_requiresPrevSourceCleanup(mbMap: unknown) {
133+
_requiresPrevSourceCleanup(mbMap: unknown): boolean {
157134
// @ts-ignore
158135
const mbTileSource = mbMap.getSource(this.getId());
159136
if (!mbTileSource) {
@@ -177,26 +154,7 @@ export class TiledVectorLayer extends VectorLayer {
177154
}
178155

179156
syncLayerWithMB(mbMap: unknown) {
180-
const requiresCleanup = this._requiresPrevSourceCleanup(mbMap);
181-
if (requiresCleanup) {
182-
// @ts-ignore
183-
const mbStyle = mbMap.getStyle();
184-
// @ts-ignore
185-
mbStyle.layers.forEach(mbLayer => {
186-
if (this.ownsMbLayerId(mbLayer.id)) {
187-
// @ts-ignore
188-
mbMap.removeLayer(mbLayer.id);
189-
}
190-
});
191-
// @ts-ignore
192-
Object.keys(mbStyle.sources).some(mbSourceId => {
193-
if (this.ownsMbSourceId(mbSourceId)) {
194-
// @ts-ignore
195-
mbMap.removeSource(mbSourceId);
196-
}
197-
});
198-
}
199-
157+
this._removeStaleMbSourcesAndLayers(mbMap);
200158
this._syncSourceBindingWithMb(mbMap);
201159
this._syncStylePropertiesWithMb(mbMap);
202160
}

x-pack/plugins/maps/public/layers/vector_layer.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
6565
_syncData(syncContext: SyncContext, source: IVectorSource, style: IVectorStyle): Promise<void>;
6666
ownsMbSourceId(sourceId: string): boolean;
6767
ownsMbLayerId(sourceId: string): boolean;
68-
_setMbPointsProperties(mbMap: unknown, options: unknown): void;
69-
_setMbLinePolygonProperties(mbMap: unknown, options: unknown): void;
68+
_setMbPointsProperties(mbMap: unknown, mvtSourceLayer?: string): void;
69+
_setMbLinePolygonProperties(mbMap: unknown, mvtSourceLayer?: string): void;
7070
getSource(): IVectorSource;
7171
}

x-pack/plugins/maps/public/layers/vector_layer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ export class VectorLayer extends AbstractLayer {
641641
}
642642
}
643643

644-
_setMbPointsProperties(mbMap, options) {
644+
_setMbPointsProperties(mbMap, mvtSourceLayer) {
645645
const pointLayerId = this._getMbPointLayerId();
646646
const symbolLayerId = this._getMbSymbolLayerId();
647647
const pointLayer = mbMap.getLayer(pointLayerId);
@@ -658,15 +658,15 @@ export class VectorLayer extends AbstractLayer {
658658
if (symbolLayer) {
659659
mbMap.setLayoutProperty(symbolLayerId, 'visibility', 'none');
660660
}
661-
this._setMbCircleProperties(mbMap, options);
661+
this._setMbCircleProperties(mbMap, mvtSourceLayer);
662662
} else {
663663
markerLayerId = symbolLayerId;
664664
textLayerId = symbolLayerId;
665665
if (pointLayer) {
666666
mbMap.setLayoutProperty(pointLayerId, 'visibility', 'none');
667667
mbMap.setLayoutProperty(this._getMbTextLayerId(), 'visibility', 'none');
668668
}
669-
this._setMbSymbolProperties(mbMap, options);
669+
this._setMbSymbolProperties(mbMap, mvtSourceLayer);
670670
}
671671

672672
this.syncVisibilityWithMb(mbMap, markerLayerId);
@@ -677,7 +677,7 @@ export class VectorLayer extends AbstractLayer {
677677
}
678678
}
679679

680-
_setMbCircleProperties(mbMap, { mvtSourceLayer }) {
680+
_setMbCircleProperties(mbMap, mvtSourceLayer) {
681681
const sourceId = this.getId();
682682
const pointLayerId = this._getMbPointLayerId();
683683
const pointLayer = mbMap.getLayer(pointLayerId);
@@ -728,7 +728,7 @@ export class VectorLayer extends AbstractLayer {
728728
});
729729
}
730730

731-
_setMbSymbolProperties(mbMap, { mvtSourceLayer }) {
731+
_setMbSymbolProperties(mbMap, mvtSourceLayer) {
732732
const sourceId = this.getId();
733733
const symbolLayerId = this._getMbSymbolLayerId();
734734
const symbolLayer = mbMap.getLayer(symbolLayerId);
@@ -763,7 +763,7 @@ export class VectorLayer extends AbstractLayer {
763763
});
764764
}
765765

766-
_setMbLinePolygonProperties(mbMap, { mvtSourceLayer }) {
766+
_setMbLinePolygonProperties(mbMap, mvtSourceLayer) {
767767
const sourceId = this.getId();
768768
const fillLayerId = this._getMbPolygonLayerId();
769769
const lineLayerId = this._getMbLineLayerId();
@@ -815,8 +815,8 @@ export class VectorLayer extends AbstractLayer {
815815
}
816816

817817
_syncStylePropertiesWithMb(mbMap) {
818-
this._setMbPointsProperties(mbMap, {});
819-
this._setMbLinePolygonProperties(mbMap, {});
818+
this._setMbPointsProperties(mbMap);
819+
this._setMbLinePolygonProperties(mbMap);
820820
}
821821

822822
_syncSourceBindingWithMb(mbMap) {

x-pack/plugins/maps/public/layers/vector_tile_layer.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,7 @@ export class VectorTileLayer extends TileLayer {
161161
return;
162162
}
163163

164-
if (this._requiresPrevSourceCleanup(mbMap)) {
165-
const mbStyle = mbMap.getStyle();
166-
mbStyle.layers.forEach(mbLayer => {
167-
if (this.ownsMbLayerId(mbLayer.id)) {
168-
mbMap.removeLayer(mbLayer.id);
169-
}
170-
});
171-
Object.keys(mbStyle.sources).some(mbSourceId => {
172-
if (this.ownsMbSourceId(mbSourceId)) {
173-
mbMap.removeSource(mbSourceId);
174-
}
175-
});
176-
}
164+
this._removeStaleMbSourcesAndLayers(mbMap);
177165

178166
let initialBootstrapCompleted = false;
179167
const sourceIds = Object.keys(vectorStyle.sources);

0 commit comments

Comments
 (0)