Skip to content

Commit 9c76f19

Browse files
thomasneirynckelasticmachineelizabetdevnreese
authored
[Maps] Add styling and tooltip support to mapbox mvt vector tile sources (#64488)
* tmp commit * rename * more boilerpalte * more boiler * more boilerpalte * typing * fix import * boilerplate * more boiler * enable custom palettes * fix label text and orientation * fix merge errors * remove dupe import * stash commit * tmp commit * debounce settings * return null * slight rearrangement * tooltip guard * minor tweaks * feedback * ts fixes * ts fixes * more ts fixes * ts fixes * jest test * fix typo * spacing * fix typing * add unit test * add more tests * add snapshot test * add snapshot * add field editor snapshot test * fix snapshot * add snapshot * remove unused import * test stub for mvt layer fix optional param more checks * add snapshot test more unit tests more unit tests ts fixes * add data syncing unit test * fix autorefactor * fix merge and replace snapshots * field editor changes * field editor changes * ts fixes * update snapshots * fix things * fix names * fix tooltip * add more error handling * improve copy * styling changes * style option box a little better * ts fixes * fix console error * remove mbProperties from interface * remove unused method * remove cruft * rename for consistency * remove unused param * feedback * feedback * ensure properties are always present * handle possible null values * feedback * typo * update SIEM * feedback * remove cruft * remove unused translations * feedback * improve readability * fix brittle test * fix snapshot after master merge * remove unused method * feedback * revert some feedback * remove micro-optimization * initialize in constructor * simplify wording * add snapshot * naming * add clarifying comment * remove unused import * sanitize tooltips * remove cruft * feedback * fix typo * remove export * Design fixes * clean up supportsAutoDomain * remove patch.txt * cleanup * clean-up * Merge in styling changes * Tweak message format * fix broken import Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: miukimiu <[email protected]> Co-authored-by: Nathan Reese <[email protected]>
1 parent 3f80868 commit 9c76f19

File tree

62 files changed

+2405
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2405
-378
lines changed

src/plugins/kibana_react/public/validated_range/validated_dual_range.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919
import { i18n } from '@kbn/i18n';
20-
import React, { Component } from 'react';
20+
import React, { Component, ReactNode } from 'react';
2121
import { EuiFormRow, EuiDualRange } from '@elastic/eui';
2222
import { EuiFormRowDisplayKeys } from '@elastic/eui/src/components/form/form_row/form_row';
2323
import { EuiDualRangeProps } from '@elastic/eui/src/components/form/range/dual_range';
@@ -32,7 +32,7 @@ export type ValueMember = EuiDualRangeProps['value'][0];
3232
interface Props extends Omit<EuiDualRangeProps, 'value' | 'onChange' | 'min' | 'max'> {
3333
value?: Value;
3434
allowEmptyRange?: boolean;
35-
label?: string;
35+
label?: string | ReactNode;
3636
formRowDisplay?: EuiFormRowDisplayKeys;
3737
onChange?: (val: [string, string]) => void;
3838
min?: number;

x-pack/plugins/maps/common/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ export enum SCALING_TYPES {
223223

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

226+
export enum MVT_FIELD_TYPE {
227+
STRING = 'String',
228+
NUMBER = 'Number',
229+
}
230+
226231
export const SPATIAL_FILTERS_LAYER_ID = 'SPATIAL_FILTERS_LAYER_ID';
227232

228233
export enum INITIAL_LOCATION {

x-pack/plugins/maps/common/descriptor_types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
*/
66

77
export * from './data_request_descriptor_types';
8-
export * from './descriptor_types';
8+
export * from './sources';
99
export * from './map_descriptor';
1010
export * from './style_property_descriptor_types';

x-pack/plugins/maps/common/descriptor_types/map_descriptor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
/* eslint-disable @typescript-eslint/consistent-type-definitions */
77

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

@@ -39,8 +40,9 @@ export type Goto = {
3940
};
4041

4142
export type TooltipFeature = {
42-
id: number;
43+
id?: number | string;
4344
layerId: string;
45+
mbProperties: GeoJsonProperties;
4446
};
4547

4648
export type TooltipState = {

x-pack/plugins/maps/common/descriptor_types/descriptor_types.d.ts renamed to x-pack/plugins/maps/common/descriptor_types/sources.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77

88
import { FeatureCollection } from 'geojson';
99
import { Query } from 'src/plugins/data/public';
10-
import { AGG_TYPE, GRID_RESOLUTION, RENDER_AS, SORT_ORDER, SCALING_TYPES } from '../constants';
10+
import {
11+
AGG_TYPE,
12+
GRID_RESOLUTION,
13+
RENDER_AS,
14+
SORT_ORDER,
15+
SCALING_TYPES,
16+
MVT_FIELD_TYPE,
17+
} from '../constants';
1118
import { StyleDescriptor, VectorStyleDescriptor } from './style_property_descriptor_types';
1219
import { DataRequestDescriptor } from './data_request_descriptor_types';
1320

@@ -96,18 +103,34 @@ export type XYZTMSSourceDescriptor = AbstractSourceDescriptor &
96103
urlTemplate: string;
97104
};
98105

99-
export type TiledSingleLayerVectorSourceDescriptor = AbstractSourceDescriptor & {
106+
export type MVTFieldDescriptor = {
107+
name: string;
108+
type: MVT_FIELD_TYPE;
109+
};
110+
111+
export type TiledSingleLayerVectorSourceSettings = {
100112
urlTemplate: string;
101113
layerName: string;
102114

103115
// These are the min/max zoom levels of the availability of the a particular layerName in the tileset at urlTemplate.
104116
// These are _not_ the visible zoom-range of the data on a map.
105-
// Tiled data can be displayed at higher levels of zoom than that they are stored in the tileset.
106-
// e.g. EMS basemap data from level 14 is at most detailed resolution and can be displayed at higher levels
117+
// These are important so mapbox does not issue invalid requests based on the zoom level.
118+
119+
// Tiled layer data cannot be displayed at lower levels of zoom than that they are stored in the tileset.
120+
// e.g. building footprints at level 14 cannot be displayed at level 0.
107121
minSourceZoom: number;
122+
// Tiled layer data can be displayed at higher levels of zoom than that they are stored in the tileset.
123+
// e.g. EMS basemap data from level 14 is at most detailed resolution and can be displayed at higher levels
108124
maxSourceZoom: number;
125+
126+
fields: MVTFieldDescriptor[];
109127
};
110128

129+
export type TiledSingleLayerVectorSourceDescriptor = AbstractSourceDescriptor &
130+
TiledSingleLayerVectorSourceSettings & {
131+
tooltipProperties: string[];
132+
};
133+
111134
export type GeojsonFileSourceDescriptor = {
112135
__featureCollection: FeatureCollection;
113136
name: string;

x-pack/plugins/maps/public/classes/fields/es_agg_field.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ export class ESAggField implements IESAggField {
128128
async getCategoricalFieldMetaRequest(size: number): Promise<unknown> {
129129
return this._esDocField ? this._esDocField.getCategoricalFieldMetaRequest(size) : null;
130130
}
131+
132+
supportsAutoDomain(): boolean {
133+
return true;
134+
}
131135
}
132136

133137
export function esAggFieldsFactory(

x-pack/plugins/maps/public/classes/fields/field.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export interface IField {
2020
isValid(): boolean;
2121
getOrdinalFieldMetaRequest(): Promise<unknown>;
2222
getCategoricalFieldMetaRequest(size: number): Promise<unknown>;
23+
24+
// Determines whether Maps-app can automatically determine the domain of the field-values
25+
// if this is not the case (e.g. for .mvt tiled data),
26+
// then styling properties that require the domain to be known cannot use this property.
27+
supportsAutoDomain(): boolean;
28+
2329
supportsFieldMeta(): boolean;
2430
}
2531

@@ -80,4 +86,8 @@ export class AbstractField implements IField {
8086
async getCategoricalFieldMetaRequest(size: number): Promise<unknown> {
8187
return null;
8288
}
89+
90+
supportsAutoDomain(): boolean {
91+
return true;
92+
}
8393
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { AbstractField, IField } from './field';
8+
import { FIELD_ORIGIN, MVT_FIELD_TYPE } from '../../../common/constants';
9+
import { ITiledSingleLayerVectorSource, IVectorSource } from '../sources/vector_source';
10+
import { MVTFieldDescriptor } from '../../../common/descriptor_types';
11+
12+
export class MVTField extends AbstractField implements IField {
13+
private readonly _source: ITiledSingleLayerVectorSource;
14+
private readonly _type: MVT_FIELD_TYPE;
15+
constructor({
16+
fieldName,
17+
type,
18+
source,
19+
origin,
20+
}: {
21+
fieldName: string;
22+
source: ITiledSingleLayerVectorSource;
23+
origin: FIELD_ORIGIN;
24+
type: MVT_FIELD_TYPE;
25+
}) {
26+
super({ fieldName, origin });
27+
this._source = source;
28+
this._type = type;
29+
}
30+
31+
getMVTFieldDescriptor(): MVTFieldDescriptor {
32+
return {
33+
type: this._type,
34+
name: this.getName(),
35+
};
36+
}
37+
38+
getSource(): IVectorSource {
39+
return this._source;
40+
}
41+
42+
async getDataType(): Promise<string> {
43+
if (this._type === MVT_FIELD_TYPE.STRING) {
44+
return 'string';
45+
} else if (this._type === MVT_FIELD_TYPE.NUMBER) {
46+
return 'number';
47+
} else {
48+
throw new Error(`Unrecognized MVT field-type ${this._type}`);
49+
}
50+
}
51+
52+
async getLabel(): Promise<string> {
53+
return this.getName();
54+
}
55+
56+
supportsAutoDomain() {
57+
return false;
58+
}
59+
}

0 commit comments

Comments
 (0)