Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Apr 15, 2020
1 parent 030d1e8 commit 62a3593
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 72 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/maps/public/layers/layer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ export class AbstractLayer implements ILayer {
getMaxZoom(): number;
getMinSourceZoom(): number;
getQuery(): MapQuery;
_removeStaleMbSourcesAndLayers(mbMap: unknown): void;
_requiresPrevSourceCleanup(mbMap: unknown): boolean;
}
20 changes: 20 additions & 0 deletions x-pack/plugins/maps/public/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,26 @@ export class AbstractLayer {
return this._source.getMinZoom();
}

_requiresPrevSourceCleanup() {
return false;
}

_removeStaleMbSourcesAndLayers(mbMap) {
if (this._requiresPrevSourceCleanup(mbMap)) {
const mbStyle = mbMap.getStyle();
mbStyle.layers.forEach(mbLayer => {
if (this.ownsMbLayerId(mbLayer.id)) {
mbMap.removeLayer(mbLayer.id);
}
});
Object.keys(mbStyle.sources).some(mbSourceId => {
if (this.ownsMbSourceId(mbSourceId)) {
mbMap.removeSource(mbSourceId);
}
});
}
}

getAlpha() {
return this._descriptor.alpha;
}
Expand Down
56 changes: 7 additions & 49 deletions x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@

import React from 'react';
import { EuiIcon } from '@elastic/eui';
import { IVectorStyle, VectorStyle } from './styles/vector/vector_style';
import { VectorStyle } from './styles/vector/vector_style';
import { SOURCE_DATA_ID_ORIGIN, LAYER_TYPE } from '../../common/constants';
import { VectorLayer, VectorLayerArguments } from './vector_layer';
import { canSkipSourceUpdate } from './util/can_skip_fetch';
import { ITiledSingleLayerVectorSource, IVectorSource } from './sources/vector_source';
import { ITiledSingleLayerVectorSource } from './sources/vector_source';
import { SyncContext } from '../actions/map_actions';
import { ISource } from './sources/source';
import {
MapFilters,
VectorLayerDescriptor,
VectorSourceRequestMeta,
} from '../../common/descriptor_types';
import { VectorLayerDescriptor, VectorSourceRequestMeta } from '../../common/descriptor_types';
import { MVTSingleLayerVectorSourceConfig } from './sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor';

export class TiledVectorLayer extends VectorLayer {
Expand Down Expand Up @@ -51,24 +47,6 @@ export class TiledVectorLayer extends VectorLayer {
};
}

// _getSearchFilters(
// mapFilters: MapFilters,
// source: IVectorSource,
// style: IVectorStyle
// ): VectorSourceRequestMeta {
// const fieldNames = [...source.getFieldNames(), ...style.getSourceFieldNames()];
//
// const requestMeta: VectorSourceRequestMeta = {
// ...mapFilters,
// applyGlobalQuery: this._source.getApplyGlobalQuery(),
// sourceMeta: this._source.getSyncMeta(),
// fieldNames,
// sourceQuery: this.getQuery(),
// };
//
// return requestMeta;
// }

async _syncMVTUrlTemplate({ startLoading, stopLoading, onLoadError, dataFilters }: SyncContext) {
const requestToken: symbol = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`);
const searchFilters: VectorSourceRequestMeta = this._getSearchFilters(
Expand Down Expand Up @@ -147,13 +125,12 @@ export class TiledVectorLayer extends VectorLayer {
return;
}
const sourceMeta: MVTSingleLayerVectorSourceConfig = sourceDataRequest.getData() as MVTSingleLayerVectorSourceConfig;
const options = { mvtSourceLayer: sourceMeta.layerName };

this._setMbPointsProperties(mbMap, options);
this._setMbLinePolygonProperties(mbMap, options);
this._setMbPointsProperties(mbMap, sourceMeta.layerName);
this._setMbLinePolygonProperties(mbMap, sourceMeta.layerName);
}

_requiresPrevSourceCleanup(mbMap: unknown) {
_requiresPrevSourceCleanup(mbMap: unknown): boolean {
// @ts-ignore
const mbTileSource = mbMap.getSource(this.getId());
if (!mbTileSource) {
Expand All @@ -177,26 +154,7 @@ export class TiledVectorLayer extends VectorLayer {
}

syncLayerWithMB(mbMap: unknown) {
const requiresCleanup = this._requiresPrevSourceCleanup(mbMap);
if (requiresCleanup) {
// @ts-ignore
const mbStyle = mbMap.getStyle();
// @ts-ignore
mbStyle.layers.forEach(mbLayer => {
if (this.ownsMbLayerId(mbLayer.id)) {
// @ts-ignore
mbMap.removeLayer(mbLayer.id);
}
});
// @ts-ignore
Object.keys(mbStyle.sources).some(mbSourceId => {
if (this.ownsMbSourceId(mbSourceId)) {
// @ts-ignore
mbMap.removeSource(mbSourceId);
}
});
}

this._removeStaleMbSourcesAndLayers(mbMap);
this._syncSourceBindingWithMb(mbMap);
this._syncStylePropertiesWithMb(mbMap);
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/maps/public/layers/vector_layer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer {
_syncData(syncContext: SyncContext, source: IVectorSource, style: IVectorStyle): Promise<void>;
ownsMbSourceId(sourceId: string): boolean;
ownsMbLayerId(sourceId: string): boolean;
_setMbPointsProperties(mbMap: unknown, options: unknown): void;
_setMbLinePolygonProperties(mbMap: unknown, options: unknown): void;
_setMbPointsProperties(mbMap: unknown, mvtSourceLayer?: string): void;
_setMbLinePolygonProperties(mbMap: unknown, mvtSourceLayer?: string): void;
getSource(): IVectorSource;
}
16 changes: 8 additions & 8 deletions x-pack/plugins/maps/public/layers/vector_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ export class VectorLayer extends AbstractLayer {
}
}

_setMbPointsProperties(mbMap, options) {
_setMbPointsProperties(mbMap, mvtSourceLayer) {
const pointLayerId = this._getMbPointLayerId();
const symbolLayerId = this._getMbSymbolLayerId();
const pointLayer = mbMap.getLayer(pointLayerId);
Expand All @@ -658,15 +658,15 @@ export class VectorLayer extends AbstractLayer {
if (symbolLayer) {
mbMap.setLayoutProperty(symbolLayerId, 'visibility', 'none');
}
this._setMbCircleProperties(mbMap, options);
this._setMbCircleProperties(mbMap, mvtSourceLayer);
} else {
markerLayerId = symbolLayerId;
textLayerId = symbolLayerId;
if (pointLayer) {
mbMap.setLayoutProperty(pointLayerId, 'visibility', 'none');
mbMap.setLayoutProperty(this._getMbTextLayerId(), 'visibility', 'none');
}
this._setMbSymbolProperties(mbMap, options);
this._setMbSymbolProperties(mbMap, mvtSourceLayer);
}

this.syncVisibilityWithMb(mbMap, markerLayerId);
Expand All @@ -677,7 +677,7 @@ export class VectorLayer extends AbstractLayer {
}
}

_setMbCircleProperties(mbMap, { mvtSourceLayer }) {
_setMbCircleProperties(mbMap, mvtSourceLayer) {
const sourceId = this.getId();
const pointLayerId = this._getMbPointLayerId();
const pointLayer = mbMap.getLayer(pointLayerId);
Expand Down Expand Up @@ -728,7 +728,7 @@ export class VectorLayer extends AbstractLayer {
});
}

_setMbSymbolProperties(mbMap, { mvtSourceLayer }) {
_setMbSymbolProperties(mbMap, mvtSourceLayer) {
const sourceId = this.getId();
const symbolLayerId = this._getMbSymbolLayerId();
const symbolLayer = mbMap.getLayer(symbolLayerId);
Expand Down Expand Up @@ -763,7 +763,7 @@ export class VectorLayer extends AbstractLayer {
});
}

_setMbLinePolygonProperties(mbMap, { mvtSourceLayer }) {
_setMbLinePolygonProperties(mbMap, mvtSourceLayer) {
const sourceId = this.getId();
const fillLayerId = this._getMbPolygonLayerId();
const lineLayerId = this._getMbLineLayerId();
Expand Down Expand Up @@ -815,8 +815,8 @@ export class VectorLayer extends AbstractLayer {
}

_syncStylePropertiesWithMb(mbMap) {
this._setMbPointsProperties(mbMap, {});
this._setMbLinePolygonProperties(mbMap, {});
this._setMbPointsProperties(mbMap);
this._setMbLinePolygonProperties(mbMap);
}

_syncSourceBindingWithMb(mbMap) {
Expand Down
14 changes: 1 addition & 13 deletions x-pack/plugins/maps/public/layers/vector_tile_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,7 @@ export class VectorTileLayer extends TileLayer {
return;
}

if (this._requiresPrevSourceCleanup(mbMap)) {
const mbStyle = mbMap.getStyle();
mbStyle.layers.forEach(mbLayer => {
if (this.ownsMbLayerId(mbLayer.id)) {
mbMap.removeLayer(mbLayer.id);
}
});
Object.keys(mbStyle.sources).some(mbSourceId => {
if (this.ownsMbSourceId(mbSourceId)) {
mbMap.removeSource(mbSourceId);
}
});
}
this._removeStaleMbSourcesAndLayers(mbMap);

let initialBootstrapCompleted = false;
const sourceIds = Object.keys(vectorStyle.sources);
Expand Down

0 comments on commit 62a3593

Please sign in to comment.