From 4ae21f5fd9522920b3580e8bc8eed309e7b3570b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 31 Mar 2020 18:29:18 -0400 Subject: [PATCH 01/50] tmp commit --- .../maps/public/layers/sources/all_sources.js | 2 + .../mvt_single_layer_vector_source.tsx | 83 +++++++ .../mvt_vector_source_editor.tsx | 64 ++++++ .../public/layers/sources/vector_source.d.ts | 9 + .../maps/public/layers/tiled_vector_layer.tsx | 202 ++++++++++++++++++ .../maps/public/layers/vector_layer.d.ts | 12 +- .../maps/public/selectors/map_selectors.js | 3 + x-pack/plugins/maps/common/constants.ts | 2 + 8 files changed, 376 insertions(+), 1 deletion(-) create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx create mode 100644 x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx create mode 100644 x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/all_sources.js b/x-pack/legacy/plugins/maps/public/layers/sources/all_sources.js index 6a518609dd77f..d4e7109cd4d80 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/all_sources.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/all_sources.js @@ -14,6 +14,7 @@ import { KibanaTilemapSource } from './kibana_tilemap_source'; import { ESGeoGridSource } from './es_geo_grid_source'; import { ESSearchSource } from './es_search_source'; import { ESPewPewSource } from './es_pew_pew_source/es_pew_pew_source'; +import { MVTSingleLayerVectorSource } from './mvt_vector_source/mvt_single_layer_vector_source'; export const ALL_SOURCES = [ GeojsonFileSource, @@ -26,4 +27,5 @@ export const ALL_SOURCES = [ KibanaTilemapSource, XYZTMSSource, WMSSource, + MVTSingleLayerVectorSource, ]; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx new file mode 100644 index 0000000000000..c9e7a1ff5ca60 --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -0,0 +1,83 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { i18n } from '@kbn/i18n'; +import uuid from 'uuid/v4'; +import React from 'react'; +import { MVTVectorSourceEditor } from './mvt_vector_source_editor'; +import { AbstractSource } from '../source'; +import { TiledVectorLayer } from '../../tiled_vector_layer'; +import { GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source'; +import { MVT_SINGLE_LAYER } from '../../../../../../../plugins/maps/common/constants'; +import { IField } from '../../fields/field'; + +export class MVTSingleLayerVectorSource extends AbstractSource + implements ITiledSingleLayerVectorSource { + static type = MVT_SINGLE_LAYER; + static title = i18n.translate('xpack.maps.source.tiledSingleLayerVectorTitle', { + defaultMessage: 'Tiled vector', + }); + static description = i18n.translate('xpack.maps.source.tiledSingleLayerVectorDescription', { + defaultMessage: 'Tiled vector with url template', + }); + + static icon = 'logoElasticsearch'; + + static createDescriptor({ urlTemplate }) { + return { + type: MVTSingleLayerVectorSource.type, + id: uuid(), + urlTemplate, + }; + } + + static renderEditor({ onPreviewSource, inspectorAdapters }) { + const onSourceConfigChange = sourceConfig => { + const sourceDescriptor = MVTSingleLayerVectorSource.createDescriptor(sourceConfig); + const source = new MVTSingleLayerVectorSource(sourceDescriptor, inspectorAdapters); + onPreviewSource(source); + }; + return ; + } + + renderSourceSettingsEditor({ onChange }) { + return
No source settings to edit
; + } + + _createDefaultLayerDescriptor(options) { + return TiledVectorLayer.createDescriptor({ + sourceDescriptor: this._descriptor, + ...options, + }); + } + + createDefaultLayer(options) { + return new TiledVectorLayer({ + layerDescriptor: this._createDefaultLayerDescriptor(options), + source: this, + }); + } + + getGeoJsonWithMeta( + layerName: 'string', + searchFilters: unknown[], + registerCancelCallback: (callback: () => void) => void + ): Promise { + throw new Error('Does not implement getGeoJsonWithMeta'); + } + + async getFields(): Promise { + return []; + } + + getFieldByName(fieldName: string) { + return null; + }; + + async getUrlTemplateWithMeta() { + return this._descriptor.urlTemplate; + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx new file mode 100644 index 0000000000000..5360b4f1c313b --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -0,0 +1,64 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React, { Fragment } from 'react'; +import _ from 'lodash'; +import { EuiFieldText, EuiFormRow } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; + +export class MVTVectorSourceEditor extends React.Component { + state = { + mvtInput: '', + layerName: '', + mvtCanPreview: false, + }; + + _sourceConfigChange = _.debounce(() => { + if (this.state.mvtCanPreview && this.state.layerName) { + this.props.onSourceConfigChange({ + urlTemplate: this.state.mvtInput, + layerName: this.state.layerName, + }); + } + }, 2000); + + _handleMVTInputChange(e) { + const url = e.target.value; + + const canPreview = + url.indexOf('{x}') >= 0 && url.indexOf('{y}') >= 0 && url.indexOf('{z}') >= 0; + this.setState( + { + mvtInput: url, + mvtCanPreview: canPreview, + }, + () => this._sourceConfigChange() + ); + } + + _handleLayerNameInputChange(e) { + const layerName = e.target.value; + this.setState( + { + layerName, + }, + () => this._sourceConfigChange() + ); + } + + render() { + const example = `https://tiles.maps.elastic.co/data/v3/{z}/{x}/{y}.pbf`; + return ( + +
{example}
+ + this._handleMVTInputChange(e)} /> + this._handleLayerNameInputChange(e)} /> + +
+ ); + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts index 7a747da244233..a45989212027f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts @@ -38,3 +38,12 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc getFields(): Promise; getFieldByName(fieldName: string): IField; } + +type TiledSingleLayerVectorSourceMeta = { + urlTemplate: string; + layerName: string; +}; + +export interface ITiledSingleLayerVectorSource extends IVectorSource { + getUrlTemplateWithMeta(): Promise; +} diff --git a/x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx new file mode 100644 index 0000000000000..a56a7ec714f7d --- /dev/null +++ b/x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -0,0 +1,202 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { EuiIcon } from '@elastic/eui'; +import _ from 'lodash'; +import { IVectorStyle, VectorStyle } from './styles/vector/vector_style'; +import { + SOURCE_DATA_ID_ORIGIN, + LAYER_TYPE, + FEATURE_ID_PROPERTY_NAME, +} from '../../common/constants'; +import { VectorLayer, VectorLayerArguments } from './vector_layer'; +import { canSkipSourceUpdate } from './util/can_skip_fetch'; +import { ITiledSingleLayerVectorSource } from './sources/vector_source'; +import { SyncContext } from '../actions/map_actions'; + +export class TiledVectorLayer extends VectorLayer { + static type = LAYER_TYPE.TILED_VECTOR; + + static createDescriptor(options, mapColors) { + const layerDescriptor = super.createDescriptor(options); + layerDescriptor.type = TiledVectorLayer.type; + + if (!options.style) { + const styleProperties = VectorStyle.createDefaultStyleProperties(mapColors); + layerDescriptor.style = VectorStyle.createDescriptor(styleProperties); + } + + return layerDescriptor; + } + + private readonly _source: ITiledSingleLayerVectorSource; + private readonly _style: IVectorStyle; + + constructor(vectorArgs: VectorLayerArguments) { + if (vectorArgs.joins) { + throw new Error('Tiled vector layers do not support joins'); + } + super({ layerDescriptor: vectorArgs.layerDescriptor, source: vectorArgs.source, joins: [] }); + } + + destroy() { + if (this._source) { + this._source.destroy(); + } + } + + getCustomIconAndTooltipContent() { + return { + icon: , + }; + } + + _getSearchFilters(dataFilters) { + const fieldNames = [...this._source.getFieldNames(), ...this._style.getSourceFieldNames()]; + + return { + ...dataFilters, + fieldNames: _.uniq(fieldNames).sort(), + sourceQuery: this.getQuery(), + applyGlobalQuery: this._source.getApplyGlobalQuery(), + }; + } + + async _syncMVTUrlTemplate({ + startLoading, + stopLoading, + onLoadError, + registerCancelCallback, + dataFilters, + }: SyncContext) { + const requestToken = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`); + const searchFilters = this._getSearchFilters(dataFilters); + const prevDataRequest = this.getSourceDataRequest(); + const canSkip = await canSkipSourceUpdate({ + source: this._source, + prevDataRequest, + nextMeta: searchFilters, + }); + if (canSkip) { + return null; + } + + startLoading(SOURCE_DATA_ID_ORIGIN, requestToken, searchFilters); + try { + const templateWithMeta = await this._source.getUrlTemplateWithMeta(searchFilters); + const url = templateWithMeta.url; + stopLoading(SOURCE_DATA_ID_ORIGIN, requestToken, url, {}); + } catch (error) { + onLoadError(SOURCE_DATA_ID_ORIGIN, requestToken, error.message); + } + } + + async syncData(syncContext) { + if (!this.isVisible() || !this.showAtZoomLevel(syncContext.dataFilters.zoom)) { + return; + } + + await this._syncSourceStyleMeta(syncContext, this._source, this._style); + await this._syncSourceFormatters(syncContext, this._source, this._style); + await this._syncMVTUrlTemplate(syncContext); + } + + _syncSourceBindingWithMb(mbMap) { + const mbSource = mbMap.getSource(this.getId()); + if (!mbSource) { + const sourceDataRequest = this.getSourceDataRequest(); + if (!sourceDataRequest) { + // this is possible if the layer was invisible at startup. + // the actions will not perform any data=syncing as an optimization when a layer is invisible + // when turning the layer back into visible, it's possible the url has not been resovled yet. + return; + } + + const url = sourceDataRequest.getData(); + if (!url) { + return; + } + + const sourceId = this.getId(); + + // @ts-ignore + mbMap.addSource(sourceId, { + type: 'vector', + tiles: [url], + }); + } + } + + _syncStylePropertiesWithMb(mbMap) { + const mbSource = mbMap.getSource(this.getId()); + if (!mbSource) { + return; + } + + const options = { mvtSourceLayer: this._source.getMvtSourceLayer() }; + this._setMbPointsProperties(mbMap, options); + this._setMbLinePolygonProperties(mbMap, options); + } + + _requiresPrevSourceCleanup(mbMap) { + const tileSource = mbMap.getSource(this.getId()); + if (!tileSource) { + return false; + } + const dataRequest = this.getSourceDataRequest(); + if (!dataRequest) { + return false; + } + const newUrl = dataRequest.getData(); + if (tileSource.tiles[0] === newUrl) { + // TileURL captures all the state. If this does not change, no updates are required. + return false; + } + + return true; + } + + syncLayerWithMB(mbMap) { + const requiresCleanup = this._requiresPrevSourceCleanup(mbMap); + if (requiresCleanup) { + 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._syncSourceBindingWithMb(mbMap); + this._syncStylePropertiesWithMb(mbMap); + } + + getJoins() { + return []; + } + + getGeometryByFeatureId(featureId, meta) { + return null; + } + + async getFeaturePropertiesByFeatureId(featureId, meta) { + const test = await this._source.filterAndFormatPropertiesToHtml({ + _id: meta.docId, + _index: meta.indexName, + }); + return test; + } + + async loadPreIndexedShapeByFeatureId(featureId, meta) { + return null; + } +} diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts index 70fd9927b7732..549470e685457 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts @@ -20,7 +20,7 @@ import { SyncContext } from '../actions/map_actions'; type VectorLayerArguments = { source: IVectorSource; - joins: IJoin[]; + joins?: IJoin[]; layerDescriptor: VectorLayerDescriptor; }; @@ -44,6 +44,16 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { getFields(): Promise; getStyleEditorFields(): Promise; getValidJoins(): IJoin[]; + _syncSourceStyleMeta( + syncContext: SyncContext, + source: IVectorSource, + style: IVectorStyle + ): Promise; + _syncSourceFormatters( + syncContext: SyncContext, + source: IVectorSource, + style: IVectorStyle + ): Promise; _getSearchFilters( dataFilters: MapFilters, source: IVectorSource, diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index 61eea2d172ae4..078a80043b9ff 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -11,6 +11,7 @@ import { VectorTileLayer } from '../layers/vector_tile_layer'; import { VectorLayer } from '../layers/vector_layer'; import { HeatmapLayer } from '../layers/heatmap_layer'; import { BlendedVectorLayer } from '../layers/blended_vector_layer'; +import { TiledVectorLayer } from '../layers/tiled_vector_layer'; import { ALL_SOURCES } from '../layers/sources/all_sources'; import { getTimeFilter } from '../kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths @@ -43,6 +44,8 @@ function createLayerInstance(layerDescriptor, inspectorAdapters) { return new HeatmapLayer({ layerDescriptor, source }); case BlendedVectorLayer.type: return new BlendedVectorLayer({ layerDescriptor, source }); + case TiledVectorLayer.type: + return new TiledVectorLayer({ layerDescriptor, source }); default: throw new Error(`Unrecognized layerType ${layerDescriptor.type}`); } diff --git a/x-pack/plugins/maps/common/constants.ts b/x-pack/plugins/maps/common/constants.ts index 30a3350ad754e..528fbcf691762 100644 --- a/x-pack/plugins/maps/common/constants.ts +++ b/x-pack/plugins/maps/common/constants.ts @@ -49,6 +49,7 @@ export enum LAYER_TYPE { VECTOR_TILE = 'VECTOR_TILE', HEATMAP = 'HEATMAP', BLENDED_VECTOR = 'BLENDED_VECTOR', + TILED_VECTOR = 'TILED_VECTOR', } export enum SORT_ORDER { @@ -62,6 +63,7 @@ export const ES_GEO_GRID = 'ES_GEO_GRID'; export const ES_SEARCH = 'ES_SEARCH'; export const ES_PEW_PEW = 'ES_PEW_PEW'; export const EMS_XYZ = 'EMS_XYZ'; // identifies a custom TMS source. Name is a little unfortunate. +export const MVT_SINGLE_LAYER = 'MVT_SINGLE_LAYER'; export enum FIELD_ORIGIN { SOURCE = 'source', From fec373b08a7e6b6f3843b4103472a587d33c87bf Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 6 Apr 2020 11:19:18 -0400 Subject: [PATCH 02/50] more boiler --- .../maps/public/layers/load_layer_wizards.js | 2 + .../mvt_single_layer_vector_source.tsx | 45 ++++++++++++++----- .../mvt_vector_source_editor.tsx | 15 ++++--- .../maps/public/layers/sources/source.js | 10 ++++- .../public/layers/sources/vector_source.d.ts | 2 + .../maps/public/layers/tiled_vector_layer.tsx | 26 ++++++++--- .../maps/public/layers/vector_layer.d.ts | 2 - 7 files changed, 77 insertions(+), 25 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/load_layer_wizards.js b/x-pack/legacy/plugins/maps/public/layers/load_layer_wizards.js index d0169165eaa35..29846cf2ec4bc 100644 --- a/x-pack/legacy/plugins/maps/public/layers/load_layer_wizards.js +++ b/x-pack/legacy/plugins/maps/public/layers/load_layer_wizards.js @@ -15,6 +15,7 @@ import { kibanaRegionMapLayerWizardConfig } from './sources/kibana_regionmap_sou import { kibanaBasemapLayerWizardConfig } from './sources/kibana_tilemap_source'; import { tmsLayerWizardConfig } from './sources/xyz_tms_source'; import { wmsLayerWizardConfig } from './sources/wms_source'; +import { mvtVectorSourceWizardConfig } from './sources/mvt_vector_source/mvt_single_layer_vector_source'; // Registration order determines display order registerLayerWizard(uploadLayerWizardConfig); @@ -28,3 +29,4 @@ registerLayerWizard(kibanaRegionMapLayerWizardConfig); registerLayerWizard(kibanaBasemapLayerWizardConfig); registerLayerWizard(tmsLayerWizardConfig); registerLayerWizard(wmsLayerWizardConfig); +registerLayerWizard(mvtVectorSourceWizardConfig); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index c9e7a1ff5ca60..70bdfe4e59895 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -13,6 +13,11 @@ import { TiledVectorLayer } from '../../tiled_vector_layer'; import { GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source'; import { MVT_SINGLE_LAYER } from '../../../../../../../plugins/maps/common/constants'; import { IField } from '../../fields/field'; +import { registerSource } from '../source_registry'; + +const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle', { + defaultMessage: 'XYZ Vector Tile Layer', +}); export class MVTSingleLayerVectorSource extends AbstractSource implements ITiledSingleLayerVectorSource { @@ -34,15 +39,6 @@ export class MVTSingleLayerVectorSource extends AbstractSource }; } - static renderEditor({ onPreviewSource, inspectorAdapters }) { - const onSourceConfigChange = sourceConfig => { - const sourceDescriptor = MVTSingleLayerVectorSource.createDescriptor(sourceConfig); - const source = new MVTSingleLayerVectorSource(sourceDescriptor, inspectorAdapters); - onPreviewSource(source); - }; - return ; - } - renderSourceSettingsEditor({ onChange }) { return
No source settings to edit
; } @@ -75,9 +71,38 @@ export class MVTSingleLayerVectorSource extends AbstractSource getFieldByName(fieldName: string) { return null; - }; + } async getUrlTemplateWithMeta() { return this._descriptor.urlTemplate; } + + getSupportedShapeTypes() { + return []; + } + + canFormatFeatureProperties() { + return false; + } } + +registerSource({ + ConstructorFunction: MVTSingleLayerVectorSource, + type: MVT_SINGLE_LAYER, +}); + +export const mvtVectorSourceWizardConfig = { + description: i18n.translate('xpack.maps.source.mvtVectorSourceWizard', { + defaultMessage: 'Vector source wizard', + }), + icon: 'grid', + renderWizard: ({ onPreviewSource, inspectorAdapters }) => { + const onSourceConfigChange = sourceConfig => { + const sourceDescriptor = MVTSingleLayerVectorSource.createDescriptor(sourceConfig); + const source = new MVTSingleLayerVectorSource(sourceDescriptor, inspectorAdapters); + onPreviewSource(source); + }; + return ; + }, + title: sourceTitle, +}; diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index 5360b4f1c313b..d488929df849f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -7,11 +7,10 @@ import React, { Fragment } from 'react'; import _ from 'lodash'; import { EuiFieldText, EuiFormRow } from '@elastic/eui'; -import { i18n } from '@kbn/i18n'; export class MVTVectorSourceEditor extends React.Component { state = { - mvtInput: '', + urlTemplate: '', layerName: '', mvtCanPreview: false, }; @@ -19,20 +18,20 @@ export class MVTVectorSourceEditor extends React.Component { _sourceConfigChange = _.debounce(() => { if (this.state.mvtCanPreview && this.state.layerName) { this.props.onSourceConfigChange({ - urlTemplate: this.state.mvtInput, + urlTemplate: this.state.urlTemplate, layerName: this.state.layerName, }); } }, 2000); - _handleMVTInputChange(e) { + _handleUrlTemplateChange(e) { const url = e.target.value; const canPreview = url.indexOf('{x}') >= 0 && url.indexOf('{y}') >= 0 && url.indexOf('{z}') >= 0; this.setState( { - mvtInput: url, + urlTemplate: url, mvtCanPreview: canPreview, }, () => this._sourceConfigChange() @@ -55,8 +54,10 @@ export class MVTVectorSourceEditor extends React.Component {
{example}
- this._handleMVTInputChange(e)} /> - this._handleLayerNameInputChange(e)} /> + this._handleUrlTemplateChange(e)} /> + + + this._handleLayerNameInputChange(e)} />
); diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/source.js b/x-pack/legacy/plugins/maps/public/layers/sources/source.js index b6b6c10831bb5..3e0ff19ff541d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/source.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/source.js @@ -79,7 +79,7 @@ export class AbstractSource { return false; } - isQueryAware() { + async isTimeAware() { return false; } @@ -107,6 +107,14 @@ export class AbstractSource { return []; } + isFilterByMapBounds() { + return false; + } + + isQueryAware() { + return false; + } + getGeoGridPrecision() { return 0; } diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts index f1f9213f4403f..9b37212e5170e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/sources/vector_source.d.ts @@ -43,6 +43,8 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc getFields(): Promise; getFieldByName(fieldName: string): IField; + getSupportedShapeTypes(): VECTOR_SHAPE_TYPES[]; + canFormatFeatureProperties() : boolean; } type TiledSingleLayerVectorSourceMeta = { diff --git a/x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx index a56a7ec714f7d..cd23e1e1e5a7e 100644 --- a/x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -33,14 +33,17 @@ export class TiledVectorLayer extends VectorLayer { return layerDescriptor; } - private readonly _source: ITiledSingleLayerVectorSource; - private readonly _style: IVectorStyle; + private readonly _source: ITiledSingleLayerVectorSource; //downcast to the more specific type constructor(vectorArgs: VectorLayerArguments) { - if (vectorArgs.joins) { + if (vectorArgs.joins && vectorArgs.joins.length) { throw new Error('Tiled vector layers do not support joins'); } - super({ layerDescriptor: vectorArgs.layerDescriptor, source: vectorArgs.source, joins: [] }); + super(vectorArgs); + + //reassignment is required due since _source is a shadowed property + // and in the transpiled JS-code, the .source assignment in super() is getting voided in this constructor. + this._source = vectorArgs.source; } destroy() { @@ -73,6 +76,7 @@ export class TiledVectorLayer extends VectorLayer { registerCancelCallback, dataFilters, }: SyncContext) { + console.log('sync mvt template'); const requestToken = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`); const searchFilters = this._getSearchFilters(dataFilters); const prevDataRequest = this.getSourceDataRequest(); @@ -85,9 +89,11 @@ export class TiledVectorLayer extends VectorLayer { return null; } + console.log('start'); startLoading(SOURCE_DATA_ID_ORIGIN, requestToken, searchFilters); try { - const templateWithMeta = await this._source.getUrlTemplateWithMeta(searchFilters); + const templateWithMeta = await this._source.getUrlTemplateWithMeta(); + console.log('template with meta', templateWithMeta); const url = templateWithMeta.url; stopLoading(SOURCE_DATA_ID_ORIGIN, requestToken, url, {}); } catch (error) { @@ -96,6 +102,7 @@ export class TiledVectorLayer extends VectorLayer { } async syncData(syncContext) { + console.log('sunc ddata', syncContext); if (!this.isVisible() || !this.showAtZoomLevel(syncContext.dataFilters.zoom)) { return; } @@ -107,16 +114,20 @@ export class TiledVectorLayer extends VectorLayer { _syncSourceBindingWithMb(mbMap) { const mbSource = mbMap.getSource(this.getId()); + console.log('mbs', mbSource); if (!mbSource) { const sourceDataRequest = this.getSourceDataRequest(); if (!sourceDataRequest) { + console.log('mno source data request', sourceDataRequest); // this is possible if the layer was invisible at startup. // the actions will not perform any data=syncing as an optimization when a layer is invisible // when turning the layer back into visible, it's possible the url has not been resovled yet. return; } + ; const url = sourceDataRequest.getData(); + console.log(url); if (!url) { return; } @@ -132,12 +143,14 @@ export class TiledVectorLayer extends VectorLayer { } _syncStylePropertiesWithMb(mbMap) { + console.log('sunc style props', mbMap); const mbSource = mbMap.getSource(this.getId()); if (!mbSource) { return; } const options = { mvtSourceLayer: this._source.getMvtSourceLayer() }; + this._setMbPointsProperties(mbMap, options); this._setMbLinePolygonProperties(mbMap, options); } @@ -161,7 +174,10 @@ export class TiledVectorLayer extends VectorLayer { } syncLayerWithMB(mbMap) { + console.log('sunc kayer with mb', mbMap); + const requiresCleanup = this._requiresPrevSourceCleanup(mbMap); + console.log('reclenaup', requiresCleanup); if (requiresCleanup) { const mbStyle = mbMap.getStyle(); mbStyle.layers.forEach(mbLayer => { diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts index 549470e685457..1ba1b5bbfd96c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.d.ts @@ -37,8 +37,6 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { ): VectorLayerDescriptor; protected readonly _source: IVectorSource; - protected readonly _style: IVectorStyle; - constructor(options: VectorLayerArguments); getFields(): Promise; From f6fd50e449c21c4f7289a93135ee7f90bde96949 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 6 Apr 2020 12:13:19 -0400 Subject: [PATCH 03/50] more boilerplate --- .../mvt_single_layer_vector_source.tsx | 13 +++-- .../maps/public/layers/tiled_vector_layer.tsx | 38 ++++++------- .../maps/public/layers/vector_layer.js | 55 +++++++++++++------ 3 files changed, 64 insertions(+), 42 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 70bdfe4e59895..fc1824b986d5c 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/legacy/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -10,7 +10,7 @@ import React from 'react'; import { MVTVectorSourceEditor } from './mvt_vector_source_editor'; import { AbstractSource } from '../source'; import { TiledVectorLayer } from '../../tiled_vector_layer'; -import { GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source'; +import {GeoJsonWithMeta, ITiledSingleLayerVectorSource, TiledSingleLayerVectorSourceMeta} from '../vector_source'; import { MVT_SINGLE_LAYER } from '../../../../../../../plugins/maps/common/constants'; import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; @@ -31,11 +31,12 @@ export class MVTSingleLayerVectorSource extends AbstractSource static icon = 'logoElasticsearch'; - static createDescriptor({ urlTemplate }) { + static createDescriptor({ urlTemplate, layerName }) { return { type: MVTSingleLayerVectorSource.type, id: uuid(), urlTemplate, + layerName, }; } @@ -73,8 +74,12 @@ export class MVTSingleLayerVectorSource extends AbstractSource return null; } - async getUrlTemplateWithMeta() { - return this._descriptor.urlTemplate; + async getUrlTemplateWithMeta(): TiledSingleLayerVectorSourceMeta { + return { + urlTemplate: this._descriptor.urlTemplate, + layerName: this._descriptor.layerName, + + }; } getSupportedShapeTypes() { diff --git a/x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx index cd23e1e1e5a7e..23c1526cc0b4d 100644 --- a/x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/legacy/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -15,7 +15,10 @@ import { } from '../../common/constants'; import { VectorLayer, VectorLayerArguments } from './vector_layer'; import { canSkipSourceUpdate } from './util/can_skip_fetch'; -import { ITiledSingleLayerVectorSource } from './sources/vector_source'; +import { + ITiledSingleLayerVectorSource, + TiledSingleLayerVectorSourceMeta, +} from './sources/vector_source'; import { SyncContext } from '../actions/map_actions'; export class TiledVectorLayer extends VectorLayer { @@ -33,7 +36,7 @@ export class TiledVectorLayer extends VectorLayer { return layerDescriptor; } - private readonly _source: ITiledSingleLayerVectorSource; //downcast to the more specific type + private readonly _source: ITiledSingleLayerVectorSource; // downcast to the more specific type constructor(vectorArgs: VectorLayerArguments) { if (vectorArgs.joins && vectorArgs.joins.length) { @@ -41,7 +44,7 @@ export class TiledVectorLayer extends VectorLayer { } super(vectorArgs); - //reassignment is required due since _source is a shadowed property + // reassignment is required due since _source is a shadowed property // and in the transpiled JS-code, the .source assignment in super() is getting voided in this constructor. this._source = vectorArgs.source; } @@ -76,7 +79,6 @@ export class TiledVectorLayer extends VectorLayer { registerCancelCallback, dataFilters, }: SyncContext) { - console.log('sync mvt template'); const requestToken = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`); const searchFilters = this._getSearchFilters(dataFilters); const prevDataRequest = this.getSourceDataRequest(); @@ -89,20 +91,16 @@ export class TiledVectorLayer extends VectorLayer { return null; } - console.log('start'); startLoading(SOURCE_DATA_ID_ORIGIN, requestToken, searchFilters); try { - const templateWithMeta = await this._source.getUrlTemplateWithMeta(); - console.log('template with meta', templateWithMeta); - const url = templateWithMeta.url; - stopLoading(SOURCE_DATA_ID_ORIGIN, requestToken, url, {}); + const templateWithMeta: TiledSingleLayerVectorSourceMeta = await this._source.getUrlTemplateWithMeta(); + stopLoading(SOURCE_DATA_ID_ORIGIN, requestToken, templateWithMeta, {}); } catch (error) { onLoadError(SOURCE_DATA_ID_ORIGIN, requestToken, error.message); } } async syncData(syncContext) { - console.log('sunc ddata', syncContext); if (!this.isVisible() || !this.showAtZoomLevel(syncContext.dataFilters.zoom)) { return; } @@ -114,21 +112,17 @@ export class TiledVectorLayer extends VectorLayer { _syncSourceBindingWithMb(mbMap) { const mbSource = mbMap.getSource(this.getId()); - console.log('mbs', mbSource); if (!mbSource) { const sourceDataRequest = this.getSourceDataRequest(); if (!sourceDataRequest) { - console.log('mno source data request', sourceDataRequest); // this is possible if the layer was invisible at startup. // the actions will not perform any data=syncing as an optimization when a layer is invisible // when turning the layer back into visible, it's possible the url has not been resovled yet. return; } - ; - const url = sourceDataRequest.getData(); - console.log(url); - if (!url) { + const sourceMeta: TiledSingleLayerVectorSourceMeta = sourceDataRequest.getData() as TiledSingleLayerVectorSourceMeta; + if (!sourceMeta) { return; } @@ -137,19 +131,23 @@ export class TiledVectorLayer extends VectorLayer { // @ts-ignore mbMap.addSource(sourceId, { type: 'vector', - tiles: [url], + tiles: [sourceMeta.urlTemplate], }); } } _syncStylePropertiesWithMb(mbMap) { - console.log('sunc style props', mbMap); const mbSource = mbMap.getSource(this.getId()); if (!mbSource) { return; } - const options = { mvtSourceLayer: this._source.getMvtSourceLayer() }; + const sourceDataRequest = this.getSourceDataRequest(); + if (!sourceDataRequest) { + return; + } + const sourceMeta: TiledSingleLayerVectorSourceMeta = sourceDataRequest.getData() as TiledSingleLayerVectorSourceMeta; + const options = { mvtSourceLayer: sourceMeta.layerName }; this._setMbPointsProperties(mbMap, options); this._setMbLinePolygonProperties(mbMap, options); @@ -174,10 +172,8 @@ export class TiledVectorLayer extends VectorLayer { } syncLayerWithMB(mbMap) { - console.log('sunc kayer with mb', mbMap); const requiresCleanup = this._requiresPrevSourceCleanup(mbMap); - console.log('reclenaup', requiresCleanup); if (requiresCleanup) { const mbStyle = mbMap.getStyle(); mbStyle.layers.forEach(mbLayer => { diff --git a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js index d606420909281..2b438d056d077 100644 --- a/x-pack/legacy/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/legacy/plugins/maps/public/layers/vector_layer.js @@ -641,7 +641,7 @@ export class VectorLayer extends AbstractLayer { } } - _setMbPointsProperties(mbMap) { + _setMbPointsProperties(mbMap, options) { const pointLayerId = this._getMbPointLayerId(); const symbolLayerId = this._getMbSymbolLayerId(); const pointLayer = mbMap.getLayer(pointLayerId); @@ -658,7 +658,7 @@ export class VectorLayer extends AbstractLayer { if (symbolLayer) { mbMap.setLayoutProperty(symbolLayerId, 'visibility', 'none'); } - this._setMbCircleProperties(mbMap); + this._setMbCircleProperties(mbMap, options); } else { markerLayerId = symbolLayerId; textLayerId = symbolLayerId; @@ -677,27 +677,36 @@ export class VectorLayer extends AbstractLayer { } } - _setMbCircleProperties(mbMap) { + _setMbCircleProperties(mbMap, { mvtSourceLayer }) { const sourceId = this.getId(); const pointLayerId = this._getMbPointLayerId(); const pointLayer = mbMap.getLayer(pointLayerId); if (!pointLayer) { - mbMap.addLayer({ + const mbLayer = { id: pointLayerId, type: 'circle', source: sourceId, paint: {}, - }); + }; + + if (mvtSourceLayer) { + mbLayer['source-layer'] = mvtSourceLayer; + } + mbMap.addLayer(mbLayer); } const textLayerId = this._getMbTextLayerId(); const textLayer = mbMap.getLayer(textLayerId); if (!textLayer) { - mbMap.addLayer({ + const mbLayer = { id: textLayerId, type: 'symbol', source: sourceId, - }); + }; + if (mvtSourceLayer) { + mbLayer['source-layer'] = mvtSourceLayer; + } + mbMap.addLayer(mbLayer); } const filterExpr = getPointFilterExpression(this._hasJoins()); @@ -719,17 +728,21 @@ export class VectorLayer extends AbstractLayer { }); } - _setMbSymbolProperties(mbMap) { + _setMbSymbolProperties(mbMap, { mvtSourceLayer }) { const sourceId = this.getId(); const symbolLayerId = this._getMbSymbolLayerId(); const symbolLayer = mbMap.getLayer(symbolLayerId); if (!symbolLayer) { - mbMap.addLayer({ + const mbLayer = { id: symbolLayerId, type: 'symbol', source: sourceId, - }); + }; + if (mvtSourceLayer) { + mbLayer['source-layer'] = mvtSourceLayer; + } + mbMap.addLayer(mbLayer); } const filterExpr = getPointFilterExpression(this._hasJoins()); @@ -750,26 +763,34 @@ export class VectorLayer extends AbstractLayer { }); } - _setMbLinePolygonProperties(mbMap) { + _setMbLinePolygonProperties(mbMap, { mvtSourceLayer }) { const sourceId = this.getId(); const fillLayerId = this._getMbPolygonLayerId(); const lineLayerId = this._getMbLineLayerId(); const hasJoins = this._hasJoins(); if (!mbMap.getLayer(fillLayerId)) { - mbMap.addLayer({ + const mbLayer = { id: fillLayerId, type: 'fill', source: sourceId, paint: {}, - }); + }; + if (mvtSourceLayer) { + mbLayer['source-layer'] = mvtSourceLayer; + } + mbMap.addLayer(mbLayer); } if (!mbMap.getLayer(lineLayerId)) { - mbMap.addLayer({ + const mbLayer = { id: lineLayerId, type: 'line', source: sourceId, paint: {}, - }); + }; + if (mvtSourceLayer) { + mbLayer['source-layer'] = mvtSourceLayer; + } + mbMap.addLayer(mbLayer); } this.getCurrentStyle().setMBPaintProperties({ alpha: this.getAlpha(), @@ -794,8 +815,8 @@ export class VectorLayer extends AbstractLayer { } _syncStylePropertiesWithMb(mbMap) { - this._setMbPointsProperties(mbMap); - this._setMbLinePolygonProperties(mbMap); + this._setMbPointsProperties(mbMap, {}); + this._setMbLinePolygonProperties(mbMap, {}); } _syncSourceBindingWithMb(mbMap) { From c5ab5ccc8ed9999725c7c767e29baa74420bd298 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 6 Apr 2020 17:20:57 -0400 Subject: [PATCH 04/50] show constants --- .../mvt_vector_source/mvt_single_layer_vector_source.tsx | 2 +- x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 768fb19eb79a8..f59111d864fc2 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -15,7 +15,7 @@ import { ITiledSingleLayerVectorSource, TiledSingleLayerVectorSourceMeta, } from '../vector_source'; -import { MVT_SINGLE_LAYER } from '../../../../../../../plugins/maps/common/constants'; +import { MVT_SINGLE_LAYER } from '../../../../common/constants'; import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index 0ce14a564c46b..feaf0f9f7c42f 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -20,7 +20,7 @@ import { SyncContext } from '../actions/map_actions'; export class TiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; - static createDescriptor(options, mapColors) { + static createDescriptor(opMVtions, mapColors) { const layerDescriptor = super.createDescriptor(options); layerDescriptor.type = TiledVectorLayer.type; From b6384116ce276e00655087c5bf301563d48adf00 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 6 Apr 2020 18:05:17 -0400 Subject: [PATCH 05/50] fix typo --- .../mvt_vector_source/mvt_single_layer_vector_source.tsx | 2 +- x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index f59111d864fc2..3265907ccf747 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -45,7 +45,7 @@ export class MVTSingleLayerVectorSource extends AbstractSource } renderSourceSettingsEditor({ onChange }) { - return
No source settings to edit
; + return null; } _createDefaultLayerDescriptor(options) { diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index feaf0f9f7c42f..0ce14a564c46b 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -20,7 +20,7 @@ import { SyncContext } from '../actions/map_actions'; export class TiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; - static createDescriptor(opMVtions, mapColors) { + static createDescriptor(options, mapColors) { const layerDescriptor = super.createDescriptor(options); layerDescriptor.type = TiledVectorLayer.type; From c9468cbf4f0ab0ccd750200c71b071f8819b6392 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 6 Apr 2020 18:13:00 -0400 Subject: [PATCH 06/50] allow all shape types --- .../mvt_vector_source/mvt_single_layer_vector_source.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 3265907ccf747..9d47eb2f94677 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -15,7 +15,7 @@ import { ITiledSingleLayerVectorSource, TiledSingleLayerVectorSourceMeta, } from '../vector_source'; -import { MVT_SINGLE_LAYER } from '../../../../common/constants'; +import { ES_GEO_FIELD_TYPE, MVT_SINGLE_LAYER } from '../../../../common/constants'; import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; @@ -85,8 +85,8 @@ export class MVTSingleLayerVectorSource extends AbstractSource }; } - getSupportedShapeTypes() { - return []; + async getSupportedShapeTypes() { + return [VECTOR_SHAPE_TYPES.POINT, VECTOR_SHAPE_TYPES.LINE, VECTOR_SHAPE_TYPES.POLYGON]; } canFormatFeatureProperties() { From 8caba58a0c40f882568121ee2d49a96ec9246519 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 6 Apr 2020 18:18:40 -0400 Subject: [PATCH 07/50] enable point styling --- .../mvt_single_layer_vector_source.tsx | 3 ++- ...vector_feature_types.js => vector_feature_types.ts} | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) rename x-pack/plugins/maps/public/layers/sources/{vector_feature_types.js => vector_feature_types.ts} (71%) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 9d47eb2f94677..908e168413386 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -15,7 +15,8 @@ import { ITiledSingleLayerVectorSource, TiledSingleLayerVectorSourceMeta, } from '../vector_source'; -import { ES_GEO_FIELD_TYPE, MVT_SINGLE_LAYER } from '../../../../common/constants'; +import { MVT_SINGLE_LAYER } from '../../../../common/constants'; +import { VECTOR_SHAPE_TYPES } from '../vector_feature_types'; import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; diff --git a/x-pack/plugins/maps/public/layers/sources/vector_feature_types.js b/x-pack/plugins/maps/public/layers/sources/vector_feature_types.ts similarity index 71% rename from x-pack/plugins/maps/public/layers/sources/vector_feature_types.js rename to x-pack/plugins/maps/public/layers/sources/vector_feature_types.ts index cc5f30389c4f3..9f03357e17dad 100644 --- a/x-pack/plugins/maps/public/layers/sources/vector_feature_types.js +++ b/x-pack/plugins/maps/public/layers/sources/vector_feature_types.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -export const VECTOR_SHAPE_TYPES = { - POINT: 'POINT', - LINE: 'LINE', - POLYGON: 'POLYGON', -}; +export enum VECTOR_SHAPE_TYPES { + POINT = 'POINT', + LINE = 'LINE', + POLYGON = 'POLYGON', +} From fe67239aa3401fe573a56d657d04ec638ca7eb7d Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 6 Apr 2020 18:44:45 -0400 Subject: [PATCH 08/50] add points --- .../maps/public/actions/map_actions.js | 3 +++ .../vector/components/vector_style_editor.js | 26 +++++++++++-------- .../maps/public/layers/vector_layer.js | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/actions/map_actions.js b/x-pack/legacy/plugins/maps/public/actions/map_actions.js index aa55cf0808ef2..32dbab2e34e4c 100644 --- a/x-pack/legacy/plugins/maps/public/actions/map_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/map_actions.js @@ -861,16 +861,19 @@ export function updateLayerStyle(layerId, styleDescriptor) { export function updateStyleMeta(layerId) { return async (dispatch, getState) => { + console.log('update style meta'); const layer = getLayerById(layerId, getState()); if (!layer) { return; } const sourceDataRequest = layer.getSourceDataRequest(); + console.log('sourcedatareq', sourceDataRequest); const style = layer.getCurrentStyle(); if (!style || !sourceDataRequest) { return; } const styleMeta = await style.pluckStyleMetaFromSourceDataRequest(sourceDataRequest); + console.log('style meta', styleMeta); dispatch({ type: SET_LAYER_STYLE_META, layerId, diff --git a/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index 6cece5efb3a5d..ec6374c24a1a0 100644 --- a/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -37,7 +37,7 @@ export class VectorStyleEditor extends Component { defaultDynamicProperties: getDefaultDynamicProperties(), defaultStaticProperties: getDefaultStaticProperties(), supportedFeatures: undefined, - selectedFeatureType: undefined, + selectedFeature: null, }; componentWillUnmount() { @@ -91,18 +91,21 @@ export class VectorStyleEditor extends Component { return; } - let selectedFeature = VECTOR_SHAPE_TYPES.POLYGON; - if (this.props.isPointsOnly) { - selectedFeature = VECTOR_SHAPE_TYPES.POINT; - } else if (this.props.isLinesOnly) { - selectedFeature = VECTOR_SHAPE_TYPES.LINE; + if (!_.isEqual(supportedFeatures, this.state.supportedFeatures)) { + this.setState({ supportedFeatures }); } - if ( - !_.isEqual(supportedFeatures, this.state.supportedFeatures) || - selectedFeature !== this.state.selectedFeature - ) { - this.setState({ supportedFeatures, selectedFeature }); + //todo: this should be fixed separately + if (this.state.selectedFeature === null) { + let selectedFeature = VECTOR_SHAPE_TYPES.POLYGON; + if (this.props.isPointsOnly) { + selectedFeature = VECTOR_SHAPE_TYPES.POINT; + } else if (this.props.isLinesOnly) { + selectedFeature = VECTOR_SHAPE_TYPES.LINE; + } + this.setState({ + selectedFeature: selectedFeature, + }); } } @@ -111,6 +114,7 @@ export class VectorStyleEditor extends Component { } _handleSelectedFeatureChange = selectedFeature => { + console.log('sel feature change', selectedFeature); this.setState({ selectedFeature }); }; diff --git a/x-pack/plugins/maps/public/layers/vector_layer.js b/x-pack/plugins/maps/public/layers/vector_layer.js index 2b438d056d077..91091f62ae086 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/plugins/maps/public/layers/vector_layer.js @@ -666,7 +666,7 @@ export class VectorLayer extends AbstractLayer { mbMap.setLayoutProperty(pointLayerId, 'visibility', 'none'); mbMap.setLayoutProperty(this._getMbTextLayerId(), 'visibility', 'none'); } - this._setMbSymbolProperties(mbMap); + this._setMbSymbolProperties(mbMap, options); } this.syncVisibilityWithMb(mbMap, markerLayerId); From 600a007d35cede258e9e52da668059613c24f390 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 6 Apr 2020 18:49:38 -0400 Subject: [PATCH 09/50] add display --- .../mvt_single_layer_vector_source.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 908e168413386..d3415cad51cca 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -19,6 +19,7 @@ import { MVT_SINGLE_LAYER } from '../../../../common/constants'; import { VECTOR_SHAPE_TYPES } from '../vector_feature_types'; import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; +import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters'; const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle', { defaultMessage: 'XYZ Vector Tile Layer', @@ -79,6 +80,18 @@ export class MVTSingleLayerVectorSource extends AbstractSource return null; } + async getImmutableProperties() { + return [ + { label: getDataSourceLabel(), value: sourceTitle }, + { label: getUrlLabel(), value: this._descriptor.urlTemplate }, + { label: 'Layer name', value: this._descriptor.layerName }, + ]; + } + + getDisplayName(): Promise { + return this._descriptor.layerName; + } + async getUrlTemplateWithMeta(): TiledSingleLayerVectorSourceMeta { return { urlTemplate: this._descriptor.urlTemplate, From d9eef55e26eec6196f3170cf01cfd79cd33db347 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 7 Apr 2020 09:58:36 -0400 Subject: [PATCH 10/50] remove debug cruft --- x-pack/legacy/plugins/maps/public/actions/map_actions.js | 3 --- .../layers/styles/vector/components/vector_style_editor.js | 1 - 2 files changed, 4 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/actions/map_actions.js b/x-pack/legacy/plugins/maps/public/actions/map_actions.js index 32dbab2e34e4c..aa55cf0808ef2 100644 --- a/x-pack/legacy/plugins/maps/public/actions/map_actions.js +++ b/x-pack/legacy/plugins/maps/public/actions/map_actions.js @@ -861,19 +861,16 @@ export function updateLayerStyle(layerId, styleDescriptor) { export function updateStyleMeta(layerId) { return async (dispatch, getState) => { - console.log('update style meta'); const layer = getLayerById(layerId, getState()); if (!layer) { return; } const sourceDataRequest = layer.getSourceDataRequest(); - console.log('sourcedatareq', sourceDataRequest); const style = layer.getCurrentStyle(); if (!style || !sourceDataRequest) { return; } const styleMeta = await style.pluckStyleMetaFromSourceDataRequest(sourceDataRequest); - console.log('style meta', styleMeta); dispatch({ type: SET_LAYER_STYLE_META, layerId, diff --git a/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index ec6374c24a1a0..d3895d63ea89d 100644 --- a/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -114,7 +114,6 @@ export class VectorStyleEditor extends Component { } _handleSelectedFeatureChange = selectedFeature => { - console.log('sel feature change', selectedFeature); this.setState({ selectedFeature }); }; From b2ed4392e75504b12772d628a455a07d06b997a1 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 7 Apr 2020 18:13:31 -0400 Subject: [PATCH 11/50] add feature flag --- x-pack/legacy/plugins/maps/index.js | 2 + x-pack/legacy/plugins/maps/public/plugin.ts | 6 +-- x-pack/plugins/maps/public/kibana_services.js | 5 ++- .../maps/public/layers/load_layer_wizards.js | 37 +++++++++++++------ .../mvt_single_layer_vector_source.tsx | 2 +- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/x-pack/legacy/plugins/maps/index.js b/x-pack/legacy/plugins/maps/index.js index 1a7f478d3bbad..f4e01efc05f45 100644 --- a/x-pack/legacy/plugins/maps/index.js +++ b/x-pack/legacy/plugins/maps/index.js @@ -38,6 +38,7 @@ export function maps(kibana) { return { showMapVisualizationTypes: serverConfig.get('xpack.maps.showMapVisualizationTypes'), showMapsInspectorAdapter: serverConfig.get('xpack.maps.showMapsInspectorAdapter'), + enableVectorTiles: serverConfig.get('xpack.maps.enableVectorTiles'), preserveDrawingBuffer: serverConfig.get('xpack.maps.preserveDrawingBuffer'), isEmsEnabled: mapConfig.includeElasticMapsService, emsFontLibraryUrl: mapConfig.emsFontLibraryUrl, @@ -85,6 +86,7 @@ export function maps(kibana) { showMapVisualizationTypes: Joi.boolean().default(false), showMapsInspectorAdapter: Joi.boolean().default(false), // flag used in functional testing preserveDrawingBuffer: Joi.boolean().default(false), // flag used in functional testing + enableVectorTiles: Joi.boolean().default(false), // flag used to enable/disable vector-tiles }).default(); }, diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 0fa7e1106a6df..27e60c5c30577 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -8,14 +8,13 @@ import '../../../../plugins/maps/public/layers/layer_wizard_registry'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import '../../../../plugins/maps/public/layers/sources/source_registry'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import '../../../../plugins/maps/public/layers/load_layer_wizards'; - import { Plugin, CoreStart, CoreSetup } from 'src/core/public'; // @ts-ignore import { wrapInI18nContext } from 'ui/i18n'; // @ts-ignore import { Start as InspectorStartContract } from 'src/plugins/inspector/public'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { registerLayerWizards } from '../../../../plugins/maps/public/layers/load_layer_wizards'; // @ts-ignore import { MapListing } from './components/map_listing'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths @@ -74,6 +73,7 @@ export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { setIndexPatternSelect(data.ui.IndexPatternSelect); setTimeFilter(data.query.timefilter.timefilter); setIndexPatternService(data.indexPatterns); + registerLayerWizards(); }; /** @internal */ diff --git a/x-pack/plugins/maps/public/kibana_services.js b/x-pack/plugins/maps/public/kibana_services.js index d2ddecfdf915b..d76393070def2 100644 --- a/x-pack/plugins/maps/public/kibana_services.js +++ b/x-pack/plugins/maps/public/kibana_services.js @@ -38,7 +38,10 @@ export const getFileUploadComponent = () => { }; let getInjectedVar; -export const setInjectedVarFunc = getInjectedVarFunc => (getInjectedVar = getInjectedVarFunc); +export const setInjectedVarFunc = getInjectedVarFunc => { + console.log('setinjev', getInjectedVarFunc); + getInjectedVar = getInjectedVarFunc; +}; export const getInjectedVarFunc = () => getInjectedVar; let uiSettings; diff --git a/x-pack/plugins/maps/public/layers/load_layer_wizards.js b/x-pack/plugins/maps/public/layers/load_layer_wizards.js index 29846cf2ec4bc..147a9e9fb3fed 100644 --- a/x-pack/plugins/maps/public/layers/load_layer_wizards.js +++ b/x-pack/plugins/maps/public/layers/load_layer_wizards.js @@ -16,17 +16,30 @@ import { kibanaBasemapLayerWizardConfig } from './sources/kibana_tilemap_source' import { tmsLayerWizardConfig } from './sources/xyz_tms_source'; import { wmsLayerWizardConfig } from './sources/wms_source'; import { mvtVectorSourceWizardConfig } from './sources/mvt_vector_source/mvt_single_layer_vector_source'; +import { getInjectedVarFunc } from '../kibana_services'; // Registration order determines display order -registerLayerWizard(uploadLayerWizardConfig); -registerLayerWizard(esDocumentsLayerWizardConfig); -registerLayerWizard(clustersLayerWizardConfig); -registerLayerWizard(heatmapLayerWizardConfig); -registerLayerWizard(point2PointLayerWizardConfig); -registerLayerWizard(emsBoundariesLayerWizardConfig); -registerLayerWizard(emsBaseMapLayerWizardConfig); -registerLayerWizard(kibanaRegionMapLayerWizardConfig); -registerLayerWizard(kibanaBasemapLayerWizardConfig); -registerLayerWizard(tmsLayerWizardConfig); -registerLayerWizard(wmsLayerWizardConfig); -registerLayerWizard(mvtVectorSourceWizardConfig); +let registered = false; +export function registerLayerWizards() { + if (registered) { + return; + } + registerLayerWizard(uploadLayerWizardConfig); + registerLayerWizard(esDocumentsLayerWizardConfig); + registerLayerWizard(clustersLayerWizardConfig); + registerLayerWizard(heatmapLayerWizardConfig); + registerLayerWizard(point2PointLayerWizardConfig); + registerLayerWizard(emsBoundariesLayerWizardConfig); + registerLayerWizard(emsBaseMapLayerWizardConfig); + registerLayerWizard(kibanaRegionMapLayerWizardConfig); + registerLayerWizard(kibanaBasemapLayerWizardConfig); + registerLayerWizard(tmsLayerWizardConfig); + registerLayerWizard(wmsLayerWizardConfig); + + const getInjectedVar = getInjectedVarFunc(); + if (getInjectedVar && getInjectedVar('enableVectorTiles', false)) { + console.warn('Vector tiles are an experimental feature and should not be used in production.'); + registerLayerWizard(mvtVectorSourceWizardConfig); + } + registered = true; +} diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index d3415cad51cca..011647a7239d1 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -22,7 +22,7 @@ import { registerSource } from '../source_registry'; import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters'; const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle', { - defaultMessage: 'XYZ Vector Tile Layer', + defaultMessage: 'Vector Tile Layer', }); export class MVTSingleLayerVectorSource extends AbstractSource From 83799b4bb2124a5ef4a0fb7f7e004a8278f9c32a Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 8 Apr 2020 09:04:24 -0400 Subject: [PATCH 12/50] tmp commit --- .../connected_components/map/mb/view.js | 9 +++- .../mvt_single_layer_vector_source.tsx | 20 ++++----- .../mvt_vector_source_editor.tsx | 45 +++++++++++++------ .../public/layers/sources/vector_source.d.ts | 2 + 4 files changed, 52 insertions(+), 24 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js index fedc1902d80a2..fdca2abdc1109 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/map/mb/view.js @@ -14,7 +14,12 @@ import { } from './utils'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getGlyphUrl, isRetina } from '../../../../../../../plugins/maps/public/meta'; -import { DECIMAL_DEGREES_PRECISION, ZOOM_PRECISION } from '../../../../common/constants'; +import { + DECIMAL_DEGREES_PRECISION, + MAX_ZOOM, + MIN_ZOOM, + ZOOM_PRECISION, +} from '../../../../common/constants'; import mapboxgl from 'mapbox-gl/dist/mapbox-gl-csp'; import mbWorkerUrl from '!!file-loader!mapbox-gl/dist/mapbox-gl-csp-worker'; import mbRtlPlugin from '!!file-loader!@mapbox/mapbox-gl-rtl-text/mapbox-gl-rtl-text.min.js'; @@ -131,6 +136,8 @@ export class MBMapContainer extends React.Component { scrollZoom: this.props.scrollZoom, preserveDrawingBuffer: chrome.getInjected('preserveDrawingBuffer', false), interactive: !this.props.disableInteractive, + minZoom: MIN_ZOOM, + maxZoom: MAX_ZOOM, }; const initialView = _.get(this.props.goto, 'center'); if (initialView) { diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 011647a7239d1..3433cd2e76dd7 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -15,7 +15,7 @@ import { ITiledSingleLayerVectorSource, TiledSingleLayerVectorSourceMeta, } from '../vector_source'; -import { MVT_SINGLE_LAYER } from '../../../../common/constants'; +import { MAX_ZOOM, MIN_ZOOM, MVT_SINGLE_LAYER } from '../../../../common/constants'; import { VECTOR_SHAPE_TYPES } from '../vector_feature_types'; import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; @@ -37,12 +37,14 @@ export class MVTSingleLayerVectorSource extends AbstractSource static icon = 'logoElasticsearch'; - static createDescriptor({ urlTemplate, layerName }) { + static createDescriptor({ urlTemplate, layerName, minZoom, maxZoom }) { return { type: MVTSingleLayerVectorSource.type, id: uuid(), urlTemplate, layerName, + minZoom: Math.max(MIN_ZOOM, minZoom), + maxZoom: Math.min(MAX_ZOOM, maxZoom), }; } @@ -50,16 +52,12 @@ export class MVTSingleLayerVectorSource extends AbstractSource return null; } - _createDefaultLayerDescriptor(options) { - return TiledVectorLayer.createDescriptor({ - sourceDescriptor: this._descriptor, - ...options, - }); - } - createDefaultLayer(options) { return new TiledVectorLayer({ - layerDescriptor: this._createDefaultLayerDescriptor(options), + layerDescriptor: TiledVectorLayer.createDescriptor({ + sourceDescriptor: this._descriptor, + ...options, + }), source: this, }); } @@ -96,6 +94,8 @@ export class MVTSingleLayerVectorSource extends AbstractSource return { urlTemplate: this._descriptor.urlTemplate, layerName: this._descriptor.layerName, + minZoom: this._descriptor.minZoom, + maxZoom: this._descriptor.maxZoom, }; } diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index 3f356c924a7f7..7bbc2983beb36 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -7,11 +7,15 @@ import React, { Fragment } from 'react'; import _ from 'lodash'; import { EuiFieldText, EuiFormRow } from '@elastic/eui'; +import { EuiDualRange } from '@elastic/eui'; +import { MAX_ZOOM, MIN_ZOOM } from '../../../../common/constants'; export class MVTVectorSourceEditor extends React.Component { state = { urlTemplate: '', layerName: '', + minZoom: 0, + maxZoom: 16, mvtCanPreview: false, }; @@ -20,11 +24,13 @@ export class MVTVectorSourceEditor extends React.Component { this.props.onSourceConfigChange({ urlTemplate: this.state.urlTemplate, layerName: this.state.layerName, + minZoom: this.state.minZoom, + maxZoom: this.state.maxZoom, }); } }, 2000); - _handleUrlTemplateChange(e) { + _handleUrlTemplateChange = e => { const url = e.target.value; const canPreview = @@ -36,9 +42,9 @@ export class MVTVectorSourceEditor extends React.Component { }, () => this._sourceConfigChange() ); - } + }; - _handleLayerNameInputChange(e) { + _handleLayerNameInputChange = e => { const layerName = e.target.value; this.setState( { @@ -46,23 +52,36 @@ export class MVTVectorSourceEditor extends React.Component { }, () => this._sourceConfigChange() ); - } + }; + + _handleZoomRangeChange = e => { + console.log(e); + const minZoom = parseInt(e[0], 10); + const maxZoom = parseInt(e[1], 10); + + if (this.state.minZoom !== minZoom || this.state.maxZoom !== maxZoom) { + this.setState({ minZoom, maxZoom }); + } + }; render() { - const example = `https://tiles.maps.elastic.co/data/v3/{z}/{x}/{y}.pbf`; return ( -
{example}
- this._handleUrlTemplateChange(e)} - /> + + + + - this._handleLayerNameInputChange(e)} +
diff --git a/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts b/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts index 6d40237b66253..a9e466b7ba7d0 100644 --- a/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts @@ -50,6 +50,8 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc type TiledSingleLayerVectorSourceMeta = { urlTemplate: string; layerName: string; + minZoom: number; + maxZoom: number; }; export interface ITiledSingleLayerVectorSource extends IVectorSource { From e692fc854953da878f46d75b4a12eb2f5b50cfa5 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 8 Apr 2020 15:05:31 -0400 Subject: [PATCH 13/50] more typing --- x-pack/plugins/maps/public/kibana_services.js | 1 - x-pack/plugins/maps/public/layers/layer.d.ts | 4 ++++ .../maps/public/layers/sources/source.d.ts | 1 + .../public/layers/sources/vector_source.d.ts | 3 +++ .../public/layers/styles/abstract_style.js | 4 ---- .../layers/styles/vector/vector_style.d.ts | 2 +- .../maps/public/layers/tiled_vector_layer.tsx | 19 +++++-------------- .../maps/public/layers/vector_layer.d.ts | 2 +- 8 files changed, 15 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/maps/public/kibana_services.js b/x-pack/plugins/maps/public/kibana_services.js index d76393070def2..25ba36fde2254 100644 --- a/x-pack/plugins/maps/public/kibana_services.js +++ b/x-pack/plugins/maps/public/kibana_services.js @@ -39,7 +39,6 @@ export const getFileUploadComponent = () => { let getInjectedVar; export const setInjectedVarFunc = getInjectedVarFunc => { - console.log('setinjev', getInjectedVarFunc); getInjectedVar = getInjectedVarFunc; }; export const getInjectedVarFunc = () => getInjectedVar; diff --git a/x-pack/plugins/maps/public/layers/layer.d.ts b/x-pack/plugins/maps/public/layers/layer.d.ts index de59642ede8ab..13763a9b89f3f 100644 --- a/x-pack/plugins/maps/public/layers/layer.d.ts +++ b/x-pack/plugins/maps/public/layers/layer.d.ts @@ -17,6 +17,8 @@ export interface ILayer { getSource(): ISource; getSourceForEditing(): ISource; syncData(syncContext: SyncContext): Promise; + isVisible(): boolean; + showAtZoomLevel(zoomLevel: number): boolean; } export interface ILayerArguments { @@ -34,4 +36,6 @@ export class AbstractLayer implements ILayer { getSource(): ISource; getSourceForEditing(): ISource; syncData(syncContext: SyncContext): Promise; + isVisible(): boolean; + showAtZoomLevel(zoomLevel: number): boolean; } diff --git a/x-pack/plugins/maps/public/layers/sources/source.d.ts b/x-pack/plugins/maps/public/layers/sources/source.d.ts index e1706ad7b7d77..6579c43fd36fd 100644 --- a/x-pack/plugins/maps/public/layers/sources/source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/source.d.ts @@ -33,4 +33,5 @@ export class AbstractSource implements ISource { isQueryAware(): boolean; isRefreshTimerAware(): Promise; isTimeAware(): Promise; + getFieldNames(): string[]; } diff --git a/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts b/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts index 47de65f649764..cafbd27bd6812 100644 --- a/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts @@ -34,6 +34,8 @@ export interface IVectorSource extends ISource { getFields(): Promise; getFieldByName(fieldName: string): IField; getSyncMeta(): VectorSourceSyncMeta; + getFieldNames(): string[]; + getApplyGlobalQuery(): boolean; } export class AbstractVectorSource extends AbstractSource implements IVectorSource { @@ -49,6 +51,7 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc getSyncMeta(): VectorSourceSyncMeta; getSupportedShapeTypes(): VECTOR_SHAPE_TYPES[]; canFormatFeatureProperties(): boolean; + getApplyGlobalQuery(): boolean; } type TiledSingleLayerVectorSourceMeta = { diff --git a/x-pack/plugins/maps/public/layers/styles/abstract_style.js b/x-pack/plugins/maps/public/layers/styles/abstract_style.js index 3e7a3dbf7ed20..161df58b921c0 100644 --- a/x-pack/plugins/maps/public/layers/styles/abstract_style.js +++ b/x-pack/plugins/maps/public/layers/styles/abstract_style.js @@ -15,10 +15,6 @@ export class AbstractStyle { return {}; } - getDescriptor() { - return this._descriptor; - } - renderEditor(/* { layer, onStyleDescriptorChange } */) { return null; } diff --git a/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts b/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts index 77ea44ac26bf9..3634aadb83c2d 100644 --- a/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts +++ b/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts @@ -17,7 +17,7 @@ export interface IVectorStyle { export class VectorStyle implements IVectorStyle { constructor(descriptor: VectorStyleDescriptor, source: IVectorSource, layer: IVectorLayer); - + getSourceFieldNames(): string[]; getAllStyleProperties(): IStyleProperty[]; getDescriptor(): VectorStyleDescriptor; getDynamicPropertiesArray(): IDynamicStyleProperty[]; diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index 0ce14a564c46b..26e3c6822d248 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -21,7 +21,7 @@ export class TiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; static createDescriptor(options, mapColors) { - const layerDescriptor = super.createDescriptor(options); + const layerDescriptor = super.createDescriptor(options, mapColors); layerDescriptor.type = TiledVectorLayer.type; if (!options.style) { @@ -34,21 +34,12 @@ export class TiledVectorLayer extends VectorLayer { private readonly _source: ITiledSingleLayerVectorSource; // downcast to the more specific type - constructor(vectorArgs: VectorLayerArguments) { - if (vectorArgs.joins && vectorArgs.joins.length) { - throw new Error('Tiled vector layers do not support joins'); - } - super(vectorArgs); + constructor({ layerDescriptor, source }) { + super({ layerDescriptor, source }); // reassignment is required due since _source is a shadowed property // and in the transpiled JS-code, the .source assignment in super() is getting voided in this constructor. - this._source = vectorArgs.source; - } - - destroy() { - if (this._source) { - this._source.destroy(); - } + this._source = source as ITiledSingleLayerVectorSource; } getCustomIconAndTooltipContent() { @@ -75,7 +66,7 @@ export class TiledVectorLayer extends VectorLayer { registerCancelCallback, dataFilters, }: SyncContext) { - const requestToken = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`); + const requestToken: symbol = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`); const searchFilters = this._getSearchFilters(dataFilters); const prevDataRequest = this.getSourceDataRequest(); const canSkip = await canSkipSourceUpdate({ diff --git a/x-pack/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/plugins/maps/public/layers/vector_layer.d.ts index 1ba1b5bbfd96c..519fa0fea94b6 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/layers/vector_layer.d.ts @@ -38,7 +38,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { protected readonly _source: IVectorSource; constructor(options: VectorLayerArguments); - + getLayerTypeIconName(): string; getFields(): Promise; getStyleEditorFields(): Promise; getValidJoins(): IJoin[]; From f67627178dfd9d32ca7a8a98706c4b9a5e15e286 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 8 Apr 2020 15:39:01 -0400 Subject: [PATCH 14/50] add readout --- .../connected_components/layer_addpanel/view.js | 13 ++++++++----- .../plugins/maps/public/selectors/map_selectors.js | 6 +++--- .../mvt_single_layer_vector_source.tsx | 8 +++++--- .../mvt_vector_source/mvt_vector_source_editor.tsx | 5 ++--- .../maps/public/layers/sources/vector_source.d.ts | 5 +++++ .../maps/public/layers/styles/abstract_style.js | 4 ++++ .../maps/public/layers/tiled_vector_layer.tsx | 8 +++++--- 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/view.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/view.js index a54df69471aa0..864dc5b0b5cc6 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/view.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/view.js @@ -63,13 +63,16 @@ export class AddLayerPanel extends Component { return; } - const style = - this.state.layer && this.state.layer.getCurrentStyle() - ? this.state.layer.getCurrentStyle().getDescriptor() - : null; + let styleDescriptor; + if (this.state.layer && this.state.layer.getCurrentStyle()) { + const currentStyle = this.state.layer.getCurrentStyle(); + styleDescriptor = currentStyle.getDescriptor(); + } else { + styleDescriptor = null; + } const layerInitProps = { ...options, - style: style, + style: styleDescriptor, }; const newLayer = source.createDefaultLayer(layerInitProps, this.props.mapColors); if (!this._isMounted) { diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index b07798edddde9..26e5373431bda 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -17,7 +17,7 @@ import { HeatmapLayer } from '../../../../../plugins/maps/public/layers/heatmap_ // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { BlendedVectorLayer } from '../../../../../plugins/maps/public/layers/blended_vector_layer'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { TiledVectorLayer } from '../../../../../plugins/maps/public/layers/tiled_vector_layer'; +import { SingleTiledVectorLayer } from '../../../../../plugins/maps/public/layers/tiled_vector_layer'; import { getTimeFilter } from '../kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; @@ -52,8 +52,8 @@ function createLayerInstance(layerDescriptor, inspectorAdapters) { return new HeatmapLayer({ layerDescriptor, source }); case BlendedVectorLayer.type: return new BlendedVectorLayer({ layerDescriptor, source }); - case TiledVectorLayer.type: - return new TiledVectorLayer({ layerDescriptor, source }); + case SingleTiledVectorLayer.type: + return new SingleTiledVectorLayer({ layerDescriptor, source }); default: throw new Error(`Unrecognized layerType ${layerDescriptor.type}`); } diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 3433cd2e76dd7..bd5c1765bb169 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -9,7 +9,7 @@ import uuid from 'uuid/v4'; import React from 'react'; import { MVTVectorSourceEditor } from './mvt_vector_source_editor'; import { AbstractSource } from '../source'; -import { TiledVectorLayer } from '../../tiled_vector_layer'; +import { SingleTiledVectorLayer } from '../../tiled_vector_layer'; import { GeoJsonWithMeta, ITiledSingleLayerVectorSource, @@ -53,8 +53,8 @@ export class MVTSingleLayerVectorSource extends AbstractSource } createDefaultLayer(options) { - return new TiledVectorLayer({ - layerDescriptor: TiledVectorLayer.createDescriptor({ + return new SingleTiledVectorLayer({ + layerDescriptor: SingleTiledVectorLayer.createDescriptor({ sourceDescriptor: this._descriptor, ...options, }), @@ -83,6 +83,8 @@ export class MVTSingleLayerVectorSource extends AbstractSource { label: getDataSourceLabel(), value: sourceTitle }, { label: getUrlLabel(), value: this._descriptor.urlTemplate }, { label: 'Layer name', value: this._descriptor.layerName }, + { label: 'Min zoom', value: this._descriptor.minZoom }, + { label: 'Max zoom', value: this._descriptor.maxZoom }, ]; } diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index 7bbc2983beb36..8df72aad33ccd 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -55,12 +55,11 @@ export class MVTVectorSourceEditor extends React.Component { }; _handleZoomRangeChange = e => { - console.log(e); const minZoom = parseInt(e[0], 10); const maxZoom = parseInt(e[1], 10); if (this.state.minZoom !== minZoom || this.state.maxZoom !== maxZoom) { - this.setState({ minZoom, maxZoom }); + this.setState({ minZoom, maxZoom }, () => this._sourceConfigChange()); } }; @@ -73,7 +72,7 @@ export class MVTVectorSourceEditor extends React.Component { - + Date: Wed, 8 Apr 2020 16:46:14 -0400 Subject: [PATCH 15/50] add zoom level locks --- .../layer_panel/layer_settings/index.js | 2 ++ .../layer_settings/layer_settings.js | 10 ++++------ .../descriptor_types/descriptor_types.d.ts | 12 ++++++++++++ x-pack/plugins/maps/public/layers/layer.d.ts | 8 ++++++++ x-pack/plugins/maps/public/layers/layer.js | 8 ++++++++ .../mvt_single_layer_vector_source.tsx | 17 +++++++++++------ .../public/layers/sources/vector_source.d.ts | 14 ++------------ .../maps/public/layers/tiled_vector_layer.tsx | 19 +++++++++++++------ 8 files changed, 60 insertions(+), 30 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js index 73c98db8e429d..6e8354aa422d5 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js @@ -17,6 +17,8 @@ import { function mapStateToProps(state = {}) { const selectedLayer = getSelectedLayer(state); return { + minZoomForData: selectedLayer.getMinZoomForData(), + maxZoomForData: selectedLayer.getMaxZoomForData(), alpha: selectedLayer.getAlpha(), label: selectedLayer.getLabel(), layerId: selectedLayer.getId(), diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js index bd27450943638..b7c7314519492 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js @@ -13,8 +13,6 @@ import { ValidatedRange } from '../../../../../../../plugins/maps/public/compone import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { ValidatedDualRange } from '../../../../../../../../src/plugins/kibana_react/public'; -import { MAX_ZOOM, MIN_ZOOM } from '../../../../common/constants'; - export function LayerSettings(props) { const onLabelChange = event => { const label = event.target.value; @@ -22,8 +20,8 @@ export function LayerSettings(props) { }; const onZoomChange = ([min, max]) => { - props.updateMinZoom(props.layerId, Math.max(MIN_ZOOM, parseInt(min, 10))); - props.updateMaxZoom(props.layerId, Math.min(MAX_ZOOM, parseInt(max, 10))); + props.updateMinZoom(props.layerId, Math.max(props.minZoomForData, parseInt(min, 10))); + props.updateMaxZoom(props.layerId, Math.min(props.maxZoomForData, parseInt(max, 10))); }; const onAlphaChange = alpha => { @@ -38,8 +36,8 @@ export function LayerSettings(props) { defaultMessage: 'Visibility', })} formRowDisplay="columnCompressed" - min={MIN_ZOOM} - max={MAX_ZOOM} + min={props.minZoomForData} + max={props.maxZoomForData} value={[props.minZoom, props.maxZoom]} showInput="inputWithPopover" showRange diff --git a/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts b/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts index fb49e1aaebe1c..404a3f95ea000 100644 --- a/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts +++ b/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts @@ -84,6 +84,18 @@ export type WMSSourceDescriptor = { attributionUrl: string; }; +export type TiledSingleLayerVectorSourceDescriptor = { + urlTemplate: string; + layerName: string; + + // These are the min/max zoom levels of the availability of the a particle layerName in the tileset at urlTemplate. + // These are _not_ the visible zoom-range of the data on a map. + // Tiled data can be displayed at higher levels of zoom than that they are stored in the tileset. + // e.g. EMS basemap data from level 16 can be displayed at higher levels + minZoom: number; + maxZoom: number; +}; + export type XYZTMSSourceDescriptor = { id: string; type: string; diff --git a/x-pack/plugins/maps/public/layers/layer.d.ts b/x-pack/plugins/maps/public/layers/layer.d.ts index 13763a9b89f3f..7242b66ae1d68 100644 --- a/x-pack/plugins/maps/public/layers/layer.d.ts +++ b/x-pack/plugins/maps/public/layers/layer.d.ts @@ -19,6 +19,10 @@ export interface ILayer { syncData(syncContext: SyncContext): Promise; isVisible(): boolean; showAtZoomLevel(zoomLevel: number): boolean; + getMinZoomForData(): number; + getMaxZoomForData(): number; + getMinZoom(): number; + getMaxZoom(): number; } export interface ILayerArguments { @@ -38,4 +42,8 @@ export class AbstractLayer implements ILayer { syncData(syncContext: SyncContext): Promise; isVisible(): boolean; showAtZoomLevel(zoomLevel: number): boolean; + getMinZoomForData(): number; + getMaxZoomForData(): number; + getMinZoom(): number; + getMaxZoom(): number; } diff --git a/x-pack/plugins/maps/public/layers/layer.js b/x-pack/plugins/maps/public/layers/layer.js index 26bce872b3c2c..4bb26e8c80e7e 100644 --- a/x-pack/plugins/maps/public/layers/layer.js +++ b/x-pack/plugins/maps/public/layers/layer.js @@ -352,4 +352,12 @@ export class AbstractLayer { getType() { return this._descriptor.type; } + + getMinZoomForData() { + return MIN_ZOOM; + } + + getMaxZoomForData() { + return MAX_ZOOM; + } } diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index bd5c1765bb169..9bd71797a9a2d 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -10,16 +10,13 @@ import React from 'react'; import { MVTVectorSourceEditor } from './mvt_vector_source_editor'; import { AbstractSource } from '../source'; import { SingleTiledVectorLayer } from '../../tiled_vector_layer'; -import { - GeoJsonWithMeta, - ITiledSingleLayerVectorSource, - TiledSingleLayerVectorSourceMeta, -} from '../vector_source'; +import { GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source'; import { MAX_ZOOM, MIN_ZOOM, MVT_SINGLE_LAYER } from '../../../../common/constants'; import { VECTOR_SHAPE_TYPES } from '../vector_feature_types'; import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters'; +import { TiledSingleLayerVectorSourceDescriptor } from '../../../../common/descriptor_types'; const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle', { defaultMessage: 'Vector Tile Layer', @@ -92,7 +89,7 @@ export class MVTSingleLayerVectorSource extends AbstractSource return this._descriptor.layerName; } - async getUrlTemplateWithMeta(): TiledSingleLayerVectorSourceMeta { + async getUrlTemplateWithMeta(): Promise { return { urlTemplate: this._descriptor.urlTemplate, layerName: this._descriptor.layerName, @@ -108,6 +105,14 @@ export class MVTSingleLayerVectorSource extends AbstractSource canFormatFeatureProperties() { return false; } + + getMinZoom() { + return this._descriptor.minZoom; + } + + getMaxZoom() { + return this._descriptor.maxZoom; + } } registerSource({ diff --git a/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts b/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts index 97f06ec4dfdd4..84aa070a6a2d4 100644 --- a/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts @@ -54,18 +54,8 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc getApplyGlobalQuery(): boolean; } -type TiledSingleLayerVectorSourceMeta = { - urlTemplate: string; - layerName: string; - - // These are the min/max zoom levels of the availability of the a particle layerName in the tileset at urlTemplate. - // These are _not_ the visible zoom-range of the data on a map. - // Tiled data can be displayed at higher levels of zoom than that they are stored in the tileset. - // e.g. EMS basemap data from level 16 can be displayed at higher levels - minZoom: number; - maxZoom: number; -}; - export interface ITiledSingleLayerVectorSource extends IVectorSource { getUrlTemplateWithMeta(): Promise; + getMinZoom(): number; + getMaxZoom(): number; } diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index d22b3dbdfb106..229d6d0c6cf0c 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -11,11 +11,9 @@ import { VectorStyle } from './styles/vector/vector_style'; import { SOURCE_DATA_ID_ORIGIN, LAYER_TYPE } from '../../common/constants'; import { VectorLayer } from './vector_layer'; import { canSkipSourceUpdate } from './util/can_skip_fetch'; -import { - ITiledSingleLayerVectorSource, - TiledSingleLayerVectorSourceMeta, -} from './sources/vector_source'; +import { ITiledSingleLayerVectorSource } from './sources/vector_source'; import { SyncContext } from '../actions/map_actions'; +import { TiledSingleLayerVectorSourceDescriptor } from '../../common/descriptor_types'; export class SingleTiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; @@ -80,7 +78,7 @@ export class SingleTiledVectorLayer extends VectorLayer { startLoading(SOURCE_DATA_ID_ORIGIN, requestToken, searchFilters); try { - const templateWithMeta: TiledSingleLayerVectorSourceMeta = await this._source.getUrlTemplateWithMeta(); + const templateWithMeta = await this._source.getUrlTemplateWithMeta(); stopLoading(SOURCE_DATA_ID_ORIGIN, requestToken, templateWithMeta, {}); } catch (error) { onLoadError(SOURCE_DATA_ID_ORIGIN, requestToken, error.message); @@ -108,7 +106,7 @@ export class SingleTiledVectorLayer extends VectorLayer { return; } - const sourceMeta: TiledSingleLayerVectorSourceMeta = sourceDataRequest.getData() as TiledSingleLayerVectorSourceMeta; + const sourceMeta: TiledSingleLayerVectorSourceDescriptor = sourceDataRequest.getData() as TiledSingleLayerVectorSourceDescriptor; if (!sourceMeta) { return; } @@ -199,4 +197,13 @@ export class SingleTiledVectorLayer extends VectorLayer { async loadPreIndexedShapeByFeatureId(featureId, meta) { return null; } + + getMinZoomForData(): number { + return this._source.getMinZoom(); + } + + getMinZoom() { + // higher resolution vector tiles cannot be displayed at lower-res + return Math.max(this.getMinZoomForData(), super.getMinZoom()); + } } From a9151c05a38300b9d834107f50a1c6275045df0b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 8 Apr 2020 16:59:10 -0400 Subject: [PATCH 16/50] remove row --- .../mvt_vector_source_editor.tsx | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index 8df72aad33ccd..1515ac1a4d86f 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -7,8 +7,9 @@ import React, { Fragment } from 'react'; import _ from 'lodash'; import { EuiFieldText, EuiFormRow } from '@elastic/eui'; -import { EuiDualRange } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; import { MAX_ZOOM, MIN_ZOOM } from '../../../../common/constants'; +import { ValidatedDualRange } from '../../../../../../../src/plugins/kibana_react/public'; export class MVTVectorSourceEditor extends React.Component { state = { @@ -72,17 +73,24 @@ export class MVTVectorSourceEditor extends React.Component { - - - + ); } From 83ba1529bfcff8570d0c2f151e1b6957f09e2844 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 8 Apr 2020 17:26:44 -0400 Subject: [PATCH 17/50] ts linting --- .../descriptor_types/descriptor_types.d.ts | 2 +- .../public/layers/layer_wizard_registry.ts | 4 +- ...layer_wizards.js => load_layer_wizards.ts} | 1 + .../mvt_single_layer_vector_source.tsx | 59 +++++++++++++++---- .../mvt_vector_source_editor.tsx | 4 +- .../maps/public/layers/sources/source.d.ts | 1 + .../public/layers/sources/source_registry.ts | 2 +- .../public/layers/sources/vector_source.d.ts | 8 ++- .../public/layers/sources/xyz_tms_source.d.ts | 3 + .../maps/public/layers/vector_layer.d.ts | 1 + 10 files changed, 66 insertions(+), 19 deletions(-) rename x-pack/plugins/maps/public/layers/{load_layer_wizards.js => load_layer_wizards.ts} (98%) diff --git a/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts b/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts index 404a3f95ea000..79594ff3d2c23 100644 --- a/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts +++ b/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts @@ -84,7 +84,7 @@ export type WMSSourceDescriptor = { attributionUrl: string; }; -export type TiledSingleLayerVectorSourceDescriptor = { +export type TiledSingleLayerVectorSourceDescriptor = AbstractSourceDescriptor & { urlTemplate: string; layerName: string; diff --git a/x-pack/plugins/maps/public/layers/layer_wizard_registry.ts b/x-pack/plugins/maps/public/layers/layer_wizard_registry.ts index 3ef4701269994..aedf9e6799dd9 100644 --- a/x-pack/plugins/maps/public/layers/layer_wizard_registry.ts +++ b/x-pack/plugins/maps/public/layers/layer_wizard_registry.ts @@ -5,7 +5,7 @@ */ /* eslint-disable @typescript-eslint/consistent-type-definitions */ -type LayerWizard = { +export type LayerWizard = { description: string; icon: string; isIndexingSource?: boolean; @@ -14,7 +14,7 @@ type LayerWizard = { inspectorAdapters, }: { onPreviewSource: () => void; - inspectorAdapters: unknown; + inspectorAdapters: object; }): unknown; title: string; }; diff --git a/x-pack/plugins/maps/public/layers/load_layer_wizards.js b/x-pack/plugins/maps/public/layers/load_layer_wizards.ts similarity index 98% rename from x-pack/plugins/maps/public/layers/load_layer_wizards.js rename to x-pack/plugins/maps/public/layers/load_layer_wizards.ts index 147a9e9fb3fed..99270b5058403 100644 --- a/x-pack/plugins/maps/public/layers/load_layer_wizards.js +++ b/x-pack/plugins/maps/public/layers/load_layer_wizards.ts @@ -38,6 +38,7 @@ export function registerLayerWizards() { const getInjectedVar = getInjectedVarFunc(); if (getInjectedVar && getInjectedVar('enableVectorTiles', false)) { + // eslint-disable-next-line no-console console.warn('Vector tiles are an experimental feature and should not be used in production.'); registerLayerWizard(mvtVectorSourceWizardConfig); } diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 9bd71797a9a2d..91c86c1b3e999 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -17,6 +17,7 @@ import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters'; import { TiledSingleLayerVectorSourceDescriptor } from '../../../../common/descriptor_types'; +import { ILayer } from '../../layer'; const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle', { defaultMessage: 'Vector Tile Layer', @@ -34,7 +35,17 @@ export class MVTSingleLayerVectorSource extends AbstractSource static icon = 'logoElasticsearch'; - static createDescriptor({ urlTemplate, layerName, minZoom, maxZoom }) { + static createDescriptor({ + urlTemplate, + layerName, + minZoom, + maxZoom, + }: { + urlTemplate: string; + layerName: string; + minZoom: number; + maxZoom: number; + }) { return { type: MVTSingleLayerVectorSource.type, id: uuid(), @@ -45,11 +56,18 @@ export class MVTSingleLayerVectorSource extends AbstractSource }; } - renderSourceSettingsEditor({ onChange }) { + private readonly _descriptor: TiledSingleLayerVectorSourceDescriptor; + + constructor(descriptor: TiledSingleLayerVectorSourceDescriptor, adapters: object) { + super(descriptor, adapters); + this._descriptor = descriptor; // re-assignment is required due to TS-JS transpilation, not the type-system + } + + renderSourceSettingsEditor() { return null; } - createDefaultLayer(options) { + createDefaultLayer(options): ILayer { return new SingleTiledVectorLayer({ layerDescriptor: SingleTiledVectorLayer.createDescriptor({ sourceDescriptor: this._descriptor, @@ -71,10 +89,6 @@ export class MVTSingleLayerVectorSource extends AbstractSource return []; } - getFieldByName(fieldName: string) { - return null; - } - async getImmutableProperties() { return [ { label: getDataSourceLabel(), value: sourceTitle }, @@ -85,11 +99,11 @@ export class MVTSingleLayerVectorSource extends AbstractSource ]; } - getDisplayName(): Promise { + async getDisplayName(): Promise { return this._descriptor.layerName; } - async getUrlTemplateWithMeta(): Promise { + async getUrlTemplateWithMeta() { return { urlTemplate: this._descriptor.urlTemplate, layerName: this._descriptor.layerName, @@ -125,9 +139,30 @@ export const mvtVectorSourceWizardConfig = { defaultMessage: 'Vector source wizard', }), icon: 'grid', - renderWizard: ({ onPreviewSource, inspectorAdapters }) => { - const onSourceConfigChange = sourceConfig => { - const sourceDescriptor = MVTSingleLayerVectorSource.createDescriptor(sourceConfig); + renderWizard: ({ + onPreviewSource, + inspectorAdapters, + }: { + onPreviewSource: (source: MVTSingleLayerVectorSource) => void; + inspectorAdapters: object; + }) => { + const onSourceConfigChange = ({ + urlTemplate, + layerName, + minZoom, + maxZoom, + }: { + urlTemplate: string; + layerName: string; + minZoom: number; + maxZoom: number; + }) => { + const sourceDescriptor = MVTSingleLayerVectorSource.createDescriptor({ + urlTemplate, + layerName, + minZoom, + maxZoom, + }); const source = new MVTSingleLayerVectorSource(sourceDescriptor, inspectorAdapters); onPreviewSource(source); }; diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index 1515ac1a4d86f..2d95092fe279a 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -15,8 +15,8 @@ export class MVTVectorSourceEditor extends React.Component { state = { urlTemplate: '', layerName: '', - minZoom: 0, - maxZoom: 16, + minZoom: MIN_ZOOM, + maxZoom: MAX_ZOOM, mvtCanPreview: false, }; diff --git a/x-pack/plugins/maps/public/layers/sources/source.d.ts b/x-pack/plugins/maps/public/layers/sources/source.d.ts index 6579c43fd36fd..34bdd3444aed3 100644 --- a/x-pack/plugins/maps/public/layers/sources/source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/source.d.ts @@ -21,6 +21,7 @@ export interface ISource { } export class AbstractSource implements ISource { + readonly _descriptor: AbstractSourceDescriptor; constructor(sourceDescriptor: AbstractSourceDescriptor, inspectorAdapters: object); destroy(): void; diff --git a/x-pack/plugins/maps/public/layers/sources/source_registry.ts b/x-pack/plugins/maps/public/layers/sources/source_registry.ts index 518cab68b601b..822cb06f177be 100644 --- a/x-pack/plugins/maps/public/layers/sources/source_registry.ts +++ b/x-pack/plugins/maps/public/layers/sources/source_registry.ts @@ -11,7 +11,7 @@ import { ISource } from './source'; type SourceRegistryEntry = { ConstructorFunction: new ( sourceDescriptor: AbstractSourceDescriptor, - inspectorAdapters: unknown + inspectorAdapters: object ) => ISource; type: string; }; diff --git a/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts b/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts index 84aa070a6a2d4..cff11ca04add9 100644 --- a/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts @@ -11,6 +11,7 @@ import { IField } from '../fields/field'; import { ESSearchSourceResponseMeta, MapExtent, + TiledSingleLayerVectorSourceDescriptor, VectorSourceRequestMeta, VectorSourceSyncMeta, } from '../../../common/descriptor_types'; @@ -55,7 +56,12 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc } export interface ITiledSingleLayerVectorSource extends IVectorSource { - getUrlTemplateWithMeta(): Promise; + getUrlTemplateWithMeta(): Promise<{ + layerName: string; + urlTemplate: string; + minZoom: number; + maxZoom: number; + }>; getMinZoom(): number; getMaxZoom(): number; } diff --git a/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.d.ts b/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.d.ts index 579c9debeab3e..3d4d1868fed9a 100644 --- a/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.d.ts @@ -5,7 +5,10 @@ */ import { AbstractTMSSource } from './tms_source'; import { XYZTMSSourceDescriptor } from '../../../common/descriptor_types'; +import { LayerWizard } from '../layer_wizard_registry'; export class XYZTMSSource extends AbstractTMSSource { constructor(sourceDescriptor: XYZTMSSourceDescriptor, inspectorAdapters: unknown); } + +export const tmsLayerWizardConfig: LayerWizard; diff --git a/x-pack/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/plugins/maps/public/layers/vector_layer.d.ts index 519fa0fea94b6..8530b63ba3dc8 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/layers/vector_layer.d.ts @@ -31,6 +31,7 @@ export interface IVectorLayer extends ILayer { } export class VectorLayer extends AbstractLayer implements IVectorLayer { + readonly _style: IVectorStyle; static createDescriptor( options: VectorLayerArguments, mapColors: string[] From 7dca92a152db3097e9b50747a9527224713110f0 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 8 Apr 2020 18:07:43 -0400 Subject: [PATCH 18/50] typing --- x-pack/plugins/maps/public/layers/layer.d.ts | 1 + .../maps/public/layers/load_layer_wizards.ts | 20 +++++ .../mvt_single_layer_vector_source.tsx | 14 +-- .../layers/styles/vector/vector_style.d.ts | 9 +- .../maps/public/layers/tiled_vector_layer.tsx | 85 ++++++++++++------- .../maps/public/layers/vector_layer.d.ts | 5 ++ 6 files changed, 94 insertions(+), 40 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/layer.d.ts b/x-pack/plugins/maps/public/layers/layer.d.ts index 7242b66ae1d68..1ead9bcd14f91 100644 --- a/x-pack/plugins/maps/public/layers/layer.d.ts +++ b/x-pack/plugins/maps/public/layers/layer.d.ts @@ -46,4 +46,5 @@ export class AbstractLayer implements ILayer { getMaxZoomForData(): number; getMinZoom(): number; getMaxZoom(): number; + getQuery(): string; } diff --git a/x-pack/plugins/maps/public/layers/load_layer_wizards.ts b/x-pack/plugins/maps/public/layers/load_layer_wizards.ts index 99270b5058403..33a405bd88cee 100644 --- a/x-pack/plugins/maps/public/layers/load_layer_wizards.ts +++ b/x-pack/plugins/maps/public/layers/load_layer_wizards.ts @@ -5,17 +5,27 @@ */ import { registerLayerWizard } from './layer_wizard_registry'; +// @ts-ignore import { uploadLayerWizardConfig } from './sources/client_file_source'; +// @ts-ignore import { esDocumentsLayerWizardConfig } from './sources/es_search_source'; +// @ts-ignore import { clustersLayerWizardConfig, heatmapLayerWizardConfig } from './sources/es_geo_grid_source'; +// @ts-ignore import { point2PointLayerWizardConfig } from './sources/es_pew_pew_source/es_pew_pew_source'; +// @ts-ignore import { emsBoundariesLayerWizardConfig } from './sources/ems_file_source'; +// @ts-ignore import { emsBaseMapLayerWizardConfig } from './sources/ems_tms_source'; +// @ts-ignore import { kibanaRegionMapLayerWizardConfig } from './sources/kibana_regionmap_source'; +// @ts-ignore import { kibanaBasemapLayerWizardConfig } from './sources/kibana_tilemap_source'; import { tmsLayerWizardConfig } from './sources/xyz_tms_source'; +// @ts-ignore import { wmsLayerWizardConfig } from './sources/wms_source'; import { mvtVectorSourceWizardConfig } from './sources/mvt_vector_source/mvt_single_layer_vector_source'; +// @ts-ignore import { getInjectedVarFunc } from '../kibana_services'; // Registration order determines display order @@ -24,16 +34,26 @@ export function registerLayerWizards() { if (registered) { return; } + // @ts-ignore registerLayerWizard(uploadLayerWizardConfig); + // @ts-ignore registerLayerWizard(esDocumentsLayerWizardConfig); + // @ts-ignore registerLayerWizard(clustersLayerWizardConfig); + // @ts-ignore registerLayerWizard(heatmapLayerWizardConfig); + // @ts-ignore registerLayerWizard(point2PointLayerWizardConfig); + // @ts-ignore registerLayerWizard(emsBoundariesLayerWizardConfig); + // @ts-ignore registerLayerWizard(emsBaseMapLayerWizardConfig); + // @ts-ignore registerLayerWizard(kibanaRegionMapLayerWizardConfig); + // @ts-ignore registerLayerWizard(kibanaBasemapLayerWizardConfig); registerLayerWizard(tmsLayerWizardConfig); + // @ts-ignore registerLayerWizard(wmsLayerWizardConfig); const getInjectedVar = getInjectedVarFunc(); diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 91c86c1b3e999..675d5b06fddc5 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -17,7 +17,6 @@ import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters'; import { TiledSingleLayerVectorSourceDescriptor } from '../../../../common/descriptor_types'; -import { ILayer } from '../../layer'; const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle', { defaultMessage: 'Vector Tile Layer', @@ -67,12 +66,15 @@ export class MVTSingleLayerVectorSource extends AbstractSource return null; } - createDefaultLayer(options): ILayer { + createDefaultLayer(options): SingleTiledVectorLayer { return new SingleTiledVectorLayer({ - layerDescriptor: SingleTiledVectorLayer.createDescriptor({ - sourceDescriptor: this._descriptor, - ...options, - }), + layerDescriptor: SingleTiledVectorLayer.createDescriptor( + { + sourceDescriptor: this._descriptor, + ...options, + }, + [] + ), source: this, }); } diff --git a/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts b/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts index 3634aadb83c2d..2e19611efb014 100644 --- a/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts +++ b/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts @@ -7,7 +7,10 @@ import { IStyleProperty } from './properties/style_property'; import { IDynamicStyleProperty } from './properties/dynamic_style_property'; import { IVectorLayer } from '../../vector_layer'; import { IVectorSource } from '../../sources/vector_source'; -import { VectorStyleDescriptor } from '../../../../common/descriptor_types'; +import { + VectorStyleDescriptor, + VectorStylePropertiesDescriptor, +} from '../../../../common/descriptor_types'; export interface IVectorStyle { getAllStyleProperties(): IStyleProperty[]; @@ -16,6 +19,10 @@ export interface IVectorStyle { } export class VectorStyle implements IVectorStyle { + static createDescriptor( + properties: VectorStylePropertiesDescriptor + ): VectorStylePropertiesDescriptor; + static createDefaultStyleProperties(mapColors: string[]): VectorStylePropertiesDescriptor; constructor(descriptor: VectorStyleDescriptor, source: IVectorSource, layer: IVectorLayer); getSourceFieldNames(): string[]; getAllStyleProperties(): IStyleProperty[]; diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index 229d6d0c6cf0c..f0feb6cd88962 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -9,11 +9,13 @@ import { EuiIcon } from '@elastic/eui'; import _ from 'lodash'; import { VectorStyle } from './styles/vector/vector_style'; import { SOURCE_DATA_ID_ORIGIN, LAYER_TYPE } from '../../common/constants'; -import { VectorLayer } from './vector_layer'; +import { VectorLayer, VectorLayerArguments } from './vector_layer'; import { canSkipSourceUpdate } from './util/can_skip_fetch'; import { ITiledSingleLayerVectorSource } from './sources/vector_source'; import { SyncContext } from '../actions/map_actions'; -import { TiledSingleLayerVectorSourceDescriptor } from '../../common/descriptor_types'; +import { ISource } from './sources/source'; +import { DataRequest } from './util/data_request'; +import { DataMeta, LayerDescriptor } from '../../common/descriptor_types'; export class SingleTiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; @@ -32,7 +34,7 @@ export class SingleTiledVectorLayer extends VectorLayer { private readonly _source: ITiledSingleLayerVectorSource; // downcast to the more specific type - constructor({ layerDescriptor, source }) { + constructor({ layerDescriptor, source }: VectorLayerArguments) { super({ layerDescriptor, source }); // reassignment is required due since _source is a shadowed property @@ -46,7 +48,7 @@ export class SingleTiledVectorLayer extends VectorLayer { }; } - _getSearchFilters(dataFilters) { + _getSearchFilters(dataFilters): DataMeta { const fieldNames = [...this._source.getFieldNames(), ...this._style.getSourceFieldNames()]; return { @@ -65,10 +67,11 @@ export class SingleTiledVectorLayer extends VectorLayer { dataFilters, }: SyncContext) { const requestToken: symbol = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`); - const searchFilters = this._getSearchFilters(dataFilters); + const searchFilters: DataMeta = this._getSearchFilters(dataFilters); const prevDataRequest = this.getSourceDataRequest(); + const canSkip = await canSkipSourceUpdate({ - source: this._source, + source: this._source as ISource, prevDataRequest, nextMeta: searchFilters, }); @@ -95,7 +98,7 @@ export class SingleTiledVectorLayer extends VectorLayer { await this._syncMVTUrlTemplate(syncContext); } - _syncSourceBindingWithMb(mbMap) { + _syncSourceBindingWithMb(mbMap: unknown) { const mbSource = mbMap.getSource(this.getId()); if (!mbSource) { const sourceDataRequest = this.getSourceDataRequest(); @@ -106,7 +109,17 @@ export class SingleTiledVectorLayer extends VectorLayer { return; } - const sourceMeta: TiledSingleLayerVectorSourceDescriptor = sourceDataRequest.getData() as TiledSingleLayerVectorSourceDescriptor; + const sourceMeta: { + layerName: string; + urlTemplate: string; + minZoom: number; + maxZoom: number; + } | null = sourceDataRequest.getData() as { + layerName: string; + urlTemplate: string; + minZoom: number; + maxZoom: number; + }; if (!sourceMeta) { return; } @@ -123,7 +136,8 @@ export class SingleTiledVectorLayer extends VectorLayer { } } - _syncStylePropertiesWithMb(mbMap) { + _syncStylePropertiesWithMb(mbMap: unknown) { + // @ts-ignore const mbSource = mbMap.getSource(this.getId()); if (!mbSource) { return; @@ -133,42 +147,63 @@ export class SingleTiledVectorLayer extends VectorLayer { if (!sourceDataRequest) { return; } - const sourceMeta: TiledSingleLayerVectorSourceMeta = sourceDataRequest.getData() as TiledSingleLayerVectorSourceMeta; + const sourceMeta: { + layerName: string; + } = sourceDataRequest.getData() as { + layerName: string; + }; const options = { mvtSourceLayer: sourceMeta.layerName }; this._setMbPointsProperties(mbMap, options); this._setMbLinePolygonProperties(mbMap, options); } - _requiresPrevSourceCleanup(mbMap) { - const tileSource = mbMap.getSource(this.getId()); - if (!tileSource) { + _requiresPrevSourceCleanup(mbMap: unknown) { + // @ts-ignore + const mbTileSource = mbMap.getSource(this.getId()); + if (!mbTileSource) { return false; } const dataRequest = this.getSourceDataRequest(); if (!dataRequest) { return false; } - const newUrl = dataRequest.getData(); - if (tileSource.tiles[0] === newUrl) { - // TileURL captures all the state. If this does not change, no updates are required. + const tiledSourceMeta: { + urlTemplate: string; + minZoom: number; + maxZoom: number; + } | null = dataRequest.getData() as { + urlTemplate: string; + minZoom: number; + maxZoom: number; + }; + if ( + mbTileSource.tiles[0] === tiledSourceMeta.urlTemplate && + mbTileSource.minzoom === tiledSourceMeta.minZoom && + mbTileSource.maxzoom === tiledSourceMeta.maxZoom + ) { + // TileURL and zoom-range captures all the state. If this does not change, no updates are required. return false; } return true; } - syncLayerWithMB(mbMap) { + syncLayerWithMB(mbMap: unknown) { const requiresCleanup = this._requiresPrevSourceCleanup(mbMap); if (requiresCleanup) { 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); } }); @@ -182,22 +217,6 @@ export class SingleTiledVectorLayer extends VectorLayer { return []; } - getGeometryByFeatureId(featureId, meta) { - return null; - } - - async getFeaturePropertiesByFeatureId(featureId, meta) { - const test = await this._source.filterAndFormatPropertiesToHtml({ - _id: meta.docId, - _index: meta.indexName, - }); - return test; - } - - async loadPreIndexedShapeByFeatureId(featureId, meta) { - return null; - } - getMinZoomForData(): number { return this._source.getMinZoom(); } diff --git a/x-pack/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/plugins/maps/public/layers/vector_layer.d.ts index 8530b63ba3dc8..239c82d68b480 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/layers/vector_layer.d.ts @@ -58,5 +58,10 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { source: IVectorSource, style: IVectorStyle ): VectorSourceRequestMeta; + syncLayerWithMb(mbMap: unknown): void; _syncData(syncContext: SyncContext, source: IVectorSource, style: IVectorStyle): Promise; + ownsMbSourceId(sourceId: string): boolean; + ownsMbLayerId(sourceId: string): boolean; + _setMbPointsProperties(mbMap: unknown, options: unknown): void; + _setMbLinePolygonProperties(mbMap: unknown, options: unknown): void; } From a4e5f92788359c2f19f9b341da704d7141943faa Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 8 Apr 2020 18:08:18 -0400 Subject: [PATCH 19/50] fix --- .../maps/public/layers/styles/vector/vector_style.d.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts b/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts index 2e19611efb014..b4568cd31cf2e 100644 --- a/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts +++ b/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts @@ -19,9 +19,7 @@ export interface IVectorStyle { } export class VectorStyle implements IVectorStyle { - static createDescriptor( - properties: VectorStylePropertiesDescriptor - ): VectorStylePropertiesDescriptor; + static createDescriptor(properties: VectorStylePropertiesDescriptor): VectorStyleDescriptor; static createDefaultStyleProperties(mapColors: string[]): VectorStylePropertiesDescriptor; constructor(descriptor: VectorStyleDescriptor, source: IVectorSource, layer: IVectorLayer); getSourceFieldNames(): string[]; From 63859cf0b43d206048c7af27aae4c718a92ffbd5 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 8 Apr 2020 22:43:10 -0400 Subject: [PATCH 20/50] typescript fixes --- .../data_request_descriptor_types.d.ts | 2 +- .../mvt_single_layer_vector_source.tsx | 30 +++++++++++++++++-- .../mvt_vector_source_editor.tsx | 6 ++-- .../maps/public/layers/sources/source.d.ts | 4 +-- .../public/layers/sources/vector_source.d.ts | 2 +- .../layers/styles/vector/vector_style.d.ts | 1 + .../maps/public/layers/tiled_vector_layer.tsx | 17 ++++++----- 7 files changed, 46 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.d.ts b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.d.ts index ceba2fe56db12..4ad827beff9c0 100644 --- a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.d.ts +++ b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.d.ts @@ -31,7 +31,7 @@ type ESGeoGridSourceSyncMeta = { requestType: RENDER_AS; }; -export type VectorSourceSyncMeta = ESSearchSourceSyncMeta | ESGeoGridSourceSyncMeta; +export type VectorSourceSyncMeta = ESSearchSourceSyncMeta | ESGeoGridSourceSyncMeta | null; export type VectorSourceRequestMeta = MapFilters & { applyGlobalQuery: boolean; diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 675d5b06fddc5..2ca70e56593e7 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -16,7 +16,12 @@ import { VECTOR_SHAPE_TYPES } from '../vector_feature_types'; import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters'; -import { TiledSingleLayerVectorSourceDescriptor } from '../../../../common/descriptor_types'; +import { + MapExtent, + TiledSingleLayerVectorSourceDescriptor, + VectorSourceRequestMeta, + VectorSourceSyncMeta, +} from '../../../../common/descriptor_types'; const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle', { defaultMessage: 'Vector Tile Layer', @@ -66,7 +71,7 @@ export class MVTSingleLayerVectorSource extends AbstractSource return null; } - createDefaultLayer(options): SingleTiledVectorLayer { + createDefaultLayer(options: unknown): SingleTiledVectorLayer { return new SingleTiledVectorLayer({ layerDescriptor: SingleTiledVectorLayer.createDescriptor( { @@ -129,6 +134,27 @@ export class MVTSingleLayerVectorSource extends AbstractSource getMaxZoom() { return this._descriptor.maxZoom; } + + getBoundsForFilters(searchFilters: VectorSourceRequestMeta): MapExtent { + return { + maxLat: 90, + maxLon: 180, + minLat: -90, + minLon: -180, + }; + } + + getFieldByName(fieldName: string): IField | null { + return null; + } + + getSyncMeta(): VectorSourceSyncMeta { + return null; + } + + getApplyGlobalQuery(): boolean { + return false; + } } registerSource({ diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index 2d95092fe279a..274f866fc069a 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -9,7 +9,7 @@ import _ from 'lodash'; import { EuiFieldText, EuiFormRow } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { MAX_ZOOM, MIN_ZOOM } from '../../../../common/constants'; -import { ValidatedDualRange } from '../../../../../../../src/plugins/kibana_react/public'; +import { ValidatedDualRange, Value } from '../../../../../../../src/plugins/kibana_react/public'; export class MVTVectorSourceEditor extends React.Component { state = { @@ -31,6 +31,7 @@ export class MVTVectorSourceEditor extends React.Component { } }, 2000); + // @ts-ignore _handleUrlTemplateChange = e => { const url = e.target.value; @@ -45,6 +46,7 @@ export class MVTVectorSourceEditor extends React.Component { ); }; + // @ts-ignore _handleLayerNameInputChange = e => { const layerName = e.target.value; this.setState( @@ -55,7 +57,7 @@ export class MVTVectorSourceEditor extends React.Component { ); }; - _handleZoomRangeChange = e => { + _handleZoomRangeChange = (e: Value) => { const minZoom = parseInt(e[0], 10); const maxZoom = parseInt(e[1], 10); diff --git a/x-pack/plugins/maps/public/layers/sources/source.d.ts b/x-pack/plugins/maps/public/layers/sources/source.d.ts index 34bdd3444aed3..4ceb350fc0e27 100644 --- a/x-pack/plugins/maps/public/layers/sources/source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/source.d.ts @@ -8,7 +8,7 @@ import { AbstractSourceDescriptor } from '../../../common/descriptor_types'; import { ILayer } from '../layer'; export interface ISource { - createDefaultLayer(): ILayer; + createDefaultLayer(options: unknown): ILayer; destroy(): void; getDisplayName(): Promise; getInspectorAdapters(): object; @@ -25,7 +25,7 @@ export class AbstractSource implements ISource { constructor(sourceDescriptor: AbstractSourceDescriptor, inspectorAdapters: object); destroy(): void; - createDefaultLayer(): ILayer; + createDefaultLayer(options: unknown): ILayer; getDisplayName(): Promise; getInspectorAdapters(): object; isFieldAware(): boolean; diff --git a/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts b/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts index cff11ca04add9..e3ee38e25de3c 100644 --- a/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/vector_source.d.ts @@ -33,7 +33,7 @@ export interface IVectorSource extends ISource { ): Promise; getFields(): Promise; - getFieldByName(fieldName: string): IField; + getFieldByName(fieldName: string): IField | null; getSyncMeta(): VectorSourceSyncMeta; getFieldNames(): string[]; getApplyGlobalQuery(): boolean; diff --git a/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts b/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts index b4568cd31cf2e..e010d5ac7d7a3 100644 --- a/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts +++ b/x-pack/plugins/maps/public/layers/styles/vector/vector_style.d.ts @@ -16,6 +16,7 @@ export interface IVectorStyle { getAllStyleProperties(): IStyleProperty[]; getDescriptor(): VectorStyleDescriptor; getDynamicPropertiesArray(): IDynamicStyleProperty[]; + getSourceFieldNames(): string[]; } export class VectorStyle implements IVectorStyle { diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index f0feb6cd88962..84b436c0fc522 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -7,20 +7,19 @@ import React from 'react'; import { EuiIcon } from '@elastic/eui'; import _ from 'lodash'; -import { VectorStyle } from './styles/vector/vector_style'; +import { IVectorStyle, 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 } from './sources/vector_source'; +import { ITiledSingleLayerVectorSource, IVectorSource } from './sources/vector_source'; import { SyncContext } from '../actions/map_actions'; import { ISource } from './sources/source'; -import { DataRequest } from './util/data_request'; -import { DataMeta, LayerDescriptor } from '../../common/descriptor_types'; +import { DataMeta, MapFilters, VectorLayerDescriptor } from '../../common/descriptor_types'; export class SingleTiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; - static createDescriptor(options, mapColors) { + static createDescriptor(options: VectorLayerDescriptor, mapColors: string[]) { const layerDescriptor = super.createDescriptor(options, mapColors); layerDescriptor.type = SingleTiledVectorLayer.type; @@ -48,8 +47,8 @@ export class SingleTiledVectorLayer extends VectorLayer { }; } - _getSearchFilters(dataFilters): DataMeta { - const fieldNames = [...this._source.getFieldNames(), ...this._style.getSourceFieldNames()]; + _getSearchFilters(dataFilters: MapFilters, source: IVectorSource, style: IVectorStyle): DataMeta { + const fieldNames = [...source.getFieldNames(), ...style.getSourceFieldNames()]; return { ...dataFilters, @@ -88,7 +87,7 @@ export class SingleTiledVectorLayer extends VectorLayer { } } - async syncData(syncContext) { + async syncData(syncContext: SyncContext) { if (!this.isVisible() || !this.showAtZoomLevel(syncContext.dataFilters.zoom)) { return; } @@ -99,6 +98,7 @@ export class SingleTiledVectorLayer extends VectorLayer { } _syncSourceBindingWithMb(mbMap: unknown) { + // @ts-ignore const mbSource = mbMap.getSource(this.getId()); if (!mbSource) { const sourceDataRequest = this.getSourceDataRequest(); @@ -192,6 +192,7 @@ export class SingleTiledVectorLayer extends VectorLayer { syncLayerWithMB(mbMap: unknown) { const requiresCleanup = this._requiresPrevSourceCleanup(mbMap); if (requiresCleanup) { + // @ts-ignore const mbStyle = mbMap.getStyle(); // @ts-ignore mbStyle.layers.forEach(mbLayer => { From dc266e855cfd686c002eb67734f9ae5c875e55b6 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 8 Apr 2020 22:58:17 -0400 Subject: [PATCH 21/50] ts fixes --- src/plugins/kibana_react/public/index.ts | 2 +- .../mvt_single_layer_vector_source.tsx | 10 +++------- x-pack/plugins/maps/public/layers/sources/source.d.ts | 8 ++++---- .../plugins/maps/public/layers/tiled_vector_layer.tsx | 6 +++++- x-pack/plugins/maps/public/layers/vector_layer.d.ts | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/plugins/kibana_react/public/index.ts b/src/plugins/kibana_react/public/index.ts index e1689e38dbfe0..de8f35cf85eef 100644 --- a/src/plugins/kibana_react/public/index.ts +++ b/src/plugins/kibana_react/public/index.ts @@ -25,7 +25,7 @@ export * from './ui_settings'; export * from './field_icon'; export * from './table_list_view'; export * from './split_panel'; -export { ValidatedDualRange } from './validated_range'; +export { ValidatedDualRange, Value } from './validated_range'; export * from './notifications'; export { Markdown, MarkdownSimple } from './markdown'; export { reactToUiComponent, uiToReactComponent } from './adapters'; diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 2ca70e56593e7..e70be8faf404f 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -17,6 +17,7 @@ import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters'; import { + LayerDescriptor, MapExtent, TiledSingleLayerVectorSourceDescriptor, VectorSourceRequestMeta, @@ -44,12 +45,7 @@ export class MVTSingleLayerVectorSource extends AbstractSource layerName, minZoom, maxZoom, - }: { - urlTemplate: string; - layerName: string; - minZoom: number; - maxZoom: number; - }) { + }: TiledSingleLayerVectorSourceDescriptor) { return { type: MVTSingleLayerVectorSource.type, id: uuid(), @@ -71,7 +67,7 @@ export class MVTSingleLayerVectorSource extends AbstractSource return null; } - createDefaultLayer(options: unknown): SingleTiledVectorLayer { + createDefaultLayer(options: LayerDescriptor): SingleTiledVectorLayer { return new SingleTiledVectorLayer({ layerDescriptor: SingleTiledVectorLayer.createDescriptor( { diff --git a/x-pack/plugins/maps/public/layers/sources/source.d.ts b/x-pack/plugins/maps/public/layers/sources/source.d.ts index 4ceb350fc0e27..cfe4edacf83cf 100644 --- a/x-pack/plugins/maps/public/layers/sources/source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/source.d.ts @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { AbstractSourceDescriptor } from '../../../common/descriptor_types'; +import { AbstractSourceDescriptor, LayerDescriptor } from '../../../common/descriptor_types'; import { ILayer } from '../layer'; export interface ISource { - createDefaultLayer(options: unknown): ILayer; + createDefaultLayer(options: LayerDescriptor | undefined): ILayer; destroy(): void; getDisplayName(): Promise; getInspectorAdapters(): object; @@ -21,11 +21,11 @@ export interface ISource { } export class AbstractSource implements ISource { - readonly _descriptor: AbstractSourceDescriptor; + private readonly _descriptor: AbstractSourceDescriptor; constructor(sourceDescriptor: AbstractSourceDescriptor, inspectorAdapters: object); destroy(): void; - createDefaultLayer(options: unknown): ILayer; + createDefaultLayer(options: LayerDescriptor): ILayer; getDisplayName(): Promise; getInspectorAdapters(): object; isFieldAware(): boolean; diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index 84b436c0fc522..fecb50f7ffed7 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -66,7 +66,11 @@ export class SingleTiledVectorLayer extends VectorLayer { dataFilters, }: SyncContext) { const requestToken: symbol = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`); - const searchFilters: DataMeta = this._getSearchFilters(dataFilters); + const searchFilters: DataMeta = this._getSearchFilters( + dataFilters, + this.getSource(), + this._style + ); const prevDataRequest = this.getSourceDataRequest(); const canSkip = await canSkipSourceUpdate({ diff --git a/x-pack/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/plugins/maps/public/layers/vector_layer.d.ts index 239c82d68b480..51b9072678a34 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/layers/vector_layer.d.ts @@ -58,7 +58,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { source: IVectorSource, style: IVectorStyle ): VectorSourceRequestMeta; - syncLayerWithMb(mbMap: unknown): void; + syncLayerWithMB(mbMap: unknown): void; _syncData(syncContext: SyncContext, source: IVectorSource, style: IVectorStyle): Promise; ownsMbSourceId(sourceId: string): boolean; ownsMbLayerId(sourceId: string): boolean; From 2bf0a0db7f85b7c604bf57f487048e00ef36edd2 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 8 Apr 2020 23:54:24 -0400 Subject: [PATCH 22/50] ts issues --- .../kibana_react/public/validated_range/index.ts | 2 +- x-pack/plugins/maps/public/layers/layer.d.ts | 4 ++-- .../mvt_single_layer_vector_source.tsx | 9 +++++---- .../mvt_vector_source/mvt_vector_source_editor.tsx | 4 ++-- .../plugins/maps/public/layers/sources/source.d.ts | 4 ++-- .../maps/public/layers/sources/tms_source.d.ts | 2 ++ .../plugins/maps/public/layers/tile_layer.test.ts | 2 +- .../maps/public/layers/tiled_vector_layer.tsx | 14 +++++++++----- .../plugins/maps/public/layers/vector_layer.d.ts | 2 ++ 9 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/plugins/kibana_react/public/validated_range/index.ts b/src/plugins/kibana_react/public/validated_range/index.ts index bc643373f5e60..7d720ec842a43 100644 --- a/src/plugins/kibana_react/public/validated_range/index.ts +++ b/src/plugins/kibana_react/public/validated_range/index.ts @@ -17,4 +17,4 @@ * under the License. */ -export { ValidatedDualRange } from './validated_dual_range'; +export { ValidatedDualRange, Value } from './validated_dual_range'; diff --git a/x-pack/plugins/maps/public/layers/layer.d.ts b/x-pack/plugins/maps/public/layers/layer.d.ts index 1ead9bcd14f91..9a83221c6d5be 100644 --- a/x-pack/plugins/maps/public/layers/layer.d.ts +++ b/x-pack/plugins/maps/public/layers/layer.d.ts @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { LayerDescriptor, MapExtent, MapFilters } from '../../common/descriptor_types'; +import { LayerDescriptor, MapExtent, MapFilters, MapQuery } from '../../common/descriptor_types'; import { ISource } from './sources/source'; import { DataRequest } from './util/data_request'; import { SyncContext } from '../actions/map_actions'; @@ -46,5 +46,5 @@ export class AbstractLayer implements ILayer { getMaxZoomForData(): number; getMinZoom(): number; getMaxZoom(): number; - getQuery(): string; + getQuery(): MapQuery; } diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index e70be8faf404f..ca7b5ed438e8c 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -56,11 +56,11 @@ export class MVTSingleLayerVectorSource extends AbstractSource }; } - private readonly _descriptor: TiledSingleLayerVectorSourceDescriptor; + readonly _descriptor: TiledSingleLayerVectorSourceDescriptor; - constructor(descriptor: TiledSingleLayerVectorSourceDescriptor, adapters: object) { - super(descriptor, adapters); - this._descriptor = descriptor; // re-assignment is required due to TS-JS transpilation, not the type-system + constructor(sourceDescriptor: TiledSingleLayerVectorSourceDescriptor, inspectorAdapters: object) { + super(sourceDescriptor, inspectorAdapters); + this._descriptor = sourceDescriptor; // re-assignment is required due to TS-JS transpilation, not the type-system } renderSourceSettingsEditor() { @@ -186,6 +186,7 @@ export const mvtVectorSourceWizardConfig = { layerName, minZoom, maxZoom, + type: MVTSingleLayerVectorSource.type, }); const source = new MVTSingleLayerVectorSource(sourceDescriptor, inspectorAdapters); onPreviewSource(source); diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index 274f866fc069a..1146b16541cc0 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -58,8 +58,8 @@ export class MVTVectorSourceEditor extends React.Component { }; _handleZoomRangeChange = (e: Value) => { - const minZoom = parseInt(e[0], 10); - const maxZoom = parseInt(e[1], 10); + const minZoom = parseInt(e[0] as string, 10); + const maxZoom = parseInt(e[1] as string, 10); if (this.state.minZoom !== minZoom || this.state.maxZoom !== maxZoom) { this.setState({ minZoom, maxZoom }, () => this._sourceConfigChange()); diff --git a/x-pack/plugins/maps/public/layers/sources/source.d.ts b/x-pack/plugins/maps/public/layers/sources/source.d.ts index cfe4edacf83cf..eb8cb9e5dbbeb 100644 --- a/x-pack/plugins/maps/public/layers/sources/source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/source.d.ts @@ -21,11 +21,11 @@ export interface ISource { } export class AbstractSource implements ISource { - private readonly _descriptor: AbstractSourceDescriptor; + readonly _descriptor: AbstractSourceDescriptor; constructor(sourceDescriptor: AbstractSourceDescriptor, inspectorAdapters: object); destroy(): void; - createDefaultLayer(options: LayerDescriptor): ILayer; + createDefaultLayer(options: LayerDescriptor | undefined): ILayer; getDisplayName(): Promise; getInspectorAdapters(): object; isFieldAware(): boolean; diff --git a/x-pack/plugins/maps/public/layers/sources/tms_source.d.ts b/x-pack/plugins/maps/public/layers/sources/tms_source.d.ts index 90b6f28e050fd..560431a05e642 100644 --- a/x-pack/plugins/maps/public/layers/sources/tms_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/tms_source.d.ts @@ -5,11 +5,13 @@ */ import { AbstractSource, ISource } from './source'; +import { XYZTMSSourceDescriptor } from '../../../common/descriptor_types'; export interface ITMSSource extends ISource { getUrlTemplate(): Promise; } export class AbstractTMSSource extends AbstractSource implements ITMSSource { + readonly _descriptor: XYZTMSSourceDescriptor; getUrlTemplate(): Promise; } diff --git a/x-pack/plugins/maps/public/layers/tile_layer.test.ts b/x-pack/plugins/maps/public/layers/tile_layer.test.ts index 1cb99dcbc1a70..43465eac7f3ce 100644 --- a/x-pack/plugins/maps/public/layers/tile_layer.test.ts +++ b/x-pack/plugins/maps/public/layers/tile_layer.test.ts @@ -17,7 +17,7 @@ const sourceDescriptor: XYZTMSSourceDescriptor = { }; class MockTileSource extends AbstractTMSSource implements ITMSSource { - private readonly _descriptor: XYZTMSSourceDescriptor; + readonly _descriptor: XYZTMSSourceDescriptor; constructor(descriptor: XYZTMSSourceDescriptor) { super(descriptor, {}); this._descriptor = descriptor; diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index fecb50f7ffed7..187def6d549c6 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -14,16 +14,16 @@ import { canSkipSourceUpdate } from './util/can_skip_fetch'; import { ITiledSingleLayerVectorSource, IVectorSource } from './sources/vector_source'; import { SyncContext } from '../actions/map_actions'; import { ISource } from './sources/source'; -import { DataMeta, MapFilters, VectorLayerDescriptor } from '../../common/descriptor_types'; +import { DataMeta, MapFilters, VectorSourceRequestMeta } from '../../common/descriptor_types'; export class SingleTiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; - static createDescriptor(options: VectorLayerDescriptor, mapColors: string[]) { + static createDescriptor(options: VectorLayerArguments, mapColors: string[]) { const layerDescriptor = super.createDescriptor(options, mapColors); layerDescriptor.type = SingleTiledVectorLayer.type; - if (!options.style) { + if (!layerDescriptor.style) { const styleProperties = VectorStyle.createDefaultStyleProperties(mapColors); layerDescriptor.style = VectorStyle.createDescriptor(styleProperties); } @@ -31,7 +31,7 @@ export class SingleTiledVectorLayer extends VectorLayer { return layerDescriptor; } - private readonly _source: ITiledSingleLayerVectorSource; // downcast to the more specific type + readonly _source: ITiledSingleLayerVectorSource; // downcast to the more specific type constructor({ layerDescriptor, source }: VectorLayerArguments) { super({ layerDescriptor, source }); @@ -47,7 +47,11 @@ export class SingleTiledVectorLayer extends VectorLayer { }; } - _getSearchFilters(dataFilters: MapFilters, source: IVectorSource, style: IVectorStyle): DataMeta { + _getSearchFilters( + dataFilters: MapFilters, + source: IVectorSource, + style: IVectorStyle + ): VectorSourceRequestMeta { const fieldNames = [...source.getFieldNames(), ...style.getSourceFieldNames()]; return { diff --git a/x-pack/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/plugins/maps/public/layers/vector_layer.d.ts index 51b9072678a34..6fae9264165c1 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/layers/vector_layer.d.ts @@ -28,6 +28,7 @@ export interface IVectorLayer extends ILayer { getFields(): Promise; getStyleEditorFields(): Promise; getValidJoins(): IJoin[]; + getSource(): IVectorSource; } export class VectorLayer extends AbstractLayer implements IVectorLayer { @@ -64,4 +65,5 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { ownsMbLayerId(sourceId: string): boolean; _setMbPointsProperties(mbMap: unknown, options: unknown): void; _setMbLinePolygonProperties(mbMap: unknown, options: unknown): void; + getSource(): IVectorSource; } From f603d439401e270c89f29be191b4fecded1bcd2e Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 8 Apr 2020 23:58:06 -0400 Subject: [PATCH 23/50] make optional --- x-pack/plugins/maps/public/layers/sources/source.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/sources/source.d.ts b/x-pack/plugins/maps/public/layers/sources/source.d.ts index eb8cb9e5dbbeb..4863a6d01bdea 100644 --- a/x-pack/plugins/maps/public/layers/sources/source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/source.d.ts @@ -8,7 +8,7 @@ import { AbstractSourceDescriptor, LayerDescriptor } from '../../../common/descr import { ILayer } from '../layer'; export interface ISource { - createDefaultLayer(options: LayerDescriptor | undefined): ILayer; + createDefaultLayer(options?: LayerDescriptor): ILayer; destroy(): void; getDisplayName(): Promise; getInspectorAdapters(): object; @@ -25,7 +25,7 @@ export class AbstractSource implements ISource { constructor(sourceDescriptor: AbstractSourceDescriptor, inspectorAdapters: object); destroy(): void; - createDefaultLayer(options: LayerDescriptor | undefined): ILayer; + createDefaultLayer(options?: LayerDescriptor): ILayer; getDisplayName(): Promise; getInspectorAdapters(): object; isFieldAware(): boolean; From da46cf398fe0bf119ab0a934c86b27419bf60041 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 9 Apr 2020 09:52:16 -0400 Subject: [PATCH 24/50] tslint --- .../common/descriptor_types/descriptor_types.d.ts | 4 +--- .../maps/public/layers/sources/source.d.ts | 2 +- .../maps/public/layers/sources/source_registry.ts | 2 +- .../public/layers/sources/xyz_tms_source.d.ts | 2 +- .../public/layers/sources/xyz_tms_source.test.ts | 2 +- .../maps/public/layers/styles/abstract_style.js | 8 ++++---- .../vector/components/vector_style_editor.js | 1 - .../maps/public/layers/tiled_vector_layer.tsx | 15 ++++++++++----- 8 files changed, 19 insertions(+), 17 deletions(-) diff --git a/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts b/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts index 79594ff3d2c23..f6e3af812f1fe 100644 --- a/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts +++ b/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts @@ -96,9 +96,7 @@ export type TiledSingleLayerVectorSourceDescriptor = AbstractSourceDescriptor & maxZoom: number; }; -export type XYZTMSSourceDescriptor = { - id: string; - type: string; +export type XYZTMSSourceDescriptor = AbstractSourceDescriptor & { urlTemplate: string; }; diff --git a/x-pack/plugins/maps/public/layers/sources/source.d.ts b/x-pack/plugins/maps/public/layers/sources/source.d.ts index 4863a6d01bdea..aae172bcd3344 100644 --- a/x-pack/plugins/maps/public/layers/sources/source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/source.d.ts @@ -22,7 +22,7 @@ export interface ISource { export class AbstractSource implements ISource { readonly _descriptor: AbstractSourceDescriptor; - constructor(sourceDescriptor: AbstractSourceDescriptor, inspectorAdapters: object); + constructor(sourceDescriptor: AbstractSourceDescriptor, inspectorAdapters?: object); destroy(): void; createDefaultLayer(options?: LayerDescriptor): ILayer; diff --git a/x-pack/plugins/maps/public/layers/sources/source_registry.ts b/x-pack/plugins/maps/public/layers/sources/source_registry.ts index 822cb06f177be..9b61e97b335ed 100644 --- a/x-pack/plugins/maps/public/layers/sources/source_registry.ts +++ b/x-pack/plugins/maps/public/layers/sources/source_registry.ts @@ -11,7 +11,7 @@ import { ISource } from './source'; type SourceRegistryEntry = { ConstructorFunction: new ( sourceDescriptor: AbstractSourceDescriptor, - inspectorAdapters: object + inspectorAdapters?: object ) => ISource; type: string; }; diff --git a/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.d.ts b/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.d.ts index 3d4d1868fed9a..4a614863fa8a2 100644 --- a/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.d.ts @@ -8,7 +8,7 @@ import { XYZTMSSourceDescriptor } from '../../../common/descriptor_types'; import { LayerWizard } from '../layer_wizard_registry'; export class XYZTMSSource extends AbstractTMSSource { - constructor(sourceDescriptor: XYZTMSSourceDescriptor, inspectorAdapters: unknown); + constructor(sourceDescriptor: XYZTMSSourceDescriptor, inspectorAdapters?: object); } export const tmsLayerWizardConfig: LayerWizard; diff --git a/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.test.ts b/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.test.ts index e5ab5e57122ba..6c91488f2a4a0 100644 --- a/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.test.ts +++ b/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.test.ts @@ -17,7 +17,7 @@ const descriptor: XYZTMSSourceDescriptor = { }; describe('xyz Tilemap Source', () => { it('should create a tile-layer', () => { - const source = new XYZTMSSource(descriptor, null); + const source = new XYZTMSSource(descriptor); const layer: ILayer = source.createDefaultLayer(); expect(layer instanceof TileLayer).toEqual(true); }); diff --git a/x-pack/plugins/maps/public/layers/styles/abstract_style.js b/x-pack/plugins/maps/public/layers/styles/abstract_style.js index 9808efdcdb5b0..3e7a3dbf7ed20 100644 --- a/x-pack/plugins/maps/public/layers/styles/abstract_style.js +++ b/x-pack/plugins/maps/public/layers/styles/abstract_style.js @@ -15,14 +15,14 @@ export class AbstractStyle { return {}; } - renderEditor(/* { layer, onStyleDescriptorChange } */) { - return null; - } - getDescriptor() { return this._descriptor; } + renderEditor(/* { layer, onStyleDescriptorChange } */) { + return null; + } + getSourceFieldNames() { return []; } diff --git a/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js b/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js index d3895d63ea89d..c46dc2cb4b73e 100644 --- a/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js +++ b/x-pack/plugins/maps/public/layers/styles/vector/components/vector_style_editor.js @@ -95,7 +95,6 @@ export class VectorStyleEditor extends Component { this.setState({ supportedFeatures }); } - //todo: this should be fixed separately if (this.state.selectedFeature === null) { let selectedFeature = VECTOR_SHAPE_TYPES.POLYGON; if (this.props.isPointsOnly) { diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index 187def6d549c6..ec480a96108f6 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -14,12 +14,20 @@ import { canSkipSourceUpdate } from './util/can_skip_fetch'; import { ITiledSingleLayerVectorSource, IVectorSource } from './sources/vector_source'; import { SyncContext } from '../actions/map_actions'; import { ISource } from './sources/source'; -import { DataMeta, MapFilters, VectorSourceRequestMeta } from '../../common/descriptor_types'; +import { + DataMeta, + MapFilters, + VectorLayerDescriptor, + VectorSourceRequestMeta, +} from '../../common/descriptor_types'; export class SingleTiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; - static createDescriptor(options: VectorLayerArguments, mapColors: string[]) { + static createDescriptor( + options: VectorLayerArguments, + mapColors: string[] + ): VectorLayerDescriptor { const layerDescriptor = super.createDescriptor(options, mapColors); layerDescriptor.type = SingleTiledVectorLayer.type; @@ -35,9 +43,6 @@ export class SingleTiledVectorLayer extends VectorLayer { constructor({ layerDescriptor, source }: VectorLayerArguments) { super({ layerDescriptor, source }); - - // reassignment is required due since _source is a shadowed property - // and in the transpiled JS-code, the .source assignment in super() is getting voided in this constructor. this._source = source as ITiledSingleLayerVectorSource; } From b8953520ae147ed16b3d4cc401079b1e7a245cd8 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 9 Apr 2020 10:57:28 -0400 Subject: [PATCH 25/50] remove unused --- .../data_request_descriptor_types.d.ts | 2 +- .../mvt_single_layer_vector_source.tsx | 30 ++++++++++++------- .../layers/sources/xyz_tms_source.test.ts | 2 +- .../maps/public/layers/tiled_vector_layer.tsx | 27 +++++++---------- .../maps/public/layers/vector_layer.d.ts | 5 ---- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.d.ts b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.d.ts index 4ad827beff9c0..b6cbb4aaf8a5f 100644 --- a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.d.ts +++ b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.d.ts @@ -36,7 +36,7 @@ export type VectorSourceSyncMeta = ESSearchSourceSyncMeta | ESGeoGridSourceSyncM export type VectorSourceRequestMeta = MapFilters & { applyGlobalQuery: boolean; fieldNames: string[]; - geogridPrecision: number; + geogridPrecision?: number; sourceQuery: MapQuery; sourceMeta: VectorSourceSyncMeta; }; diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index ca7b5ed438e8c..7d08dca78d831 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -23,6 +23,7 @@ import { VectorSourceRequestMeta, VectorSourceSyncMeta, } from '../../../../common/descriptor_types'; +import { VectorLayerArguments } from '../../vector_layer'; const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle', { defaultMessage: 'Vector Tile Layer', @@ -58,9 +59,12 @@ export class MVTSingleLayerVectorSource extends AbstractSource readonly _descriptor: TiledSingleLayerVectorSourceDescriptor; - constructor(sourceDescriptor: TiledSingleLayerVectorSourceDescriptor, inspectorAdapters: object) { + constructor( + sourceDescriptor: TiledSingleLayerVectorSourceDescriptor, + inspectorAdapters?: object + ) { super(sourceDescriptor, inspectorAdapters); - this._descriptor = sourceDescriptor; // re-assignment is required due to TS-JS transpilation, not the type-system + this._descriptor = sourceDescriptor; } renderSourceSettingsEditor() { @@ -68,16 +72,20 @@ export class MVTSingleLayerVectorSource extends AbstractSource } createDefaultLayer(options: LayerDescriptor): SingleTiledVectorLayer { - return new SingleTiledVectorLayer({ - layerDescriptor: SingleTiledVectorLayer.createDescriptor( - { - sourceDescriptor: this._descriptor, - ...options, - }, - [] - ), + const layerDescriptor = { + sourceDescriptor: this._descriptor, + ...options, + }; + const normalizedLayerDescriptor: LayerDescriptor = SingleTiledVectorLayer.createDescriptor( + { layerDescriptor, source: this }, + [] + ); + const vectorLayerArguments: VectorLayerArguments = { + layerDescriptor: normalizedLayerDescriptor, source: this, - }); + ...options, + }; + return new SingleTiledVectorLayer(vectorLayerArguments); } getGeoJsonWithMeta( diff --git a/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.test.ts b/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.test.ts index 6c91488f2a4a0..5d2d85d5ba275 100644 --- a/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.test.ts +++ b/x-pack/plugins/maps/public/layers/sources/xyz_tms_source.test.ts @@ -23,7 +23,7 @@ describe('xyz Tilemap Source', () => { }); it('should echo url template for url template', async () => { - const source = new XYZTMSSource(descriptor, null); + const source = new XYZTMSSource(descriptor); const template = await source.getUrlTemplate(); expect(template).toEqual(descriptor.urlTemplate); }); diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index ec480a96108f6..3c4d048f94cb5 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -15,7 +15,6 @@ import { ITiledSingleLayerVectorSource, IVectorSource } from './sources/vector_s import { SyncContext } from '../actions/map_actions'; import { ISource } from './sources/source'; import { - DataMeta, MapFilters, VectorLayerDescriptor, VectorSourceRequestMeta, @@ -25,10 +24,10 @@ export class SingleTiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; static createDescriptor( - options: VectorLayerArguments, + vectorLayerArguments: VectorLayerArguments, mapColors: string[] ): VectorLayerDescriptor { - const layerDescriptor = super.createDescriptor(options, mapColors); + const layerDescriptor = super.createDescriptor(vectorLayerArguments, mapColors); layerDescriptor.type = SingleTiledVectorLayer.type; if (!layerDescriptor.style) { @@ -53,29 +52,25 @@ export class SingleTiledVectorLayer extends VectorLayer { } _getSearchFilters( - dataFilters: MapFilters, + mapFilters: MapFilters, source: IVectorSource, style: IVectorStyle ): VectorSourceRequestMeta { const fieldNames = [...source.getFieldNames(), ...style.getSourceFieldNames()]; - return { - ...dataFilters, - fieldNames: _.uniq(fieldNames).sort(), - sourceQuery: this.getQuery(), + const requestMeta: VectorSourceRequestMeta = { + ...mapFilters, applyGlobalQuery: this._source.getApplyGlobalQuery(), + fieldNames, + sourceQuery: this.getQuery(), }; + + return requestMeta; } - async _syncMVTUrlTemplate({ - startLoading, - stopLoading, - onLoadError, - registerCancelCallback, - dataFilters, - }: SyncContext) { + async _syncMVTUrlTemplate({ startLoading, stopLoading, onLoadError, dataFilters }: SyncContext) { const requestToken: symbol = Symbol(`layer-${this.getId()}-${SOURCE_DATA_ID_ORIGIN}`); - const searchFilters: DataMeta = this._getSearchFilters( + const searchFilters: VectorSourceRequestMeta = this._getSearchFilters( dataFilters, this.getSource(), this._style diff --git a/x-pack/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/plugins/maps/public/layers/vector_layer.d.ts index 6fae9264165c1..c1e5806ecc7bf 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/layers/vector_layer.d.ts @@ -54,11 +54,6 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { source: IVectorSource, style: IVectorStyle ): Promise; - _getSearchFilters( - dataFilters: MapFilters, - source: IVectorSource, - style: IVectorStyle - ): VectorSourceRequestMeta; syncLayerWithMB(mbMap: unknown): void; _syncData(syncContext: SyncContext, source: IVectorSource, style: IVectorStyle): Promise; ownsMbSourceId(sourceId: string): boolean; From 483b77b49817bd7862aed1ab0f8225c71cd871ca Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 9 Apr 2020 12:23:04 -0400 Subject: [PATCH 26/50] fix layer descriptor typung --- .../legacy/plugins/maps/public/selectors/map_selectors.js | 1 + x-pack/plugins/maps/public/layers/blended_vector_layer.ts | 3 ++- x-pack/plugins/maps/public/layers/layer.d.ts | 1 + .../mvt_vector_source/mvt_single_layer_vector_source.tsx | 8 ++++---- x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx | 4 ++-- x-pack/plugins/maps/public/layers/vector_layer.d.ts | 6 ++---- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index 26e5373431bda..c7104586ae4d8 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -32,6 +32,7 @@ import { InnerJoin } from '../../../../../plugins/maps/public/layers/joins/inner import { getSourceByType } from '../../../../../plugins/maps/public/layers/sources/source_registry'; function createLayerInstance(layerDescriptor, inspectorAdapters) { + console.log('lauyer inst', layerDescriptor); const source = createSourceInstance(layerDescriptor.sourceDescriptor, inspectorAdapters); switch (layerDescriptor.type) { diff --git a/x-pack/plugins/maps/public/layers/blended_vector_layer.ts b/x-pack/plugins/maps/public/layers/blended_vector_layer.ts index f5526ad703dd2..cd5f75cf9a92a 100644 --- a/x-pack/plugins/maps/public/layers/blended_vector_layer.ts +++ b/x-pack/plugins/maps/public/layers/blended_vector_layer.ts @@ -34,6 +34,7 @@ import { VectorStyleDescriptor, SizeDynamicOptions, DynamicStylePropertyOptions, + VectorLayerDescriptor, } from '../../common/descriptor_types'; const ACTIVE_COUNT_DATA_ID = 'ACTIVE_COUNT_DATA_ID'; @@ -147,7 +148,7 @@ function getClusterStyleDescriptor( export class BlendedVectorLayer extends VectorLayer implements IVectorLayer { static type = LAYER_TYPE.BLENDED_VECTOR; - static createDescriptor(options: VectorLayerArguments, mapColors: string[]) { + static createDescriptor(options: VectorLayerDescriptor, mapColors: string[]) { const layerDescriptor = VectorLayer.createDescriptor(options, mapColors); layerDescriptor.type = BlendedVectorLayer.type; return layerDescriptor; diff --git a/x-pack/plugins/maps/public/layers/layer.d.ts b/x-pack/plugins/maps/public/layers/layer.d.ts index 9a83221c6d5be..d389fe28356a3 100644 --- a/x-pack/plugins/maps/public/layers/layer.d.ts +++ b/x-pack/plugins/maps/public/layers/layer.d.ts @@ -31,6 +31,7 @@ export interface ILayerArguments { } export class AbstractLayer implements ILayer { + static createDescriptor(options: LayerDescriptor, mapColors: string[]): LayerDescriptor; constructor(layerArguments: ILayerArguments); getBounds(mapFilters: MapFilters): Promise; getDataRequest(id: string): DataRequest | undefined; diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 7d08dca78d831..cec6fe8503369 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -20,6 +20,7 @@ import { LayerDescriptor, MapExtent, TiledSingleLayerVectorSourceDescriptor, + VectorLayerDescriptor, VectorSourceRequestMeta, VectorSourceSyncMeta, } from '../../../../common/descriptor_types'; @@ -71,19 +72,18 @@ export class MVTSingleLayerVectorSource extends AbstractSource return null; } - createDefaultLayer(options: LayerDescriptor): SingleTiledVectorLayer { + createDefaultLayer(options: VectorLayerDescriptor): SingleTiledVectorLayer { const layerDescriptor = { sourceDescriptor: this._descriptor, ...options, }; - const normalizedLayerDescriptor: LayerDescriptor = SingleTiledVectorLayer.createDescriptor( - { layerDescriptor, source: this }, + const normalizedLayerDescriptor: VectorLayerDescriptor = SingleTiledVectorLayer.createDescriptor( + layerDescriptor, [] ); const vectorLayerArguments: VectorLayerArguments = { layerDescriptor: normalizedLayerDescriptor, source: this, - ...options, }; return new SingleTiledVectorLayer(vectorLayerArguments); } diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index 3c4d048f94cb5..3e441f58e64ad 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -24,10 +24,10 @@ export class SingleTiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; static createDescriptor( - vectorLayerArguments: VectorLayerArguments, + descriptor: VectorLayerDescriptor, mapColors: string[] ): VectorLayerDescriptor { - const layerDescriptor = super.createDescriptor(vectorLayerArguments, mapColors); + const layerDescriptor = super.createDescriptor(descriptor, mapColors); layerDescriptor.type = SingleTiledVectorLayer.type; if (!layerDescriptor.style) { diff --git a/x-pack/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/plugins/maps/public/layers/vector_layer.d.ts index c1e5806ecc7bf..22ae1789fb5de 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/layers/vector_layer.d.ts @@ -8,6 +8,7 @@ import { AbstractLayer } from './layer'; import { IVectorSource } from './sources/vector_source'; import { + LayerDescriptor, MapFilters, VectorLayerDescriptor, VectorSourceRequestMeta, @@ -33,10 +34,7 @@ export interface IVectorLayer extends ILayer { export class VectorLayer extends AbstractLayer implements IVectorLayer { readonly _style: IVectorStyle; - static createDescriptor( - options: VectorLayerArguments, - mapColors: string[] - ): VectorLayerDescriptor; + static createDescriptor(options: LayerDescriptor, mapColors: string[]): VectorLayerDescriptor; protected readonly _source: IVectorSource; constructor(options: VectorLayerArguments); From 1129252b2796cb8775288c9fa1bb01c3bc34fbed Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 9 Apr 2020 12:33:46 -0400 Subject: [PATCH 27/50] remove log --- x-pack/legacy/plugins/maps/public/selectors/map_selectors.js | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index c7104586ae4d8..26e5373431bda 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -32,7 +32,6 @@ import { InnerJoin } from '../../../../../plugins/maps/public/layers/joins/inner import { getSourceByType } from '../../../../../plugins/maps/public/layers/sources/source_registry'; function createLayerInstance(layerDescriptor, inspectorAdapters) { - console.log('lauyer inst', layerDescriptor); const source = createSourceInstance(layerDescriptor.sourceDescriptor, inspectorAdapters); switch (layerDescriptor.type) { From 4b5689d95bdd6ffef66be0077603226c977eaeb5 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 9 Apr 2020 13:28:14 -0400 Subject: [PATCH 28/50] edits --- .../sources/mvt_vector_source/mvt_single_layer_vector_source.tsx | 1 - x-pack/plugins/maps/public/layers/vector_layer.js | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index cec6fe8503369..289bba4487828 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -17,7 +17,6 @@ import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters'; import { - LayerDescriptor, MapExtent, TiledSingleLayerVectorSourceDescriptor, VectorLayerDescriptor, diff --git a/x-pack/plugins/maps/public/layers/vector_layer.js b/x-pack/plugins/maps/public/layers/vector_layer.js index 91091f62ae086..2dbf8794dd811 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/plugins/maps/public/layers/vector_layer.js @@ -669,6 +669,7 @@ export class VectorLayer extends AbstractLayer { this._setMbSymbolProperties(mbMap, options); } + console.log('set layer zoom range', this._descriptor.minZoom, this._descriptor.maxZoom); this.syncVisibilityWithMb(mbMap, markerLayerId); mbMap.setLayerZoomRange(markerLayerId, this._descriptor.minZoom, this._descriptor.maxZoom); if (markerLayerId !== textLayerId) { From 58ce7c4a5a70af0805ef9a625ae892232e11de72 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 13 Apr 2020 12:03:20 -0400 Subject: [PATCH 29/50] remove log --- x-pack/plugins/maps/public/layers/vector_layer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/maps/public/layers/vector_layer.js b/x-pack/plugins/maps/public/layers/vector_layer.js index 2dbf8794dd811..91091f62ae086 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/plugins/maps/public/layers/vector_layer.js @@ -669,7 +669,6 @@ export class VectorLayer extends AbstractLayer { this._setMbSymbolProperties(mbMap, options); } - console.log('set layer zoom range', this._descriptor.minZoom, this._descriptor.maxZoom); this.syncVisibilityWithMb(mbMap, markerLayerId); mbMap.setLayerZoomRange(markerLayerId, this._descriptor.minZoom, this._descriptor.maxZoom); if (markerLayerId !== textLayerId) { From f6a6f2f754bee49fef85fdde06975a526d57a55b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 13 Apr 2020 16:14:00 -0400 Subject: [PATCH 30/50] fix zoom level check --- x-pack/plugins/maps/public/layers/layer.js | 2 +- .../sources/mvt_vector_source/mvt_vector_source_editor.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/layer.js b/x-pack/plugins/maps/public/layers/layer.js index 4bb26e8c80e7e..9a63524c8e811 100644 --- a/x-pack/plugins/maps/public/layers/layer.js +++ b/x-pack/plugins/maps/public/layers/layer.js @@ -203,7 +203,7 @@ export class AbstractLayer { } showAtZoomLevel(zoom) { - return zoom >= this._descriptor.minZoom && zoom <= this._descriptor.maxZoom; + return zoom >= this.getMinZoom() && zoom <= this.getMaxZoom(); } getMinZoom() { diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index 1146b16541cc0..bf5c1b15c8a33 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -29,7 +29,7 @@ export class MVTVectorSourceEditor extends React.Component { maxZoom: this.state.maxZoom, }); } - }, 2000); + }, 200); // @ts-ignore _handleUrlTemplateChange = e => { From ff2cfa298098cc77934aa554a46cbbbf1ec5676c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 13 Apr 2020 16:42:22 -0400 Subject: [PATCH 31/50] ts errors --- .../es_geo_grid_source.d.ts | 1 + .../es_search_source/es_search_source.d.ts | 1 + .../mvt_single_layer_vector_source.tsx | 22 +++++++++++-------- .../sources/vector_source/vector_source.d.ts | 1 + .../sources/vector_source/vector_source.js | 4 ++++ .../maps/public/layers/vector_layer.d.ts | 3 ++- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts b/x-pack/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts index 3f596cea1ae39..96347c444dd5b 100644 --- a/x-pack/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/es_geo_grid_source/es_geo_grid_source.d.ts @@ -23,6 +23,7 @@ export class ESGeoGridSource extends AbstractESAggSource { constructor(sourceDescriptor: ESGeoGridSourceDescriptor, inspectorAdapters: unknown); + getFieldNames(): string[]; getGridResolution(): GRID_RESOLUTION; getGeoGridPrecision(zoom: number): number; } diff --git a/x-pack/plugins/maps/public/layers/sources/es_search_source/es_search_source.d.ts b/x-pack/plugins/maps/public/layers/sources/es_search_source/es_search_source.d.ts index 0a4e48a195ec6..c904280a38c85 100644 --- a/x-pack/plugins/maps/public/layers/sources/es_search_source/es_search_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/es_search_source/es_search_source.d.ts @@ -9,4 +9,5 @@ import { ESSearchSourceDescriptor } from '../../../../common/descriptor_types'; export class ESSearchSource extends AbstractESSource { constructor(sourceDescriptor: Partial, inspectorAdapters: unknown); + getFieldNames(): string[]; } diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx index 4df7e662804fd..85844f245d3a1 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx @@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; import React from 'react'; import { MVTVectorSourceEditor } from './mvt_vector_source_editor'; -import { AbstractSource } from '../source'; +import { AbstractSource, ImmutableSourceProperty } from '../source'; import { SingleTiledVectorLayer } from '../../tiled_vector_layer'; import { GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source'; import { MAX_ZOOM, MIN_ZOOM, SOURCE_TYPES } from '../../../../common/constants'; @@ -17,6 +17,7 @@ import { IField } from '../../fields/field'; import { registerSource } from '../source_registry'; import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters'; import { + LayerDescriptor, MapExtent, TiledSingleLayerVectorSourceDescriptor, VectorLayerDescriptor, @@ -71,15 +72,16 @@ export class MVTSingleLayerVectorSource extends AbstractSource return null; } - createDefaultLayer(options: VectorLayerDescriptor): SingleTiledVectorLayer { + getFieldNames(): string[] { + return []; + } + + createDefaultLayer(options: LayerDescriptor): SingleTiledVectorLayer { const layerDescriptor = { sourceDescriptor: this._descriptor, ...options, }; - const normalizedLayerDescriptor: VectorLayerDescriptor = SingleTiledVectorLayer.createDescriptor( - layerDescriptor, - [] - ); + const normalizedLayerDescriptor = SingleTiledVectorLayer.createDescriptor(layerDescriptor, []); const vectorLayerArguments: VectorLayerArguments = { layerDescriptor: normalizedLayerDescriptor, source: this, @@ -99,13 +101,15 @@ export class MVTSingleLayerVectorSource extends AbstractSource return []; } - async getImmutableProperties() { + // getImmutableProperties(): Promise; + + async getImmutableProperties(): Promise { return [ { label: getDataSourceLabel(), value: sourceTitle }, { label: getUrlLabel(), value: this._descriptor.urlTemplate }, { label: 'Layer name', value: this._descriptor.layerName }, - { label: 'Min zoom', value: this._descriptor.minZoom }, - { label: 'Max zoom', value: this._descriptor.maxZoom }, + { label: 'Min zoom', value: this._descriptor.minZoom.toString() }, + { label: 'Max zoom', value: this._descriptor.maxZoom.toString() }, ]; } diff --git a/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.d.ts b/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.d.ts index 8179010a9348b..5a25914e5e443 100644 --- a/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.d.ts @@ -52,6 +52,7 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc getSupportedShapeTypes(): VECTOR_SHAPE_TYPES[]; canFormatFeatureProperties(): boolean; getApplyGlobalQuery(): boolean; + getFieldNames(): string[]; } export interface ITiledSingleLayerVectorSource extends IVectorSource { diff --git a/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.js b/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.js index bb37175b48655..509584cbc415a 100644 --- a/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.js +++ b/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.js @@ -60,6 +60,10 @@ export class AbstractVectorSource extends AbstractSource { throw new Error(`Should implemement ${this.constructor.type} ${this}`); } + getFieldNames() { + return []; + } + /** * Retrieves a field. This may be an existing instance. * @param fieldName diff --git a/x-pack/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/plugins/maps/public/layers/vector_layer.d.ts index 52470128753f1..d77b280424a20 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/layers/vector_layer.d.ts @@ -9,6 +9,7 @@ import { AbstractLayer } from './layer'; import { IVectorSource } from './sources/vector_source'; import { MapFilters, + LayerDescriptor, VectorLayerDescriptor, VectorSourceRequestMeta, } from '../../common/descriptor_types'; @@ -33,7 +34,7 @@ export interface IVectorLayer extends ILayer { export class VectorLayer extends AbstractLayer implements IVectorLayer { static createDescriptor( - options: Partial, + options: Partial, mapColors?: string[] ): VectorLayerDescriptor; From 98bdc4edbcf5c979ab9da79659eedb1fd3826dad Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 13 Apr 2020 17:06:40 -0400 Subject: [PATCH 32/50] split up into modules for consistency --- .../descriptor_types/descriptor_types.d.ts | 6 ++- .../maps/public/layers/load_layer_wizards.ts | 2 +- .../layers/sources/mvt_vector_source/index.ts | 8 ++++ .../mvt_vector_source/layer_wizard.tsx | 47 +++++++++++++++++++ ....tsx => mvt_single_layer_vector_source.ts} | 43 +---------------- .../mvt_vector_source_editor.tsx | 28 +++++++++-- 6 files changed, 84 insertions(+), 50 deletions(-) create mode 100644 x-pack/plugins/maps/public/layers/sources/mvt_vector_source/index.ts create mode 100644 x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx rename x-pack/plugins/maps/public/layers/sources/mvt_vector_source/{mvt_single_layer_vector_source.tsx => mvt_single_layer_vector_source.ts} (79%) diff --git a/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts b/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts index 943b8bf78e6bd..e0c15e6b6d462 100644 --- a/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts +++ b/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts @@ -101,7 +101,7 @@ export type TiledSingleLayerVectorSourceDescriptor = AbstractSourceDescriptor & // These are the min/max zoom levels of the availability of the a particle layerName in the tileset at urlTemplate. // These are _not_ the visible zoom-range of the data on a map. // Tiled data can be displayed at higher levels of zoom than that they are stored in the tileset. - // e.g. EMS basemap data from level 16 can be displayed at higher levels + // e.g. EMS basemap data from level 14 is at most detailed resolution and can be displayed at higher levels minZoom: number; maxZoom: number; }; @@ -119,7 +119,9 @@ export type SourceDescriptor = | ESTermSourceDescriptor | ESSearchSourceDescriptor | ESGeoGridSourceDescriptor - | EMSFileSourceDescriptor; + | EMSFileSourceDescriptor + | ESPewPewSourceDescriptor + | TiledSingleLayerVectorSourceDescriptor; export type LayerDescriptor = { __dataRequests?: DataRequestDescriptor[]; diff --git a/x-pack/plugins/maps/public/layers/load_layer_wizards.ts b/x-pack/plugins/maps/public/layers/load_layer_wizards.ts index 33a405bd88cee..5a966cb45280c 100644 --- a/x-pack/plugins/maps/public/layers/load_layer_wizards.ts +++ b/x-pack/plugins/maps/public/layers/load_layer_wizards.ts @@ -24,7 +24,7 @@ import { kibanaBasemapLayerWizardConfig } from './sources/kibana_tilemap_source' import { tmsLayerWizardConfig } from './sources/xyz_tms_source'; // @ts-ignore import { wmsLayerWizardConfig } from './sources/wms_source'; -import { mvtVectorSourceWizardConfig } from './sources/mvt_vector_source/mvt_single_layer_vector_source'; +import { mvtVectorSourceWizardConfig } from './sources/mvt_vector_source'; // @ts-ignore import { getInjectedVarFunc } from '../kibana_services'; diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/index.ts b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/index.ts new file mode 100644 index 0000000000000..89b7e76a7e359 --- /dev/null +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/index.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export * from './mvt_single_layer_vector_source'; +export * from './layer_wizard'; diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx new file mode 100644 index 0000000000000..caabe1ab8f12d --- /dev/null +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx @@ -0,0 +1,47 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { i18n } from '@kbn/i18n'; +import React from 'react'; +import { + MVTVectorSourceEditor, + MVTSingleLayerVectorSourceConfig, +} from './mvt_vector_source_editor'; +import { MVTSingleLayerVectorSource, sourceTitle } from './mvt_single_layer_vector_source'; +import { LayerWizard } from '../../layer_wizard_registry'; + +export const mvtVectorSourceWizardConfig: LayerWizard = { + description: i18n.translate('xpack.maps.source.mvtVectorSourceWizard', { + defaultMessage: 'Vector source wizard', + }), + icon: 'grid', + renderWizard: ({ + onPreviewSource, + inspectorAdapters, + }: { + onPreviewSource: (source: MVTSingleLayerVectorSource) => void; + inspectorAdapters: object; + }) => { + const onSourceConfigChange = ({ + urlTemplate, + layerName, + minZoom, + maxZoom, + }: MVTSingleLayerVectorSourceConfig) => { + const sourceDescriptor = MVTSingleLayerVectorSource.createDescriptor({ + urlTemplate, + layerName, + minZoom, + maxZoom, + type: MVTSingleLayerVectorSource.type, + }); + const source = new MVTSingleLayerVectorSource(sourceDescriptor, inspectorAdapters); + onPreviewSource(source); + }; + return ; + }, + title: sourceTitle, +}; diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts similarity index 79% rename from x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx rename to x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts index 85844f245d3a1..783cba1834a5f 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts @@ -6,8 +6,6 @@ import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; -import React from 'react'; -import { MVTVectorSourceEditor } from './mvt_vector_source_editor'; import { AbstractSource, ImmutableSourceProperty } from '../source'; import { SingleTiledVectorLayer } from '../../tiled_vector_layer'; import { GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source'; @@ -20,13 +18,12 @@ import { LayerDescriptor, MapExtent, TiledSingleLayerVectorSourceDescriptor, - VectorLayerDescriptor, VectorSourceRequestMeta, VectorSourceSyncMeta, } from '../../../../common/descriptor_types'; import { VectorLayerArguments } from '../../vector_layer'; -const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle', { +export const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle', { defaultMessage: 'Vector Tile Layer', }); @@ -168,41 +165,3 @@ registerSource({ ConstructorFunction: MVTSingleLayerVectorSource, type: SOURCE_TYPES.MVT_SINGLE_LAYER, }); - -export const mvtVectorSourceWizardConfig = { - description: i18n.translate('xpack.maps.source.mvtVectorSourceWizard', { - defaultMessage: 'Vector source wizard', - }), - icon: 'grid', - renderWizard: ({ - onPreviewSource, - inspectorAdapters, - }: { - onPreviewSource: (source: MVTSingleLayerVectorSource) => void; - inspectorAdapters: object; - }) => { - const onSourceConfigChange = ({ - urlTemplate, - layerName, - minZoom, - maxZoom, - }: { - urlTemplate: string; - layerName: string; - minZoom: number; - maxZoom: number; - }) => { - const sourceDescriptor = MVTSingleLayerVectorSource.createDescriptor({ - urlTemplate, - layerName, - minZoom, - maxZoom, - type: MVTSingleLayerVectorSource.type, - }); - const source = new MVTSingleLayerVectorSource(sourceDescriptor, inspectorAdapters); - onPreviewSource(source); - }; - return ; - }, - title: sourceTitle, -}; diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index bf5c1b15c8a33..30cf07d5055fb 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -3,15 +3,34 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +/* eslint-disable @typescript-eslint/consistent-type-definitions */ -import React, { Fragment } from 'react'; +import React, { Fragment, Component, ChangeEvent } from 'react'; import _ from 'lodash'; import { EuiFieldText, EuiFormRow } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { MAX_ZOOM, MIN_ZOOM } from '../../../../common/constants'; import { ValidatedDualRange, Value } from '../../../../../../../src/plugins/kibana_react/public'; -export class MVTVectorSourceEditor extends React.Component { +export type MVTSingleLayerVectorSourceConfig = { + urlTemplate: string; + layerName: string; + minZoom: number; + maxZoom: number; +}; + +export interface Props { + onSourceConfigChange: (sourceConfig: MVTSingleLayerVectorSourceConfig) => void; +} + +interface State { + tmsInput: string; + tmsCanPreview: boolean; + attributionText: string; + attributionUrl: string; +} + +export class MVTVectorSourceEditor extends Component { state = { urlTemplate: '', layerName: '', @@ -32,9 +51,8 @@ export class MVTVectorSourceEditor extends React.Component { }, 200); // @ts-ignore - _handleUrlTemplateChange = e => { + _handleUrlTemplateChange = (e: ChangeEvent) => { const url = e.target.value; - const canPreview = url.indexOf('{x}') >= 0 && url.indexOf('{y}') >= 0 && url.indexOf('{z}') >= 0; this.setState( @@ -47,7 +65,7 @@ export class MVTVectorSourceEditor extends React.Component { }; // @ts-ignore - _handleLayerNameInputChange = e => { + _handleLayerNameInputChange = (e: ChangeEvent) => { const layerName = e.target.value; this.setState( { From 8abbdbdf6956e86a840bd240cf951b2b948f3bd9 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 13 Apr 2020 17:26:53 -0400 Subject: [PATCH 33/50] fix typing issues --- .../sources/mvt_vector_source/layer_wizard.tsx | 10 ++-------- .../mvt_single_layer_vector_source.ts | 14 ++++++++------ .../mvt_vector_source/mvt_vector_source_editor.tsx | 9 +++++---- .../plugins/maps/public/layers/sources/source.d.ts | 2 +- .../sources/vector_source/vector_source.d.ts | 4 ++-- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx index caabe1ab8f12d..9e021c4bfb1d6 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx @@ -11,20 +11,14 @@ import { MVTSingleLayerVectorSourceConfig, } from './mvt_vector_source_editor'; import { MVTSingleLayerVectorSource, sourceTitle } from './mvt_single_layer_vector_source'; -import { LayerWizard } from '../../layer_wizard_registry'; +import { LayerWizard, RenderWizardArguments } from '../../layer_wizard_registry'; export const mvtVectorSourceWizardConfig: LayerWizard = { description: i18n.translate('xpack.maps.source.mvtVectorSourceWizard', { defaultMessage: 'Vector source wizard', }), icon: 'grid', - renderWizard: ({ - onPreviewSource, - inspectorAdapters, - }: { - onPreviewSource: (source: MVTSingleLayerVectorSource) => void; - inspectorAdapters: object; - }) => { + renderWizard: ({ onPreviewSource, inspectorAdapters }: RenderWizardArguments) => { const onSourceConfigChange = ({ urlTemplate, layerName, diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts index 783cba1834a5f..a76e9bdfe228a 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts @@ -6,9 +6,13 @@ import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; -import { AbstractSource, ImmutableSourceProperty } from '../source'; +import { ImmutableSourceProperty } from '../source'; import { SingleTiledVectorLayer } from '../../tiled_vector_layer'; -import { GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source'; +import { + AbstractVectorSource, + GeoJsonWithMeta, + ITiledSingleLayerVectorSource, +} from '../vector_source'; import { MAX_ZOOM, MIN_ZOOM, SOURCE_TYPES } from '../../../../common/constants'; import { VECTOR_SHAPE_TYPES } from '../vector_feature_types'; import { IField } from '../../fields/field'; @@ -27,7 +31,7 @@ export const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle' defaultMessage: 'Vector Tile Layer', }); -export class MVTSingleLayerVectorSource extends AbstractSource +export class MVTSingleLayerVectorSource extends AbstractVectorSource implements ITiledSingleLayerVectorSource { static type = SOURCE_TYPES.MVT_SINGLE_LAYER; static title = i18n.translate('xpack.maps.source.tiledSingleLayerVectorTitle', { @@ -98,8 +102,6 @@ export class MVTSingleLayerVectorSource extends AbstractSource return []; } - // getImmutableProperties(): Promise; - async getImmutableProperties(): Promise { return [ { label: getDataSourceLabel(), value: sourceTitle }, @@ -123,7 +125,7 @@ export class MVTSingleLayerVectorSource extends AbstractSource }; } - async getSupportedShapeTypes() { + async getSupportedShapeTypes(): Promise { return [VECTOR_SHAPE_TYPES.POINT, VECTOR_SHAPE_TYPES.LINE, VECTOR_SHAPE_TYPES.POLYGON]; } diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index 30cf07d5055fb..58eaccc065591 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -24,10 +24,11 @@ export interface Props { } interface State { - tmsInput: string; - tmsCanPreview: boolean; - attributionText: string; - attributionUrl: string; + urlTemplate: string; + layerName: string; + minZoom: number; + maxZoom: number; + mvtCanPreview: boolean; } export class MVTVectorSourceEditor extends Component { diff --git a/x-pack/plugins/maps/public/layers/sources/source.d.ts b/x-pack/plugins/maps/public/layers/sources/source.d.ts index a1581b826d9a6..85b54cbf20216 100644 --- a/x-pack/plugins/maps/public/layers/sources/source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/source.d.ts @@ -19,7 +19,7 @@ export type Attribution = { }; export interface ISource { - createDefaultLayer(): ILayer; + createDefaultLayer(options?: LayerDescriptor): ILayer; destroy(): void; getDisplayName(): Promise; getInspectorAdapters(): object; diff --git a/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.d.ts b/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.d.ts index 5a25914e5e443..df3f71e288c8d 100644 --- a/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/vector_source/vector_source.d.ts @@ -47,9 +47,9 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc ): Promise; getFields(): Promise; - getFieldByName(fieldName: string): IField; + getFieldByName(fieldName: string): IField | null; getSyncMeta(): VectorSourceSyncMeta; - getSupportedShapeTypes(): VECTOR_SHAPE_TYPES[]; + getSupportedShapeTypes(): Promise; canFormatFeatureProperties(): boolean; getApplyGlobalQuery(): boolean; getFieldNames(): string[]; From 99caa2e443f8231bef94c026e388dd4b38355c8a Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Mon, 13 Apr 2020 17:31:20 -0400 Subject: [PATCH 34/50] more fixes --- x-pack/plugins/maps/public/layers/sources/source_registry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/layers/sources/source_registry.ts b/x-pack/plugins/maps/public/layers/sources/source_registry.ts index d16b16af74e9d..3b334d45092ad 100644 --- a/x-pack/plugins/maps/public/layers/sources/source_registry.ts +++ b/x-pack/plugins/maps/public/layers/sources/source_registry.ts @@ -10,7 +10,7 @@ import { ISource } from './source'; type SourceRegistryEntry = { ConstructorFunction: new ( sourceDescriptor: any, // this is the source-descriptor that corresponds specifically to the particular ISource instance - inspectorAdapters: unknown + inspectorAdapters?: object ) => ISource; type: string; }; From d26486fef2fc3513cf08a5e31500351199200d56 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 14 Apr 2020 09:54:11 -0400 Subject: [PATCH 35/50] fix typing: --- x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index 3e441f58e64ad..4623b5a850503 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -61,6 +61,7 @@ export class SingleTiledVectorLayer extends VectorLayer { const requestMeta: VectorSourceRequestMeta = { ...mapFilters, applyGlobalQuery: this._source.getApplyGlobalQuery(), + sourceMeta: this._source.getSyncMeta(), fieldNames, sourceQuery: this.getQuery(), }; From d61dba323336a154c481fcf7357dff6ff2d21d01 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 14 Apr 2020 10:00:15 -0400 Subject: [PATCH 36/50] fix mock --- .../legacy/plugins/maps/public/selectors/map_selectors.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js index 77bd29259647c..400d4b9c0fc04 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.test.js @@ -5,6 +5,7 @@ */ jest.mock('../../../../../plugins/maps/public/layers/vector_layer', () => {}); +jest.mock('../../../../../plugins/maps/public/layers/tiled_vector_layer', () => {}); jest.mock('../../../../../plugins/maps/public/layers/blended_vector_layer', () => {}); jest.mock('../../../../../plugins/maps/public/layers/heatmap_layer', () => {}); jest.mock('../../../../../plugins/maps/public/layers/vector_tile_layer', () => {}); From ed273670f860c6bad4a5609b6d6815a892c1932f Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 14 Apr 2020 11:52:22 -0400 Subject: [PATCH 37/50] feedback (1) --- .../layer_addpanel/view.js | 11 +++---- .../layer_panel/layer_settings/index.js | 4 +-- .../layer_settings/layer_settings.js | 8 ++--- x-pack/plugins/maps/common/constants.ts | 4 +-- .../descriptor_types/descriptor_types.d.ts | 6 ++-- .../mvt_vector_source/layer_wizard.tsx | 8 ++--- .../mvt_single_layer_vector_source.ts | 20 ++++++------- .../mvt_vector_source_editor.tsx | 30 +++++++++---------- .../sources/vector_source/vector_source.d.ts | 4 +-- .../maps/public/layers/tiled_vector_layer.tsx | 25 ++++++++-------- 10 files changed, 58 insertions(+), 62 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/view.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/view.js index 864dc5b0b5cc6..92fcf01f3901f 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/view.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/view.js @@ -63,13 +63,10 @@ export class AddLayerPanel extends Component { return; } - let styleDescriptor; - if (this.state.layer && this.state.layer.getCurrentStyle()) { - const currentStyle = this.state.layer.getCurrentStyle(); - styleDescriptor = currentStyle.getDescriptor(); - } else { - styleDescriptor = null; - } + const styleDescriptor = + this.state.layer && this.state.layer.getCurrentStyle() + ? this.state.layer.getCurrentStyle().getDescriptor() + : null; const layerInitProps = { ...options, style: styleDescriptor, diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js index 6e8354aa422d5..935cc041f535d 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js @@ -17,8 +17,8 @@ import { function mapStateToProps(state = {}) { const selectedLayer = getSelectedLayer(state); return { - minZoomForData: selectedLayer.getMinZoomForData(), - maxZoomForData: selectedLayer.getMaxZoomForData(), + minDataZoom: selectedLayer.getMinZoomForData(), + maxDataZoom: selectedLayer.getMaxZoomForData(), alpha: selectedLayer.getAlpha(), label: selectedLayer.getLabel(), layerId: selectedLayer.getId(), diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js index b7c7314519492..8aebf85055097 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js @@ -20,8 +20,8 @@ export function LayerSettings(props) { }; const onZoomChange = ([min, max]) => { - props.updateMinZoom(props.layerId, Math.max(props.minZoomForData, parseInt(min, 10))); - props.updateMaxZoom(props.layerId, Math.min(props.maxZoomForData, parseInt(max, 10))); + props.updateMinZoom(props.layerId, Math.max(props.minDataZoom, parseInt(min, 10))); + props.updateMaxZoom(props.layerId, Math.min(props.maxDataZoom, parseInt(max, 10))); }; const onAlphaChange = alpha => { @@ -36,8 +36,8 @@ export function LayerSettings(props) { defaultMessage: 'Visibility', })} formRowDisplay="columnCompressed" - min={props.minZoomForData} - max={props.maxZoomForData} + min={props.minDataZoom} + max={props.maxDataZoom} value={[props.minZoom, props.maxZoom]} showInput="inputWithPopover" showRange diff --git a/x-pack/plugins/maps/common/constants.ts b/x-pack/plugins/maps/common/constants.ts index dda29121b0909..9808a62852a94 100644 --- a/x-pack/plugins/maps/common/constants.ts +++ b/x-pack/plugins/maps/common/constants.ts @@ -46,10 +46,10 @@ export function createMapPath(id: string) { export enum LAYER_TYPE { TILE = 'TILE', VECTOR = 'VECTOR', - VECTOR_TILE = 'VECTOR_TILE', + VECTOR_TILE = 'VECTOR_TILE', // for static display of mvt vector tiles with a mapbox stylesheet. Does not support any ad-hoc configurations. Used for consuming EMS vector tiles. HEATMAP = 'HEATMAP', BLENDED_VECTOR = 'BLENDED_VECTOR', - TILED_VECTOR = 'TILED_VECTOR', + TILED_VECTOR = 'TILED_VECTOR', // similar to a regular vector-layer, but it consumes the data as .mvt tilea iso GeoJson. It supports similar ad-hoc configurations like a regular vector layer (E.g. using IVectorStyle), although there is some loss of functionality e.g. does not support term joining } export enum SORT_ORDER { diff --git a/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts b/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts index e0c15e6b6d462..f8175b0ed3f10 100644 --- a/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts +++ b/x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts @@ -98,12 +98,12 @@ export type TiledSingleLayerVectorSourceDescriptor = AbstractSourceDescriptor & urlTemplate: string; layerName: string; - // These are the min/max zoom levels of the availability of the a particle layerName in the tileset at urlTemplate. + // These are the min/max zoom levels of the availability of the a particular layerName in the tileset at urlTemplate. // These are _not_ the visible zoom-range of the data on a map. // Tiled data can be displayed at higher levels of zoom than that they are stored in the tileset. // e.g. EMS basemap data from level 14 is at most detailed resolution and can be displayed at higher levels - minZoom: number; - maxZoom: number; + minSourceZoom: number; + maxSourceZoom: number; }; export type JoinDescriptor = { diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx index 9e021c4bfb1d6..57e5bc7762a1d 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx @@ -22,14 +22,14 @@ export const mvtVectorSourceWizardConfig: LayerWizard = { const onSourceConfigChange = ({ urlTemplate, layerName, - minZoom, - maxZoom, + minSourceZoom, + maxSourceZoom, }: MVTSingleLayerVectorSourceConfig) => { const sourceDescriptor = MVTSingleLayerVectorSource.createDescriptor({ urlTemplate, layerName, - minZoom, - maxZoom, + minSourceZoom, + maxSourceZoom, type: MVTSingleLayerVectorSource.type, }); const source = new MVTSingleLayerVectorSource(sourceDescriptor, inspectorAdapters); diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts index a76e9bdfe228a..ac37eb0a92eff 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts @@ -46,16 +46,16 @@ export class MVTSingleLayerVectorSource extends AbstractVectorSource static createDescriptor({ urlTemplate, layerName, - minZoom, - maxZoom, + minSourceZoom, + maxSourceZoom, }: TiledSingleLayerVectorSourceDescriptor) { return { type: MVTSingleLayerVectorSource.type, id: uuid(), urlTemplate, layerName, - minZoom: Math.max(MIN_ZOOM, minZoom), - maxZoom: Math.min(MAX_ZOOM, maxZoom), + minSourceZoom: Math.max(MIN_ZOOM, minSourceZoom), + maxSourceZoom: Math.min(MAX_ZOOM, maxSourceZoom), }; } @@ -107,8 +107,8 @@ export class MVTSingleLayerVectorSource extends AbstractVectorSource { label: getDataSourceLabel(), value: sourceTitle }, { label: getUrlLabel(), value: this._descriptor.urlTemplate }, { label: 'Layer name', value: this._descriptor.layerName }, - { label: 'Min zoom', value: this._descriptor.minZoom.toString() }, - { label: 'Max zoom', value: this._descriptor.maxZoom.toString() }, + { label: 'Min zoom', value: this._descriptor.minSourceZoom.toString() }, + { label: 'Max zoom', value: this._descriptor.maxSourceZoom.toString() }, ]; } @@ -120,8 +120,8 @@ export class MVTSingleLayerVectorSource extends AbstractVectorSource return { urlTemplate: this._descriptor.urlTemplate, layerName: this._descriptor.layerName, - minZoom: this._descriptor.minZoom, - maxZoom: this._descriptor.maxZoom, + minSourceZoom: this._descriptor.minSourceZoom, + maxSourceZoom: this._descriptor.maxSourceZoom, }; } @@ -134,11 +134,11 @@ export class MVTSingleLayerVectorSource extends AbstractVectorSource } getMinZoom() { - return this._descriptor.minZoom; + return this._descriptor.minSourceZoom; } getMaxZoom() { - return this._descriptor.maxZoom; + return this._descriptor.maxSourceZoom; } getBoundsForFilters(searchFilters: VectorSourceRequestMeta): MapExtent { diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index 58eaccc065591..dc07b888ec896 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -15,8 +15,8 @@ import { ValidatedDualRange, Value } from '../../../../../../../src/plugins/kiba export type MVTSingleLayerVectorSourceConfig = { urlTemplate: string; layerName: string; - minZoom: number; - maxZoom: number; + minSourceZoom: number; + maxSourceZoom: number; }; export interface Props { @@ -26,8 +26,8 @@ export interface Props { interface State { urlTemplate: string; layerName: string; - minZoom: number; - maxZoom: number; + minSourceZoom: number; + maxSourceZoom: number; mvtCanPreview: boolean; } @@ -35,8 +35,8 @@ export class MVTVectorSourceEditor extends Component { state = { urlTemplate: '', layerName: '', - minZoom: MIN_ZOOM, - maxZoom: MAX_ZOOM, + minSourceZoom: MIN_ZOOM, + maxSourceZoom: MAX_ZOOM, mvtCanPreview: false, }; @@ -45,8 +45,8 @@ export class MVTVectorSourceEditor extends Component { this.props.onSourceConfigChange({ urlTemplate: this.state.urlTemplate, layerName: this.state.layerName, - minZoom: this.state.minZoom, - maxZoom: this.state.maxZoom, + minSourceZoom: this.state.minSourceZoom, + maxSourceZoom: this.state.maxSourceZoom, }); } }, 200); @@ -77,11 +77,11 @@ export class MVTVectorSourceEditor extends Component { }; _handleZoomRangeChange = (e: Value) => { - const minZoom = parseInt(e[0] as string, 10); - const maxZoom = parseInt(e[1] as string, 10); + const minSourceZoom = parseInt(e[0] as string, 10); + const maxSourceZoom = parseInt(e[1] as string, 10); - if (this.state.minZoom !== minZoom || this.state.maxZoom !== maxZoom) { - this.setState({ minZoom, maxZoom }, () => this._sourceConfigChange()); + if (this.state.minSourceZoom !== minSourceZoom || this.state.maxSourceZoom !== maxSourceZoom) { + this.setState({ minSourceZoom, maxSourceZoom }, () => this._sourceConfigChange()); } }; @@ -95,13 +95,13 @@ export class MVTVectorSourceEditor extends Component { ; getMinZoom(): number; getMaxZoom(): number; diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index 4623b5a850503..61bb9f2bab526 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -6,7 +6,6 @@ import React from 'react'; import { EuiIcon } from '@elastic/eui'; -import _ from 'lodash'; import { IVectorStyle, VectorStyle } from './styles/vector/vector_style'; import { SOURCE_DATA_ID_ORIGIN, LAYER_TYPE } from '../../common/constants'; import { VectorLayer, VectorLayerArguments } from './vector_layer'; @@ -121,13 +120,13 @@ export class SingleTiledVectorLayer extends VectorLayer { const sourceMeta: { layerName: string; urlTemplate: string; - minZoom: number; - maxZoom: number; + minSourceZoom: number; + maxSourceZoom: number; } | null = sourceDataRequest.getData() as { layerName: string; urlTemplate: string; - minZoom: number; - maxZoom: number; + minSourceZoom: number; + maxSourceZoom: number; }; if (!sourceMeta) { return; @@ -139,8 +138,8 @@ export class SingleTiledVectorLayer extends VectorLayer { mbMap.addSource(sourceId, { type: 'vector', tiles: [sourceMeta.urlTemplate], - minzoom: sourceMeta.minZoom, - maxzoom: sourceMeta.maxZoom, + minzoom: sourceMeta.minSourceZoom, + maxzoom: sourceMeta.maxSourceZoom, }); } } @@ -179,17 +178,17 @@ export class SingleTiledVectorLayer extends VectorLayer { } const tiledSourceMeta: { urlTemplate: string; - minZoom: number; - maxZoom: number; + minSourceZoom: number; + maxSourceZoom: number; } | null = dataRequest.getData() as { urlTemplate: string; - minZoom: number; - maxZoom: number; + minSourceZoom: number; + maxSourceZoom: number; }; if ( mbTileSource.tiles[0] === tiledSourceMeta.urlTemplate && - mbTileSource.minzoom === tiledSourceMeta.minZoom && - mbTileSource.maxzoom === tiledSourceMeta.maxZoom + mbTileSource.minzoom === tiledSourceMeta.minSourceZoom && + mbTileSource.maxzoom === tiledSourceMeta.maxSourceZoom ) { // TileURL and zoom-range captures all the state. If this does not change, no updates are required. return false; From 5168129dc58119288918dbf2febe4fa8e33ec30a Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 14 Apr 2020 11:57:28 -0400 Subject: [PATCH 38/50] remove --- x-pack/plugins/maps/public/layers/layer.d.ts | 4 ---- x-pack/plugins/maps/public/layers/layer.js | 8 -------- x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx | 6 +----- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/layer.d.ts b/x-pack/plugins/maps/public/layers/layer.d.ts index 761be5dea63b3..301f54a72137c 100644 --- a/x-pack/plugins/maps/public/layers/layer.d.ts +++ b/x-pack/plugins/maps/public/layers/layer.d.ts @@ -19,8 +19,6 @@ export interface ILayer { syncData(syncContext: SyncContext): Promise; isVisible(): boolean; showAtZoomLevel(zoomLevel: number): boolean; - getMinZoomForData(): number; - getMaxZoomForData(): number; getMinZoom(): number; getMaxZoom(): number; } @@ -43,8 +41,6 @@ export class AbstractLayer implements ILayer { syncData(syncContext: SyncContext): Promise; isVisible(): boolean; showAtZoomLevel(zoomLevel: number): boolean; - getMinZoomForData(): number; - getMaxZoomForData(): number; getMinZoom(): number; getMaxZoom(): number; getQuery(): MapQuery; diff --git a/x-pack/plugins/maps/public/layers/layer.js b/x-pack/plugins/maps/public/layers/layer.js index 9a63524c8e811..e55ee84e61be1 100644 --- a/x-pack/plugins/maps/public/layers/layer.js +++ b/x-pack/plugins/maps/public/layers/layer.js @@ -352,12 +352,4 @@ export class AbstractLayer { getType() { return this._descriptor.type; } - - getMinZoomForData() { - return MIN_ZOOM; - } - - getMaxZoomForData() { - return MAX_ZOOM; - } } diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index 61bb9f2bab526..bd7578216e84f 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -226,12 +226,8 @@ export class SingleTiledVectorLayer extends VectorLayer { return []; } - getMinZoomForData(): number { - return this._source.getMinZoom(); - } - getMinZoom() { // higher resolution vector tiles cannot be displayed at lower-res - return Math.max(this.getMinZoomForData(), super.getMinZoom()); + return Math.max(this._source.getMinZoom(), super.getMinZoom()); } } From b0b7bfc973e3aa34ee98e0468beda17006950aa0 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 14 Apr 2020 11:59:48 -0400 Subject: [PATCH 39/50] remove bloat --- x-pack/plugins/maps/public/layers/layer.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/layer.js b/x-pack/plugins/maps/public/layers/layer.js index e55ee84e61be1..150d62eed7141 100644 --- a/x-pack/plugins/maps/public/layers/layer.js +++ b/x-pack/plugins/maps/public/layers/layer.js @@ -141,7 +141,8 @@ export class AbstractLayer { defaultMessage: `Layer is hidden.`, }); } else if (!this.showAtZoomLevel(zoomLevel)) { - const { minZoom, maxZoom } = this.getZoomConfig(); + const minZoom = this.getMinZoom(); + const maxZoom = this.getMaxZoom(); icon = ; tooltipContent = i18n.translate('xpack.maps.layer.zoomFeedbackTooltip', { defaultMessage: `Layer is visible between zoom levels {minZoom} and {maxZoom}.`, @@ -222,13 +223,6 @@ export class AbstractLayer { return this._descriptor.query; } - getZoomConfig() { - return { - minZoom: this._descriptor.minZoom, - maxZoom: this._descriptor.maxZoom, - }; - } - getCurrentStyle() { return this._style; } From 058da42c1800d426e8236d2841a0f036d1801cc6 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 14 Apr 2020 14:17:58 -0400 Subject: [PATCH 40/50] undo blanket removal --- .../layer_panel/layer_settings/index.js | 4 ++-- .../layer_panel/layer_settings/layer_settings.js | 8 ++++---- x-pack/plugins/maps/public/layers/layer.d.ts | 2 ++ x-pack/plugins/maps/public/layers/layer.js | 4 ++++ .../mvt_vector_source/mvt_vector_source_editor.tsx | 4 +--- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js index 935cc041f535d..9f171325f314b 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js @@ -17,8 +17,8 @@ import { function mapStateToProps(state = {}) { const selectedLayer = getSelectedLayer(state); return { - minDataZoom: selectedLayer.getMinZoomForData(), - maxDataZoom: selectedLayer.getMaxZoomForData(), + minSourceZoom: selectedLayer.getMinSourceZoom(), + maxSourceZoom: selectedLayer.getMaxZoom(), alpha: selectedLayer.getAlpha(), label: selectedLayer.getLabel(), layerId: selectedLayer.getId(), diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js index 8aebf85055097..e1d2c3dcc8a5d 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js @@ -20,8 +20,8 @@ export function LayerSettings(props) { }; const onZoomChange = ([min, max]) => { - props.updateMinZoom(props.layerId, Math.max(props.minDataZoom, parseInt(min, 10))); - props.updateMaxZoom(props.layerId, Math.min(props.maxDataZoom, parseInt(max, 10))); + props.updateMinZoom(props.layerId, Math.max(props.minSourceZoom, parseInt(min, 10))); + props.updateMaxZoom(props.layerId, Math.min(props.maxSourceZoom, parseInt(max, 10))); }; const onAlphaChange = alpha => { @@ -36,8 +36,8 @@ export function LayerSettings(props) { defaultMessage: 'Visibility', })} formRowDisplay="columnCompressed" - min={props.minDataZoom} - max={props.maxDataZoom} + min={props.minSourceZoom} + max={props.maxSourceZoom} value={[props.minZoom, props.maxZoom]} showInput="inputWithPopover" showRange diff --git a/x-pack/plugins/maps/public/layers/layer.d.ts b/x-pack/plugins/maps/public/layers/layer.d.ts index 301f54a72137c..f8794e7d65390 100644 --- a/x-pack/plugins/maps/public/layers/layer.d.ts +++ b/x-pack/plugins/maps/public/layers/layer.d.ts @@ -21,6 +21,7 @@ export interface ILayer { showAtZoomLevel(zoomLevel: number): boolean; getMinZoom(): number; getMaxZoom(): number; + getMinSourceZoom(): number; } export interface ILayerArguments { @@ -43,5 +44,6 @@ export class AbstractLayer implements ILayer { showAtZoomLevel(zoomLevel: number): boolean; getMinZoom(): number; getMaxZoom(): number; + getMinSourceZoom(): number; getQuery(): MapQuery; } diff --git a/x-pack/plugins/maps/public/layers/layer.js b/x-pack/plugins/maps/public/layers/layer.js index 150d62eed7141..cece8fc3976f3 100644 --- a/x-pack/plugins/maps/public/layers/layer.js +++ b/x-pack/plugins/maps/public/layers/layer.js @@ -215,6 +215,10 @@ export class AbstractLayer { return this._descriptor.maxZoom; } + getMinSourceZoom() { + return this._source.getMinZoom(); + } + getAlpha() { return this._descriptor.alpha; } diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx index dc07b888ec896..b06005d46df6f 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx @@ -95,9 +95,7 @@ export class MVTVectorSourceEditor extends Component { Date: Tue, 14 Apr 2020 14:23:55 -0400 Subject: [PATCH 41/50] remove unused --- .../mvt_single_layer_vector_source.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts index ac37eb0a92eff..eb5d2bab8dcc7 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts +++ b/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts @@ -27,22 +27,12 @@ import { } from '../../../../common/descriptor_types'; import { VectorLayerArguments } from '../../vector_layer'; -export const sourceTitle = i18n.translate('xpack.maps.source.ems_xyzVectorTitle', { +export const sourceTitle = i18n.translate('xpack.maps.source.tiledVectorTitle', { defaultMessage: 'Vector Tile Layer', }); export class MVTSingleLayerVectorSource extends AbstractVectorSource implements ITiledSingleLayerVectorSource { - static type = SOURCE_TYPES.MVT_SINGLE_LAYER; - static title = i18n.translate('xpack.maps.source.tiledSingleLayerVectorTitle', { - defaultMessage: 'Tiled vector', - }); - static description = i18n.translate('xpack.maps.source.tiledSingleLayerVectorDescription', { - defaultMessage: 'Tiled vector with url template', - }); - - static icon = 'logoElasticsearch'; - static createDescriptor({ urlTemplate, layerName, From 769950b1320c55d321e51cc17a5492d549f42010 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 14 Apr 2020 14:40:23 -0400 Subject: [PATCH 42/50] rename for clarity --- .../plugins/maps/public/selectors/map_selectors.js | 6 +++--- .../plugins/maps/public/layers/load_layer_wizards.ts | 2 +- .../index.ts | 0 .../layer_wizard.tsx | 9 +++++---- .../mvt_single_layer_vector_source.ts | 10 +++++----- .../mvt_single_layer_vector_source_editor.tsx} | 2 +- .../plugins/maps/public/layers/tiled_vector_layer.tsx | 4 ++-- 7 files changed, 17 insertions(+), 16 deletions(-) rename x-pack/plugins/maps/public/layers/sources/{mvt_vector_source => mvt_single_layer_vector_source}/index.ts (100%) rename x-pack/plugins/maps/public/layers/sources/{mvt_vector_source => mvt_single_layer_vector_source}/layer_wizard.tsx (82%) rename x-pack/plugins/maps/public/layers/sources/{mvt_vector_source => mvt_single_layer_vector_source}/mvt_single_layer_vector_source.ts (92%) rename x-pack/plugins/maps/public/layers/sources/{mvt_vector_source/mvt_vector_source_editor.tsx => mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx} (97%) diff --git a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js index 26e5373431bda..b07798edddde9 100644 --- a/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js +++ b/x-pack/legacy/plugins/maps/public/selectors/map_selectors.js @@ -17,7 +17,7 @@ import { HeatmapLayer } from '../../../../../plugins/maps/public/layers/heatmap_ // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { BlendedVectorLayer } from '../../../../../plugins/maps/public/layers/blended_vector_layer'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { SingleTiledVectorLayer } from '../../../../../plugins/maps/public/layers/tiled_vector_layer'; +import { TiledVectorLayer } from '../../../../../plugins/maps/public/layers/tiled_vector_layer'; import { getTimeFilter } from '../kibana_services'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { getInspectorAdapters } from '../../../../../plugins/maps/public/reducers/non_serializable_instances'; @@ -52,8 +52,8 @@ function createLayerInstance(layerDescriptor, inspectorAdapters) { return new HeatmapLayer({ layerDescriptor, source }); case BlendedVectorLayer.type: return new BlendedVectorLayer({ layerDescriptor, source }); - case SingleTiledVectorLayer.type: - return new SingleTiledVectorLayer({ layerDescriptor, source }); + case TiledVectorLayer.type: + return new TiledVectorLayer({ layerDescriptor, source }); default: throw new Error(`Unrecognized layerType ${layerDescriptor.type}`); } diff --git a/x-pack/plugins/maps/public/layers/load_layer_wizards.ts b/x-pack/plugins/maps/public/layers/load_layer_wizards.ts index 5a966cb45280c..49d128257fe20 100644 --- a/x-pack/plugins/maps/public/layers/load_layer_wizards.ts +++ b/x-pack/plugins/maps/public/layers/load_layer_wizards.ts @@ -24,7 +24,7 @@ import { kibanaBasemapLayerWizardConfig } from './sources/kibana_tilemap_source' import { tmsLayerWizardConfig } from './sources/xyz_tms_source'; // @ts-ignore import { wmsLayerWizardConfig } from './sources/wms_source'; -import { mvtVectorSourceWizardConfig } from './sources/mvt_vector_source'; +import { mvtVectorSourceWizardConfig } from './sources/mvt_single_layer_vector_source'; // @ts-ignore import { getInjectedVarFunc } from '../kibana_services'; diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/index.ts b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/index.ts similarity index 100% rename from x-pack/plugins/maps/public/layers/sources/mvt_vector_source/index.ts rename to x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/index.ts diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/layer_wizard.tsx similarity index 82% rename from x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx rename to x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/layer_wizard.tsx index 57e5bc7762a1d..9987c4e867b20 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/layer_wizard.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/layer_wizard.tsx @@ -7,11 +7,12 @@ import { i18n } from '@kbn/i18n'; import React from 'react'; import { - MVTVectorSourceEditor, + MVTSingleLayerVectorSourceEditor, MVTSingleLayerVectorSourceConfig, -} from './mvt_vector_source_editor'; +} from './mvt_single_layer_vector_source'; import { MVTSingleLayerVectorSource, sourceTitle } from './mvt_single_layer_vector_source'; import { LayerWizard, RenderWizardArguments } from '../../layer_wizard_registry'; +import { SOURCE_TYPES } from '../../../../common/constants'; export const mvtVectorSourceWizardConfig: LayerWizard = { description: i18n.translate('xpack.maps.source.mvtVectorSourceWizard', { @@ -30,12 +31,12 @@ export const mvtVectorSourceWizardConfig: LayerWizard = { layerName, minSourceZoom, maxSourceZoom, - type: MVTSingleLayerVectorSource.type, + type: SOURCE_TYPES.MVT_SINGLE_LAYER, }); const source = new MVTSingleLayerVectorSource(sourceDescriptor, inspectorAdapters); onPreviewSource(source); }; - return ; + return ; }, title: sourceTitle, }; diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.ts similarity index 92% rename from x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts rename to x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.ts index eb5d2bab8dcc7..da3470948b3ce 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_single_layer_vector_source.ts +++ b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.ts @@ -7,7 +7,7 @@ import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; import { ImmutableSourceProperty } from '../source'; -import { SingleTiledVectorLayer } from '../../tiled_vector_layer'; +import { TiledVectorLayer } from '../../tiled_vector_layer'; import { AbstractVectorSource, GeoJsonWithMeta, @@ -40,7 +40,7 @@ export class MVTSingleLayerVectorSource extends AbstractVectorSource maxSourceZoom, }: TiledSingleLayerVectorSourceDescriptor) { return { - type: MVTSingleLayerVectorSource.type, + type: SOURCE_TYPES.MVT_SINGLE_LAYER, id: uuid(), urlTemplate, layerName, @@ -67,17 +67,17 @@ export class MVTSingleLayerVectorSource extends AbstractVectorSource return []; } - createDefaultLayer(options: LayerDescriptor): SingleTiledVectorLayer { + createDefaultLayer(options: LayerDescriptor): TiledVectorLayer { const layerDescriptor = { sourceDescriptor: this._descriptor, ...options, }; - const normalizedLayerDescriptor = SingleTiledVectorLayer.createDescriptor(layerDescriptor, []); + const normalizedLayerDescriptor = TiledVectorLayer.createDescriptor(layerDescriptor, []); const vectorLayerArguments: VectorLayerArguments = { layerDescriptor: normalizedLayerDescriptor, source: this, }; - return new SingleTiledVectorLayer(vectorLayerArguments); + return new TiledVectorLayer(vectorLayerArguments); } getGeoJsonWithMeta( diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx similarity index 97% rename from x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx rename to x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx index b06005d46df6f..a10485b0f24f0 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_vector_source/mvt_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx @@ -31,7 +31,7 @@ interface State { mvtCanPreview: boolean; } -export class MVTVectorSourceEditor extends Component { +export class MVTSingleLayerVectorSourceEditor extends Component { state = { urlTemplate: '', layerName: '', diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index bd7578216e84f..8169f1a7065d4 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -19,7 +19,7 @@ import { VectorSourceRequestMeta, } from '../../common/descriptor_types'; -export class SingleTiledVectorLayer extends VectorLayer { +export class TiledVectorLayer extends VectorLayer { static type = LAYER_TYPE.TILED_VECTOR; static createDescriptor( @@ -27,7 +27,7 @@ export class SingleTiledVectorLayer extends VectorLayer { mapColors: string[] ): VectorLayerDescriptor { const layerDescriptor = super.createDescriptor(descriptor, mapColors); - layerDescriptor.type = SingleTiledVectorLayer.type; + layerDescriptor.type = TiledVectorLayer.type; if (!layerDescriptor.style) { const styleProperties = VectorStyle.createDefaultStyleProperties(mapColors); From fa3343dde0dcc1040d784121b6f700817efcf76c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Tue, 14 Apr 2020 14:48:18 -0400 Subject: [PATCH 43/50] fix import --- .../sources/mvt_single_layer_vector_source/layer_wizard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/layer_wizard.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/layer_wizard.tsx index 9987c4e867b20..dfdea1489d50c 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/layer_wizard.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/layer_wizard.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { MVTSingleLayerVectorSourceEditor, MVTSingleLayerVectorSourceConfig, -} from './mvt_single_layer_vector_source'; +} from './mvt_single_layer_vector_source_editor'; import { MVTSingleLayerVectorSource, sourceTitle } from './mvt_single_layer_vector_source'; import { LayerWizard, RenderWizardArguments } from '../../layer_wizard_registry'; import { SOURCE_TYPES } from '../../../../common/constants'; From 6b881cefa3ac1cedb838f73f46f3d33a91cd5bfa Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 15 Apr 2020 16:08:40 -0400 Subject: [PATCH 44/50] feedback (1) --- .../layer_panel/layer_settings/index.js | 5 ++- .../layer_settings/layer_settings.js | 8 ++-- .../mvt_single_layer_vector_source.ts | 40 +++++++++++++------ .../mvt_single_layer_vector_source_editor.tsx | 12 +++--- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js index 9f171325f314b..e8f980bbbf2b4 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/index.js @@ -13,12 +13,13 @@ import { updateLayerMinZoom, updateLayerAlpha, } from '../../../actions/map_actions'; +import { MAX_ZOOM } from '../../../../../../../plugins/maps/common/constants'; function mapStateToProps(state = {}) { const selectedLayer = getSelectedLayer(state); return { - minSourceZoom: selectedLayer.getMinSourceZoom(), - maxSourceZoom: selectedLayer.getMaxZoom(), + minVisibilityZoom: selectedLayer.getMinSourceZoom(), + maxVisibilityZoom: MAX_ZOOM, alpha: selectedLayer.getAlpha(), label: selectedLayer.getLabel(), layerId: selectedLayer.getId(), diff --git a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js index e1d2c3dcc8a5d..1d352913e54a3 100644 --- a/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js +++ b/x-pack/legacy/plugins/maps/public/connected_components/layer_panel/layer_settings/layer_settings.js @@ -20,8 +20,8 @@ export function LayerSettings(props) { }; const onZoomChange = ([min, max]) => { - props.updateMinZoom(props.layerId, Math.max(props.minSourceZoom, parseInt(min, 10))); - props.updateMaxZoom(props.layerId, Math.min(props.maxSourceZoom, parseInt(max, 10))); + props.updateMinZoom(props.layerId, Math.max(props.minVisibilityZoom, parseInt(min, 10))); + props.updateMaxZoom(props.layerId, Math.min(props.maxVisibilityZoom, parseInt(max, 10))); }; const onAlphaChange = alpha => { @@ -36,8 +36,8 @@ export function LayerSettings(props) { defaultMessage: 'Visibility', })} formRowDisplay="columnCompressed" - min={props.minSourceZoom} - max={props.maxSourceZoom} + min={props.minVisibilityZoom} + max={props.maxVisibilityZoom} value={[props.minZoom, props.maxZoom]} showInput="inputWithPopover" showRange diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.ts b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.ts index da3470948b3ce..5479e56b800c2 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.ts +++ b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.ts @@ -6,13 +6,9 @@ import { i18n } from '@kbn/i18n'; import uuid from 'uuid/v4'; -import { ImmutableSourceProperty } from '../source'; +import { AbstractSource, ImmutableSourceProperty } from '../source'; import { TiledVectorLayer } from '../../tiled_vector_layer'; -import { - AbstractVectorSource, - GeoJsonWithMeta, - ITiledSingleLayerVectorSource, -} from '../vector_source'; +import { GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source'; import { MAX_ZOOM, MIN_ZOOM, SOURCE_TYPES } from '../../../../common/constants'; import { VECTOR_SHAPE_TYPES } from '../vector_feature_types'; import { IField } from '../../fields/field'; @@ -27,11 +23,14 @@ import { } from '../../../../common/descriptor_types'; import { VectorLayerArguments } from '../../vector_layer'; -export const sourceTitle = i18n.translate('xpack.maps.source.tiledVectorTitle', { - defaultMessage: 'Vector Tile Layer', -}); +export const sourceTitle = i18n.translate( + 'xpack.maps.source.MVTSingleLayerVectorSource.sourceTitle', + { + defaultMessage: 'Vector Tile Layer', + } +); -export class MVTSingleLayerVectorSource extends AbstractVectorSource +export class MVTSingleLayerVectorSource extends AbstractSource implements ITiledSingleLayerVectorSource { static createDescriptor({ urlTemplate, @@ -96,9 +95,24 @@ export class MVTSingleLayerVectorSource extends AbstractVectorSource return [ { label: getDataSourceLabel(), value: sourceTitle }, { label: getUrlLabel(), value: this._descriptor.urlTemplate }, - { label: 'Layer name', value: this._descriptor.layerName }, - { label: 'Min zoom', value: this._descriptor.minSourceZoom.toString() }, - { label: 'Max zoom', value: this._descriptor.maxSourceZoom.toString() }, + { + label: i18n.translate('xpack.maps.source.MVTSingleLayerVectorSource.layerNameMessage', { + defaultMessage: 'Layer name', + }), + value: this._descriptor.layerName, + }, + { + label: i18n.translate('xpack.maps.source.MVTSingleLayerVectorSource.minZoomMessage', { + defaultMessage: 'Min zoom', + }), + value: this._descriptor.minSourceZoom.toString(), + }, + { + label: i18n.translate('xpack.maps.source.MVTSingleLayerVectorSource.maxZoomMessage', { + defaultMessage: 'Max zoom', + }), + value: this._descriptor.maxSourceZoom.toString(), + }, ]; } diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx index a10485b0f24f0..1970a07e0ae85 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx @@ -28,7 +28,6 @@ interface State { layerName: string; minSourceZoom: number; maxSourceZoom: number; - mvtCanPreview: boolean; } export class MVTSingleLayerVectorSourceEditor extends Component { @@ -37,11 +36,15 @@ export class MVTSingleLayerVectorSourceEditor extends Component { layerName: '', minSourceZoom: MIN_ZOOM, maxSourceZoom: MAX_ZOOM, - mvtCanPreview: false, }; _sourceConfigChange = _.debounce(() => { - if (this.state.mvtCanPreview && this.state.layerName) { + const canPreview = + this.state.urlTemplate.indexOf('{x}') >= 0 && + this.state.urlTemplate.indexOf('{y}') >= 0 && + this.state.urlTemplate.indexOf('{z}') >= 0; + + if (canPreview && this.state.layerName) { this.props.onSourceConfigChange({ urlTemplate: this.state.urlTemplate, layerName: this.state.layerName, @@ -54,12 +57,9 @@ export class MVTSingleLayerVectorSourceEditor extends Component { // @ts-ignore _handleUrlTemplateChange = (e: ChangeEvent) => { const url = e.target.value; - const canPreview = - url.indexOf('{x}') >= 0 && url.indexOf('{y}') >= 0 && url.indexOf('{z}') >= 0; this.setState( { urlTemplate: url, - mvtCanPreview: canPreview, }, () => this._sourceConfigChange() ); From 030d1e80726a7b72c0a2470a65faeb4347e70951 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 15 Apr 2020 16:21:13 -0400 Subject: [PATCH 45/50] feedback (2) --- .../mvt_single_layer_vector_source_editor.tsx | 24 +++++-- .../maps/public/layers/tiled_vector_layer.tsx | 63 +++++++------------ 2 files changed, 40 insertions(+), 47 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx index 1970a07e0ae85..ea06375aa7af0 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx @@ -88,10 +88,21 @@ export class MVTSingleLayerVectorSourceEditor extends Component { render() { return ( - + - + { onChange={this._handleZoomRangeChange} allowEmptyRange={false} compressed - prepend={i18n.translate('xpack.maps.source.mvtVectorSource.dataZoomRangeMessage', { - defaultMessage: 'Zoom levels', - })} + prepend={i18n.translate( + 'xpack.maps.source.MVTSingleLayerVectorSourceEditor.dataZoomRangeMessage', + { + defaultMessage: 'Zoom levels', + } + )} /> ); diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index 8169f1a7065d4..a1b01d4cebb7e 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -18,6 +18,7 @@ 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 { static type = LAYER_TYPE.TILED_VECTOR; @@ -50,23 +51,23 @@ 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; - } + // _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}`); @@ -117,17 +118,7 @@ export class TiledVectorLayer extends VectorLayer { return; } - const sourceMeta: { - layerName: string; - urlTemplate: string; - minSourceZoom: number; - maxSourceZoom: number; - } | null = sourceDataRequest.getData() as { - layerName: string; - urlTemplate: string; - minSourceZoom: number; - maxSourceZoom: number; - }; + const sourceMeta: MVTSingleLayerVectorSourceConfig | null = sourceDataRequest.getData() as MVTSingleLayerVectorSourceConfig; if (!sourceMeta) { return; } @@ -155,11 +146,7 @@ export class TiledVectorLayer extends VectorLayer { if (!sourceDataRequest) { return; } - const sourceMeta: { - layerName: string; - } = sourceDataRequest.getData() as { - layerName: string; - }; + const sourceMeta: MVTSingleLayerVectorSourceConfig = sourceDataRequest.getData() as MVTSingleLayerVectorSourceConfig; const options = { mvtSourceLayer: sourceMeta.layerName }; this._setMbPointsProperties(mbMap, options); @@ -176,15 +163,7 @@ export class TiledVectorLayer extends VectorLayer { if (!dataRequest) { return false; } - const tiledSourceMeta: { - urlTemplate: string; - minSourceZoom: number; - maxSourceZoom: number; - } | null = dataRequest.getData() as { - urlTemplate: string; - minSourceZoom: number; - maxSourceZoom: number; - }; + const tiledSourceMeta: MVTSingleLayerVectorSourceConfig | null = dataRequest.getData() as MVTSingleLayerVectorSourceConfig; if ( mbTileSource.tiles[0] === tiledSourceMeta.urlTemplate && mbTileSource.minzoom === tiledSourceMeta.minSourceZoom && From 62a3593d2cbe0901fc25c8486cda117f1c56f7bf Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Wed, 15 Apr 2020 16:48:34 -0400 Subject: [PATCH 46/50] feedback --- x-pack/plugins/maps/public/layers/layer.d.ts | 2 + x-pack/plugins/maps/public/layers/layer.js | 20 +++++++ .../maps/public/layers/tiled_vector_layer.tsx | 56 +++---------------- .../maps/public/layers/vector_layer.d.ts | 4 +- .../maps/public/layers/vector_layer.js | 16 +++--- .../maps/public/layers/vector_tile_layer.js | 14 +---- 6 files changed, 40 insertions(+), 72 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/layer.d.ts b/x-pack/plugins/maps/public/layers/layer.d.ts index f8794e7d65390..e8fc5d473626c 100644 --- a/x-pack/plugins/maps/public/layers/layer.d.ts +++ b/x-pack/plugins/maps/public/layers/layer.d.ts @@ -46,4 +46,6 @@ export class AbstractLayer implements ILayer { getMaxZoom(): number; getMinSourceZoom(): number; getQuery(): MapQuery; + _removeStaleMbSourcesAndLayers(mbMap: unknown): void; + _requiresPrevSourceCleanup(mbMap: unknown): boolean; } diff --git a/x-pack/plugins/maps/public/layers/layer.js b/x-pack/plugins/maps/public/layers/layer.js index cece8fc3976f3..19dcbaf1dfcfd 100644 --- a/x-pack/plugins/maps/public/layers/layer.js +++ b/x-pack/plugins/maps/public/layers/layer.js @@ -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; } diff --git a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx index a1b01d4cebb7e..c47cae5641e56 100644 --- a/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx +++ b/x-pack/plugins/maps/public/layers/tiled_vector_layer.tsx @@ -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 { @@ -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( @@ -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) { @@ -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); } diff --git a/x-pack/plugins/maps/public/layers/vector_layer.d.ts b/x-pack/plugins/maps/public/layers/vector_layer.d.ts index d77b280424a20..3d5b8054ff3fd 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/layers/vector_layer.d.ts @@ -65,7 +65,7 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { _syncData(syncContext: SyncContext, source: IVectorSource, style: IVectorStyle): Promise; 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; } diff --git a/x-pack/plugins/maps/public/layers/vector_layer.js b/x-pack/plugins/maps/public/layers/vector_layer.js index 91091f62ae086..c5947a63587ea 100644 --- a/x-pack/plugins/maps/public/layers/vector_layer.js +++ b/x-pack/plugins/maps/public/layers/vector_layer.js @@ -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); @@ -658,7 +658,7 @@ 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; @@ -666,7 +666,7 @@ export class VectorLayer extends AbstractLayer { mbMap.setLayoutProperty(pointLayerId, 'visibility', 'none'); mbMap.setLayoutProperty(this._getMbTextLayerId(), 'visibility', 'none'); } - this._setMbSymbolProperties(mbMap, options); + this._setMbSymbolProperties(mbMap, mvtSourceLayer); } this.syncVisibilityWithMb(mbMap, markerLayerId); @@ -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); @@ -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); @@ -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(); @@ -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) { diff --git a/x-pack/plugins/maps/public/layers/vector_tile_layer.js b/x-pack/plugins/maps/public/layers/vector_tile_layer.js index 44987fd3e78f0..c620ec6c56dc3 100644 --- a/x-pack/plugins/maps/public/layers/vector_tile_layer.js +++ b/x-pack/plugins/maps/public/layers/vector_tile_layer.js @@ -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); From 6fcc772b9fbd4bf904c5d19de5e93419d8cc5d0b Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 16 Apr 2020 10:57:27 -0400 Subject: [PATCH 47/50] feedback --- .../mvt_single_layer_vector_source.ts | 2 ++ .../mvt_single_layer_vector_source_editor.tsx | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.ts b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.ts index 5479e56b800c2..0bfda6be72203 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.ts +++ b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source.ts @@ -84,6 +84,8 @@ export class MVTSingleLayerVectorSource extends AbstractSource searchFilters: unknown[], registerCancelCallback: (callback: () => void) => void ): Promise { + // todo: remove this method + // This is a consequence of ITiledSingleLayerVectorSource extending IVectorSource. throw new Error('Does not implement getGeoJsonWithMeta'); } diff --git a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx index ea06375aa7af0..7a4b8d43811da 100644 --- a/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx +++ b/x-pack/plugins/maps/public/layers/sources/mvt_single_layer_vector_source/mvt_single_layer_vector_source_editor.tsx @@ -54,7 +54,6 @@ export class MVTSingleLayerVectorSourceEditor extends Component { } }, 200); - // @ts-ignore _handleUrlTemplateChange = (e: ChangeEvent) => { const url = e.target.value; this.setState( @@ -65,7 +64,6 @@ export class MVTSingleLayerVectorSourceEditor extends Component { ); }; - // @ts-ignore _handleLayerNameInputChange = (e: ChangeEvent) => { const layerName = e.target.value; this.setState( From 42e27f4c18c6c2b044322a70312ae23f59d34562 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 16 Apr 2020 11:32:16 -0400 Subject: [PATCH 48/50] fix merge --- x-pack/legacy/plugins/maps/public/plugin.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 36c6487a260a5..a4a3df0282110 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -8,11 +8,12 @@ import '../../../../plugins/maps/public/layers/layer_wizard_registry'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import '../../../../plugins/maps/public/layers/sources/source_registry'; + import { Plugin, CoreStart, CoreSetup } from 'src/core/public'; // @ts-ignore -import { wrapInI18nContext } from 'ui/i18n'; -// @ts-ignore import { Start as InspectorStartContract } from 'src/plugins/inspector/public'; +// @ts-ignore +import { wrapInI18nContext } from 'ui/i18n'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { registerLayerWizards } from '../../../../plugins/maps/public/layers/load_layer_wizards'; // @ts-ignore From f0abe334e892b67b01b70561a2b27e264b20e530 Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 16 Apr 2020 11:39:49 -0400 Subject: [PATCH 49/50] change wizard loading --- x-pack/legacy/plugins/maps/public/plugin.ts | 8 -------- x-pack/plugins/maps/public/plugin.ts | 2 ++ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index a4a3df0282110..71f1a30c1fbef 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -4,18 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import '../../../../plugins/maps/public/layers/layer_wizard_registry'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import '../../../../plugins/maps/public/layers/sources/source_registry'; - import { Plugin, CoreStart, CoreSetup } from 'src/core/public'; // @ts-ignore import { Start as InspectorStartContract } from 'src/plugins/inspector/public'; // @ts-ignore import { wrapInI18nContext } from 'ui/i18n'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { registerLayerWizards } from '../../../../plugins/maps/public/layers/load_layer_wizards'; // @ts-ignore import { MapListing } from './components/map_listing'; // @ts-ignore @@ -70,6 +63,5 @@ export class MapsPlugin implements Plugin { public start(core: CoreStart, plugins: MapsPluginStartDependencies) { bindNpStartCoreAndPlugins(core, plugins); - registerLayerWizards(); } } diff --git a/x-pack/plugins/maps/public/plugin.ts b/x-pack/plugins/maps/public/plugin.ts index 649627690ec9a..d3b9626dc8366 100644 --- a/x-pack/plugins/maps/public/plugin.ts +++ b/x-pack/plugins/maps/public/plugin.ts @@ -33,6 +33,7 @@ import { setVisualizations, // @ts-ignore } from './kibana_services'; +import { registerLayerWizards } from './layers/load_layer_wizards'; export interface MapsPluginSetupDependencies { inspector: InspectorSetupContract; @@ -72,6 +73,7 @@ export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => { setUiActions(plugins.uiActions); setNavigation(plugins.navigation); setCoreI18n(core.i18n); + registerLayerWizards(); }; /** From 7979d339809403c68f6d68c0af08daa24f8a1d7c Mon Sep 17 00:00:00 2001 From: Thomas Neirynck Date: Thu, 16 Apr 2020 14:25:55 -0400 Subject: [PATCH 50/50] fix zoom --- x-pack/plugins/maps/public/layers/sources/source.d.ts | 4 ++++ x-pack/plugins/maps/public/layers/sources/source.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/x-pack/plugins/maps/public/layers/sources/source.d.ts b/x-pack/plugins/maps/public/layers/sources/source.d.ts index 85b54cbf20216..5a01da02adaae 100644 --- a/x-pack/plugins/maps/public/layers/sources/source.d.ts +++ b/x-pack/plugins/maps/public/layers/sources/source.d.ts @@ -31,6 +31,8 @@ export interface ISource { isTimeAware(): Promise; getImmutableProperties(): Promise; getAttributions(): Promise; + getMinZoom(): number; + getMaxZoom(): number; } export class AbstractSource implements ISource { @@ -49,4 +51,6 @@ export class AbstractSource implements ISource { isTimeAware(): Promise; getImmutableProperties(): Promise; getAttributions(): Promise; + getMinZoom(): number; + getMaxZoom(): number; } diff --git a/x-pack/plugins/maps/public/layers/sources/source.js b/x-pack/plugins/maps/public/layers/sources/source.js index 14d307efae453..555b8999d6284 100644 --- a/x-pack/plugins/maps/public/layers/sources/source.js +++ b/x-pack/plugins/maps/public/layers/sources/source.js @@ -6,6 +6,7 @@ // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { copyPersistentState } from '../../reducers/util'; +import { MIN_ZOOM, MAX_ZOOM } from '../../../common/constants'; export class AbstractSource { static isIndexingSource = false; @@ -148,4 +149,12 @@ export class AbstractSource { async getValueSuggestions(/* field, query */) { return []; } + + getMinZoom() { + return MIN_ZOOM; + } + + getMaxZoom() { + return MAX_ZOOM; + } }