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 super-fine option to grid/cluster layers #76526

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
64d439b
boilerplate
thomasneirynck Sep 2, 2020
c21d565
more boilerplate
thomasneirynck Sep 2, 2020
abf23ca
even more boilerplate
thomasneirynck Sep 2, 2020
d5e882d
add round-trip boilerplate
thomasneirynck Sep 2, 2020
416ed56
Merge branch 'master' of github.com:elastic/kibana into maps/es_mvt_g…
thomasneirynck Sep 7, 2020
6b04156
move to common
thomasneirynck Sep 8, 2020
3f42ffe
move more files
thomasneirynck Sep 8, 2020
46e162a
move more utils
thomasneirynck Sep 8, 2020
3a67982
reuse existing implementation
thomasneirynck Sep 8, 2020
0df9b29
fix autodomain
thomasneirynck Sep 8, 2020
b1aa692
minor fixes
thomasneirynck Sep 8, 2020
2d84c57
undo typo
thomasneirynck Sep 8, 2020
9bb547f
enable grids
thomasneirynck Sep 8, 2020
a63d8a7
add shape support
thomasneirynck Sep 8, 2020
ee0f4d0
Merge branch 'master' of github.com:elastic/kibana into maps/es_mvt_g…
thomasneirynck Sep 8, 2020
2342a35
create util folder
thomasneirynck Sep 8, 2020
b986964
remove some dupe
thomasneirynck Sep 8, 2020
86105f4
not done
thomasneirynck Sep 8, 2020
9693042
add new api extension
thomasneirynck Sep 8, 2020
3d28a58
Merge branch 'master' of github.com:elastic/kibana into maps/es_mvt_g…
thomasneirynck Sep 9, 2020
01ed2d3
reuse implementation
thomasneirynck Sep 9, 2020
eecef6c
ts fixes
thomasneirynck Sep 9, 2020
9aa2038
type fixes
thomasneirynck Sep 9, 2020
9428aa1
more type fixes
thomasneirynck Sep 9, 2020
16f26d2
more type fixes
thomasneirynck Sep 9, 2020
b3bd0f1
remove cruft
thomasneirynck Sep 9, 2020
a148f5c
remove log
thomasneirynck Sep 9, 2020
db23dc5
remove dupes
thomasneirynck Sep 9, 2020
1ed2b67
simplification
thomasneirynck Sep 9, 2020
270f82c
reuse existing tile parsing
thomasneirynck Sep 9, 2020
751a39b
Merge branch 'master' of github.com:elastic/kibana into maps/es_mvt_g…
thomasneirynck Sep 10, 2020
989f767
Merge branch 'master' of github.com:elastic/kibana into maps/es_mvt_g…
thomasneirynck Sep 10, 2020
4e71f48
review feedback
thomasneirynck Sep 10, 2020
348a7ab
remove param
thomasneirynck Sep 10, 2020
0d5d0b6
remove fluffy try-catch
thomasneirynck Sep 10, 2020
7c642bf
Merge branch 'master' of github.com:elastic/kibana into maps/es_mvt_g…
thomasneirynck Sep 14, 2020
a3946de
Add deprecation message to coordinate map and region map
nreese Sep 14, 2020
bbf755f
clean up text
nreese Sep 15, 2020
8c61d70
Merge branch 'master' of github.com:elastic/kibana into maps/es_mvt_g…
thomasneirynck Sep 16, 2020
b773bb3
remove interfaces
thomasneirynck Sep 16, 2020
1e672ad
Merge branch 'master' of github.com:elastic/kibana into deprecation_m…
nreese Sep 16, 2020
1b5a900
add default distro link and view in maps link
nreese Sep 16, 2020
7571e3d
move url generation into onClick handler
nreese Sep 16, 2020
7ab105b
create tile map layer descritor
nreese Sep 16, 2020
a18083c
set metrics and color and scaling
nreese Sep 17, 2020
820acb3
lazy load createTileMapLayerDescriptor
nreese Sep 17, 2020
c9fa756
tslint fixes
nreese Sep 17, 2020
33f205e
Merge branch 'master' of github.com:elastic/kibana into maps/es_mvt_g…
thomasneirynck Sep 17, 2020
99ca7d8
remove things
thomasneirynck Sep 18, 2020
fbecaf8
Merge branch 'master' of github.com:elastic/kibana into maps/es_mvt_g…
thomasneirynck Sep 18, 2020
cfc4d21
add unit tests
thomasneirynck Sep 18, 2020
bb478aa
add unit tests
thomasneirynck Sep 18, 2020
45d587b
tslint cleanup for OSS code
nreese Sep 18, 2020
9fce05d
add snapshot
thomasneirynck Sep 18, 2020
070fac2
Merge branch 'deprecation_message' of https://github.com/nreese/kiban…
thomasneirynck Sep 18, 2020
5ad5585
Merge branch 'master' of github.com:elastic/kibana into maps/es_mvt_g…
thomasneirynck Sep 22, 2020
debec1e
feedback
thomasneirynck Sep 22, 2020
0b9fe76
make use of currentLayerType consistent
thomasneirynck Sep 22, 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
6 changes: 6 additions & 0 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const FONTS_API_PATH = `${GIS_API_PATH}/fonts`;
export const API_ROOT_PATH = `/${GIS_API_PATH}`;

export const MVT_GETTILE_API_PATH = 'mvt/getTile';
export const MVT_GETGRIDTILE_API_PATH = 'mvt/getGridTile';
export const MVT_SOURCE_LAYER_NAME = 'source_layer';
export const KBN_TOO_MANY_FEATURES_PROPERTY = '__kbn_too_many_features__';
export const KBN_TOO_MANY_FEATURES_IMAGE_ID = '__kbn_too_many_features_image_id__';
Expand Down Expand Up @@ -164,8 +165,13 @@ export enum GRID_RESOLUTION {
COARSE = 'COARSE',
FINE = 'FINE',
MOST_FINE = 'MOST_FINE',
SUPER_FINE = 'SUPER_FINE',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is beyond the scope of this PR, but I wonder if we can have a range slider option next to the hard-coded select box values for advanced users to fine-tune their resolution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will create follow-up issue for this after this merges.

}

export const SUPER_FINE_ZOOM_DELTA = 7; // (2 ^ SUPER_FINE_ZOOM_DELTA) ^ 2 = number of cells in a given tile
export const GEOTILE_GRID_AGG_NAME = 'gridSplit';
export const GEOCENTROID_AGG_NAME = 'gridCentroid';

export const TOP_TERM_PERCENTAGE_SUFFIX = '__percentage';

export const COUNT_PROP_LABEL = i18n.translate('xpack.maps.aggs.defaultCountLabel', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

import _ from 'lodash';
import { RENDER_AS } from '../../../../common/constants';
import { RENDER_AS, GEOTILE_GRID_AGG_NAME, GEOCENTROID_AGG_NAME } from './constants';
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
import { getTileBoundingBox } from './geo_tile_utils';
import { extractPropertiesFromBucket } from '../../util/es_agg_utils';
import { clamp } from '../../../../common/elasticsearch_geo_utils';
import { extractPropertiesFromBucket } from './es_agg_utils';
import { clamp } from './elasticsearch_geo_utils';

const GRID_BUCKET_KEYS_TO_IGNORE = ['key', 'gridCentroid'];
const GRID_BUCKET_KEYS_TO_IGNORE = ['key', GEOCENTROID_AGG_NAME];

export function convertCompositeRespToGeoJson(esResponse, renderAs) {
return convertToGeoJson(
Expand All @@ -20,7 +20,7 @@ export function convertCompositeRespToGeoJson(esResponse, renderAs) {
return _.get(esResponse, 'aggregations.compositeSplit.buckets', []);
},
(gridBucket) => {
return gridBucket.key.gridSplit;
return gridBucket.key[GEOTILE_GRID_AGG_NAME];
}
);
}
Expand All @@ -30,7 +30,7 @@ export function convertRegularRespToGeoJson(esResponse, renderAs) {
esResponse,
renderAs,
(esResponse) => {
return _.get(esResponse, 'aggregations.gridSplit.buckets', []);
return _.get(esResponse, `aggregations.${GEOTILE_GRID_AGG_NAME}.buckets`, []);
},
(gridBucket) => {
return gridBucket.key;
Expand All @@ -49,7 +49,7 @@ function convertToGeoJson(esResponse, renderAs, pluckGridBuckets, pluckGridKey)
type: 'Feature',
geometry: rowToGeometry({
gridKey,
gridCentroid: gridBucket.gridCentroid,
[GEOCENTROID_AGG_NAME]: gridBucket[GEOCENTROID_AGG_NAME],
renderAs,
}),
id: gridKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/
import { i18n } from '@kbn/i18n';
import _ from 'lodash';
import { IndexPattern, IFieldType } from '../../../../../../src/plugins/data/public';
import { TOP_TERM_PERCENTAGE_SUFFIX } from '../../../common/constants';
import { IndexPattern, IFieldType } from '../../../../../../src/plugins/data/common';
import { TOP_TERM_PERCENTAGE_SUFFIX } from './constants';

export function getField(indexPattern: IndexPattern, fieldName: string) {
const field = indexPattern.fields.getByName(fieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import _ from 'lodash';
import { DECIMAL_DEGREES_PRECISION } from '../../../../common/constants';
import { clampToLatBounds } from '../../../../common/elasticsearch_geo_utils';
import { DECIMAL_DEGREES_PRECISION } from './constants';
import { clampToLatBounds } from './elasticsearch_geo_utils';

const ZOOM_TILE_KEY_INDEX = 0;
const X_TILE_KEY_INDEX = 1;
Expand Down
15 changes: 10 additions & 5 deletions x-pack/plugins/maps/public/classes/fields/es_agg_field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IVectorSource } from '../sources/vector_source';
import { ESDocField } from './es_doc_field';
import { AGG_TYPE, FIELD_ORIGIN } from '../../../common/constants';
import { isMetricCountable } from '../util/is_metric_countable';
import { getField, addFieldToDSL } from '../util/es_agg_utils';
import { getField, addFieldToDSL } from '../../../common/es_agg_utils';
import { TopTermPercentageField } from './top_term_percentage_field';
import { ITooltipProperty, TooltipProperty } from '../tooltips/tooltip_property';
import { ESAggTooltipProperty } from '../tooltips/es_agg_tooltip_property';
Expand All @@ -30,13 +30,15 @@ export class ESAggField implements IESAggField {
private readonly _label?: string;
private readonly _aggType: AGG_TYPE;
private readonly _esDocField?: IField | undefined;
private readonly _canReadFromGeoJson: boolean;

constructor({
label,
source,
aggType,
esDocField,
origin,
canReadFromGeoJson = true,
}: {
label?: string;
source: IESAggSource;
Expand All @@ -49,6 +51,7 @@ export class ESAggField implements IESAggField {
this._label = label;
this._aggType = aggType;
this._esDocField = esDocField;
this._canReadFromGeoJson = canReadFromGeoJson;
}

getSource(): IVectorSource {
Expand Down Expand Up @@ -132,18 +135,19 @@ export class ESAggField implements IESAggField {
}

supportsAutoDomain(): boolean {
return true;
return this._canReadFromGeoJson ? true : this.supportsFieldMeta();
}

canReadFromGeoJson(): boolean {
return true;
return this._canReadFromGeoJson;
}
}

export function esAggFieldsFactory(
aggDescriptor: AggDescriptor,
source: IESAggSource,
origin: FIELD_ORIGIN
origin: FIELD_ORIGIN,
canReadFromGeoJson?: boolean = true
): IESAggField[] {
const aggField = new ESAggField({
label: aggDescriptor.label,
Expand All @@ -153,12 +157,13 @@ export function esAggFieldsFactory(
aggType: aggDescriptor.type,
source,
origin,
canReadFromGeoJson,
});

const aggFields: IESAggField[] = [aggField];

if (aggDescriptor.field && aggDescriptor.type === AGG_TYPE.TERMS) {
aggFields.push(new TopTermPercentageField(aggField));
aggFields.push(new TopTermPercentageField(aggField, canReadFromGeoJson));
}

return aggFields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { FIELD_ORIGIN } from '../../../common/constants';

export class TopTermPercentageField implements IESAggField {
private readonly _topTermAggField: IESAggField;
private readonly _canReadFromGeoJson: boolean;

constructor(topTermAggField: IESAggField) {
constructor(topTermAggField: IESAggField, canReadFromGeoJson?: boolean = true) {
this._topTermAggField = topTermAggField;
this._canReadFromGeoJson = canReadFromGeoJson;
}

getSource(): IVectorSource {
Expand Down Expand Up @@ -61,7 +63,7 @@ export class TopTermPercentageField implements IESAggField {
}

supportsAutoDomain(): boolean {
return true;
return this._canReadFromGeoJson;
}

supportsFieldMeta(): boolean {
Expand All @@ -81,6 +83,6 @@ export class TopTermPercentageField implements IESAggField {
}

canReadFromGeoJson(): boolean {
return true;
return this._canReadFromGeoJson;
}
}
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/classes/layers/layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export class AbstractLayer implements ILayer {

renderSourceSettingsEditor({ onChange }: SourceEditorArgs) {
const source = this.getSourceForEditing();
return source.renderSourceSettingsEditor({ onChange });
return source.renderSourceSettingsEditor({ onChange, currentLayerType: this._descriptor.type });
thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
}

getPrevRequestToken(dataId: string): symbol | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class TiledVectorLayer extends VectorLayer {
const templateWithMeta = await this._source.getUrlTemplateWithMeta(searchFilters);
if (prevDataRequest) {
const data: MVTSingleLayerVectorSourceConfig = prevDataRequest.getData() as MVTSingleLayerVectorSourceConfig;

if (data) {
const canSkipBecauseNoChanges =
data.layerName === this._source.getLayerName() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ import { AbstractESAggSourceDescriptor } from '../../../../common/descriptor_typ
export interface IESAggSource extends IESSource {
getAggKey(aggType: AGG_TYPE, fieldName: string): string;
getAggLabel(aggType: AGG_TYPE, fieldName: string): string;
getMetricFields(): IESAggField[];
getMetricFields(canReadFromGeoJson?: boolean): IESAggField[];
hasMatchingMetricField(fieldName: string): boolean;
getMetricFieldForName(fieldName: string): IESAggField | null;
}

export class AbstractESAggSource extends AbstractESSource implements IESAggSource {
constructor(sourceDescriptor: AbstractESAggSourceDescriptor, inspectorAdapters: object);
constructor(
sourceDescriptor: AbstractESAggSourceDescriptor,
inspectorAdapters: object,
canReadFromGeoJson?
);

getAggKey(aggType: AGG_TYPE, fieldName: string): string;
getAggLabel(aggType: AGG_TYPE, fieldName: string): string;
getMetricFields(): IESAggField[];
getMetricFields(canReadFromGeoJson?: boolean): IESAggField[];
hasMatchingMetricField(fieldName: string): boolean;
getMetricFieldForName(fieldName: string): IESAggField | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import { getSourceAggKey } from '../../../../common/get_agg_key';
export const DEFAULT_METRIC = { type: AGG_TYPE.COUNT };

export class AbstractESAggSource extends AbstractESSource {
constructor(descriptor, inspectorAdapters) {
constructor(descriptor, inspectorAdapters, canReadFromGeoJson = true) {
super(descriptor, inspectorAdapters);
this._metricFields = [];
if (this._descriptor.metrics) {
this._descriptor.metrics.forEach((aggDescriptor) => {
this._metricFields.push(
...esAggFieldsFactory(aggDescriptor, this, this.getOriginForField())
...esAggFieldsFactory(aggDescriptor, this, this.getOriginForField(), canReadFromGeoJson)
);
});
}
Expand Down Expand Up @@ -48,11 +48,16 @@ export class AbstractESAggSource extends AbstractESSource {
return FIELD_ORIGIN.SOURCE;
}

getMetricFields() {
getMetricFields(canReadFromGeoJson = true) {
const metrics = this._metricFields.filter((esAggField) => esAggField.isValid());
// Handle case where metrics is empty because older saved object state is empty array or there are no valid aggs.
return metrics.length === 0
? esAggFieldsFactory({ type: AGG_TYPE.COUNT }, this, this.getOriginForField())
? esAggFieldsFactory(
{ type: AGG_TYPE.COUNT },
this,
this.getOriginForField(),
canReadFromGeoJson
)
: metrics;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
*/

import { AbstractESAggSource } from '../es_agg_source';
import { ESGeoGridSourceDescriptor } from '../../../../common/descriptor_types';
import {
ESGeoGridSourceDescriptor,
MapFilters,
MapQuery,
} from '../../../../common/descriptor_types';
import { GRID_RESOLUTION } from '../../../../common/constants';
import { ITiledSingleLayerVectorSource } from '../vector_source';

export class ESGeoGridSource extends AbstractESAggSource {
export class ESGeoGridSource extends AbstractESAggSource implements ITiledSingleLayerVectorSource {
static createDescriptor({
indexPatternId,
geoField,
Expand All @@ -18,7 +23,26 @@ export class ESGeoGridSource extends AbstractESAggSource {

constructor(sourceDescriptor: ESGeoGridSourceDescriptor, inspectorAdapters: unknown);

private readonly _descriptor: ESGeoGridSourceDescriptor;

getFieldNames(): string[];
getGridResolution(): GRID_RESOLUTION;
getGeoGridPrecision(zoom: number): number;

getLayerName(): string;

getUrlTemplateWithMeta(
searchFilters: MapFilters & {
applyGlobalQuery: boolean;
fieldNames: string[];
geogridPrecision?: number;
sourceQuery: MapQuery;
sourceMeta: VectorSourceSyncMeta;
}
): Promise<{
layerName: string;
urlTemplate: string;
minSourceZoom: number;
maxSourceZoom: number;
}>;
}
Loading