Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] Add styling and tooltip support to mapbox mvt vector tile sources #64488

Merged
merged 120 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from 117 commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
1d1cd25
tmp commit
thomasneirynck Apr 23, 2020
9a3d90d
rename
thomasneirynck Apr 23, 2020
b67f20d
more boilerpalte
thomasneirynck Apr 23, 2020
1bbe0d9
more boiler
thomasneirynck Apr 23, 2020
fcfdd6c
more boilerpalte
thomasneirynck Apr 23, 2020
d9ad56a
typing
thomasneirynck Apr 26, 2020
f99e4af
fix import
thomasneirynck Apr 26, 2020
05e3c89
boilerplate
thomasneirynck Apr 26, 2020
0ce43bd
more boiler
thomasneirynck Apr 27, 2020
a33b196
enable custom palettes
thomasneirynck Apr 27, 2020
99aa6ca
fix label text and orientation
thomasneirynck Apr 27, 2020
0ad4b40
Merge branch 'master' into maps/mvt_fields
thomasneirynck May 14, 2020
c5c02d7
fix merge errors
thomasneirynck May 14, 2020
09bcbe9
Merge branch 'master' into maps/mvt_fields
thomasneirynck Jun 9, 2020
81423bd
remove dupe import
thomasneirynck Jun 9, 2020
9d41d94
stash commit
thomasneirynck Jun 10, 2020
8983e49
Merge branch 'master' into maps/mvt_fields
thomasneirynck Jun 18, 2020
ede6788
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 18, 2020
9062b31
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 18, 2020
6d2e8d9
tmp commit
thomasneirynck Jun 18, 2020
fd78533
debounce settings
thomasneirynck Jun 23, 2020
907c7b0
return null
thomasneirynck Jun 23, 2020
fb3a399
slight rearrangement
thomasneirynck Jun 23, 2020
a689ecb
tooltip guard
thomasneirynck Jun 23, 2020
dd74761
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 23, 2020
633358d
minor tweaks
thomasneirynck Jun 23, 2020
9f737f6
feedback
thomasneirynck Jun 23, 2020
42a250b
ts fixes
thomasneirynck Jun 23, 2020
9ef9277
ts fixes
thomasneirynck Jun 23, 2020
df3ac2c
more ts fixes
thomasneirynck Jun 23, 2020
d0994af
ts fixes
thomasneirynck Jun 23, 2020
a81a22a
jest test
thomasneirynck Jun 23, 2020
54de608
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 23, 2020
753fb30
fix typo
thomasneirynck Jun 24, 2020
9a7ba7b
spacing
thomasneirynck Jun 24, 2020
bc20cec
fix typing
thomasneirynck Jun 24, 2020
05b0cb3
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 24, 2020
f79904b
add unit test
thomasneirynck Jun 24, 2020
9b81fc1
add more tests
thomasneirynck Jun 24, 2020
b249ce6
add snapshot test
thomasneirynck Jun 24, 2020
adc872b
add snapshot
thomasneirynck Jun 24, 2020
f9d974c
add field editor snapshot test
thomasneirynck Jun 24, 2020
48b6e75
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 25, 2020
6e2ffb0
fix snapshot
thomasneirynck Jun 25, 2020
4c92c6b
add snapshot
thomasneirynck Jun 25, 2020
508b1c6
remove unused import
thomasneirynck Jun 25, 2020
9634353
test stub for mvt layer
thomasneirynck Jun 25, 2020
94efbf6
add snapshot test
thomasneirynck Jun 25, 2020
501fd89
add data syncing unit test
thomasneirynck Jun 25, 2020
7c47bb7
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 25, 2020
355f7ee
fix autorefactor
thomasneirynck Jun 25, 2020
ef52dd3
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 26, 2020
229bf3b
fix merge and replace snapshots
thomasneirynck Jun 26, 2020
80cf109
field editor changes
thomasneirynck Jun 26, 2020
bf9d298
field editor changes
thomasneirynck Jun 26, 2020
baaa565
ts fixes
thomasneirynck Jun 26, 2020
9c7de48
update snapshots
thomasneirynck Jun 26, 2020
8157710
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 26, 2020
d0613e9
fix things
thomasneirynck Jun 26, 2020
574a29e
fix names
thomasneirynck Jun 26, 2020
94024fa
fix tooltip
thomasneirynck Jun 26, 2020
9633a73
add more error handling
thomasneirynck Jun 26, 2020
cef7d8d
improve copy
thomasneirynck Jun 26, 2020
888a7c7
styling changes
thomasneirynck Jun 26, 2020
b0cac12
style option box a little better
thomasneirynck Jun 26, 2020
d67bf6f
ts fixes
thomasneirynck Jun 26, 2020
ef248c9
fix console error
thomasneirynck Jun 27, 2020
b04bead
Merge branch 'master' into maps/mvt_fields
elasticmachine Jun 29, 2020
d9a8cec
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 29, 2020
34a7860
Merge branch 'maps/mvt_fields' of github.com:thomasneirynck/kibana in…
thomasneirynck Jun 29, 2020
034430c
remove mbProperties from interface
thomasneirynck Jun 29, 2020
6bf83a6
remove unused method
thomasneirynck Jun 29, 2020
a6cd19e
remove cruft
thomasneirynck Jun 29, 2020
d0dcff8
rename for consistency
thomasneirynck Jun 29, 2020
d066db7
remove unused param
thomasneirynck Jun 29, 2020
3c2ab69
feedback
thomasneirynck Jun 29, 2020
69232ac
feedback
thomasneirynck Jun 29, 2020
5e915af
ensure properties are always present
thomasneirynck Jun 29, 2020
405afe1
handle possible null values
thomasneirynck Jun 29, 2020
53718ba
feedback
thomasneirynck Jun 29, 2020
62af3c1
typo
thomasneirynck Jun 29, 2020
65dd62f
update SIEM
thomasneirynck Jun 29, 2020
67c30db
feedback
thomasneirynck Jun 29, 2020
c53351a
remove cruft
thomasneirynck Jun 29, 2020
55798c4
remove unused translations
thomasneirynck Jun 29, 2020
d0d07c7
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 30, 2020
d1ea7fd
feedback
thomasneirynck Jun 30, 2020
23369e1
improve readability
thomasneirynck Jun 30, 2020
d67cd31
fix brittle test
thomasneirynck Jun 30, 2020
cc9bccc
fix snapshot after master merge
thomasneirynck Jun 30, 2020
f225181
remove unused method
thomasneirynck Jun 30, 2020
9f3a6e5
feedback
thomasneirynck Jun 30, 2020
defa8a0
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jun 30, 2020
76781a4
revert some feedback
thomasneirynck Jun 30, 2020
0883009
remove micro-optimization
thomasneirynck Jun 30, 2020
fcfba1d
initialize in constructor
thomasneirynck Jun 30, 2020
d4cb020
simplify wording
thomasneirynck Jun 30, 2020
91c5ef4
add snapshot
thomasneirynck Jun 30, 2020
a317465
naming
thomasneirynck Jun 30, 2020
96443f1
add clarifying comment
thomasneirynck Jun 30, 2020
8f0cc46
remove unused import
thomasneirynck Jun 30, 2020
1706c41
sanitize tooltips
thomasneirynck Jun 30, 2020
aab1d58
remove cruft
thomasneirynck Jun 30, 2020
f00612c
feedback
thomasneirynck Jul 1, 2020
68c26ed
fix typo
thomasneirynck Jul 1, 2020
94bcbad
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jul 1, 2020
7878b89
remove export
thomasneirynck Jul 1, 2020
7ccf075
Design fixes
elizabetdev Jul 1, 2020
188ac1b
clean up supportsAutoDomain
nreese Jul 1, 2020
77a99ab
remove patch.txt
nreese Jul 1, 2020
bb230cb
Merge branch 'maps/mvt_fields' of https://github.com/miukimiu/kibana;…
elizabetdev Jul 1, 2020
acdd196
cleanup
nreese Jul 1, 2020
e06d763
clean-up
nreese Jul 1, 2020
d2cb716
Merge branch 'mvt_fields_2' of https://github.com/nreese/kibana into …
thomasneirynck Jul 1, 2020
2ecec6b
Merge branch 'master' of github.com:elastic/kibana into maps/mvt_fields
thomasneirynck Jul 1, 2020
217b76a
Merge branch 'maps/mvt_fields' of https://github.com/miukimiu/kibana …
thomasneirynck Jul 1, 2020
37bb626
Merge in styling changes
thomasneirynck Jul 1, 2020
7853299
Tweak message format
thomasneirynck Jul 1, 2020
333d8b5
Merge branch 'master' into maps/mvt_fields
elasticmachine Jul 1, 2020
d8603d7
fix broken import
thomasneirynck Jul 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import { i18n } from '@kbn/i18n';
import React, { Component } from 'react';
import React, { Component, ReactNode } from 'react';
import { EuiFormRow, EuiDualRange } from '@elastic/eui';
import { EuiFormRowDisplayKeys } from '@elastic/eui/src/components/form/form_row/form_row';
import { EuiDualRangeProps } from '@elastic/eui/src/components/form/range/dual_range';
Expand All @@ -32,7 +32,7 @@ export type ValueMember = EuiDualRangeProps['value'][0];
interface Props extends Omit<EuiDualRangeProps, 'value' | 'onChange' | 'min' | 'max'> {
value?: Value;
allowEmptyRange?: boolean;
label?: string;
label?: string | ReactNode;
formRowDisplay?: EuiFormRowDisplayKeys;
onChange?: (val: [string, string]) => void;
min?: number;
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ export enum SCALING_TYPES {

export const RGBA_0000 = 'rgba(0,0,0,0)';

export enum MVT_FIELD_TYPE {
STRING = 'String',
NUMBER = 'Number',
}

export const SPATIAL_FILTERS_LAYER_ID = 'SPATIAL_FILTERS_LAYER_ID';

export enum INITIAL_LOCATION {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/common/descriptor_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
*/

export * from './data_request_descriptor_types';
export * from './descriptor_types';
export * from './sources';
export * from './map_descriptor';
export * from './style_property_descriptor_types';
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { GeoJsonProperties } from 'geojson';
import { Query } from '../../../../../src/plugins/data/common';
import { DRAW_TYPE, ES_GEO_FIELD_TYPE, ES_SPATIAL_RELATIONS } from '../constants';

Expand Down Expand Up @@ -39,8 +40,9 @@ export type Goto = {
};

export type TooltipFeature = {
id: number;
id?: number | string;
layerId: string;
mbProperties: GeoJsonProperties;
};

export type TooltipState = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@

import { FeatureCollection } from 'geojson';
import { Query } from 'src/plugins/data/public';
import { AGG_TYPE, GRID_RESOLUTION, RENDER_AS, SORT_ORDER, SCALING_TYPES } from '../constants';
import {
AGG_TYPE,
GRID_RESOLUTION,
RENDER_AS,
SORT_ORDER,
SCALING_TYPES,
MVT_FIELD_TYPE,
} from '../constants';
import { StyleDescriptor, VectorStyleDescriptor } from './style_property_descriptor_types';
import { DataRequestDescriptor } from './data_request_descriptor_types';

Expand Down Expand Up @@ -96,18 +103,34 @@ export type XYZTMSSourceDescriptor = AbstractSourceDescriptor &
urlTemplate: string;
};

export type TiledSingleLayerVectorSourceDescriptor = AbstractSourceDescriptor & {
export type MVTFieldDescriptor = {
name: string;
type: MVT_FIELD_TYPE;
};

export type TiledSingleLayerVectorSourceSettings = {
urlTemplate: string;
layerName: string;

// 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
// These are important so mapbox does not issue invalid requests based on the zoom level.

// Tiled layer data cannot be displayed at lower levels of zoom than that they are stored in the tileset.
// e.g. building footprints at level 14 cannot be displayed at level 0.
minSourceZoom: number;
// Tiled layer 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
maxSourceZoom: number;

fields: MVTFieldDescriptor[];
};

export type TiledSingleLayerVectorSourceDescriptor = AbstractSourceDescriptor &
TiledSingleLayerVectorSourceSettings & {
tooltipProperties: string[];
};

export type GeojsonFileSourceDescriptor = {
__featureCollection: FeatureCollection;
name: string;
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/maps/public/classes/fields/es_agg_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ export class ESAggField implements IESAggField {
async getCategoricalFieldMetaRequest(size: number): Promise<unknown> {
return this._esDocField ? this._esDocField.getCategoricalFieldMetaRequest(size) : null;
}

supportsAutoDomain(): boolean {
return true;
}
}

export function esAggFieldsFactory(
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/maps/public/classes/fields/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export interface IField {
isValid(): boolean;
getOrdinalFieldMetaRequest(): Promise<unknown>;
getCategoricalFieldMetaRequest(size: number): Promise<unknown>;

// Determines whether Maps-app can automatically determine the domain of the field-values
// if this is not the case (e.g. for .mvt tiled data),
// then styling properties that require the domain to be known cannot use this property.
supportsAutoDomain(): boolean;

supportsFieldMeta(): boolean;
}

Expand Down Expand Up @@ -80,4 +86,8 @@ export class AbstractField implements IField {
async getCategoricalFieldMetaRequest(size: number): Promise<unknown> {
return null;
}

supportsAutoDomain(): boolean {
return true;
}
}
59 changes: 59 additions & 0 deletions x-pack/plugins/maps/public/classes/fields/mvt_field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 { AbstractField, IField } from './field';
import { FIELD_ORIGIN, MVT_FIELD_TYPE } from '../../../common/constants';
import { ITiledSingleLayerVectorSource, IVectorSource } from '../sources/vector_source';
import { MVTFieldDescriptor } from '../../../common/descriptor_types';

export class MVTField extends AbstractField implements IField {
private readonly _source: ITiledSingleLayerVectorSource;
private readonly _type: MVT_FIELD_TYPE;
constructor({
fieldName,
type,
source,
origin,
}: {
fieldName: string;
source: ITiledSingleLayerVectorSource;
origin: FIELD_ORIGIN;
type: MVT_FIELD_TYPE;
}) {
super({ fieldName, origin });
this._source = source;
this._type = type;
}

getMVTFieldDescriptor(): MVTFieldDescriptor {
return {
type: this._type,
name: this.getName(),
};
}

getSource(): IVectorSource {
return this._source;
}

async getDataType(): Promise<string> {
if (this._type === MVT_FIELD_TYPE.STRING) {
return 'string';
} else if (this._type === MVT_FIELD_TYPE.NUMBER) {
return 'number';
} else {
throw new Error(`Unrecognized MVT field-type ${this._type}`);
}
}

async getLabel(): Promise<string> {
return this.getName();
}

supportsAutoDomain() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export class TopTermPercentageField implements IESAggField {
return 0;
}

supportsAutoDomain(): boolean {
return true;
}

supportsFieldMeta(): boolean {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 sinon from 'sinon';
import { DataRequestContext } from '../../../actions';
import { DataMeta, MapFilters } from '../../../../common/descriptor_types';

export class MockSyncContext implements DataRequestContext {
dataFilters: MapFilters;
isRequestStillActive: (dataId: string, requestToken: symbol) => boolean;
onLoadError: (dataId: string, requestToken: symbol, errorMessage: string) => void;
registerCancelCallback: (requestToken: symbol, callback: () => void) => void;
startLoading: (dataId: string, requestToken: symbol, meta: DataMeta) => void;
stopLoading: (dataId: string, requestToken: symbol, data: object, meta: DataMeta) => void;
updateSourceData: (newData: unknown) => void;

constructor({ dataFilters }: { dataFilters: Partial<MapFilters> }) {
const mapFilters: MapFilters = {
filters: [],
timeFilters: {
from: 'now',
to: '15m',
mode: 'relative',
},
zoom: 0,
...dataFilters,
};

this.dataFilters = mapFilters;
this.isRequestStillActive = sinon.spy();
this.onLoadError = sinon.spy();
this.registerCancelCallback = sinon.spy();
this.startLoading = sinon.spy();
this.stopLoading = sinon.spy();
this.updateSourceData = sinon.spy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { getFileUploadComponent } from '../../../kibana_services';
import { GeojsonFileSource } from '../../sources/geojson_file_source';
import { VectorLayer } from '../../layers/vector_layer/vector_layer';
// @ts-ignore
// @ts-expect-error
import { createDefaultLayerDescriptor } from '../../sources/es_search_source';
import { RenderWizardArguments } from '../../layers/layer_wizard_registry';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class HeatmapLayer extends VectorLayer {
resolution: this.getSource().getGridResolution(),
});
mbMap.setPaintProperty(heatmapLayerId, 'heatmap-opacity', this.getAlpha());
mbMap.setLayerZoomRange(heatmapLayerId, this._descriptor.minZoom, this._descriptor.maxZoom);
mbMap.setLayerZoomRange(heatmapLayerId, this.getMinZoom(), this.getMaxZoom());
}

getLayerTypeIconName() {
Expand Down
17 changes: 9 additions & 8 deletions x-pack/plugins/maps/public/classes/layers/layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,27 +325,28 @@ export class AbstractLayer implements ILayer {
return this._source.getMinZoom();
}

_getMbSourceId() {
return this.getId();
}

_requiresPrevSourceCleanup(mbMap: unknown) {
return false;
}

_removeStaleMbSourcesAndLayers(mbMap: unknown) {
if (this._requiresPrevSourceCleanup(mbMap)) {
// @ts-ignore
// @ts-expect-error
const mbStyle = mbMap.getStyle();
// @ts-ignore
// @ts-expect-error
mbStyle.layers.forEach((mbLayer) => {
// @ts-ignore
if (this.ownsMbLayerId(mbLayer.id)) {
// @ts-ignore
// @ts-expect-error
mbMap.removeLayer(mbLayer.id);
}
});
// @ts-ignore
Object.keys(mbStyle.sources).some((mbSourceId) => {
// @ts-ignore
if (this.ownsMbSourceId(mbSourceId)) {
// @ts-ignore
// @ts-expect-error
mbMap.removeSource(mbSourceId);
}
});
Expand Down Expand Up @@ -429,7 +430,7 @@ export class AbstractLayer implements ILayer {
throw new Error('Should implement AbstractLayer#ownsMbLayerId');
}

ownsMbSourceId(sourceId: string): boolean {
ownsMbSourceId(mbSourceId: string): boolean {
throw new Error('Should implement AbstractLayer#ownsMbSourceId');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export class TileLayer extends AbstractLayer {
return;
}

const sourceId = this.getId();
mbMap.addSource(sourceId, {
const mbSourceId = this._getMbSourceId();
mbMap.addSource(mbSourceId, {
type: 'raster',
tiles: [tmsSourceData.url],
tileSize: 256,
Expand All @@ -85,7 +85,7 @@ export class TileLayer extends AbstractLayer {
mbMap.addLayer({
id: mbLayerId,
type: 'raster',
source: sourceId,
source: mbSourceId,
minzoom: this._descriptor.minZoom,
maxzoom: this._descriptor.maxZoom,
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading