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 TileJson support #70147

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 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
514f453
tilejson poc
thomasneirynck Jun 27, 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 @@ -67,6 +67,7 @@ export enum SOURCE_TYPES {
REGIONMAP_FILE = 'REGIONMAP_FILE',
GEOJSON_FILE = 'GEOJSON_FILE',
MVT_SINGLE_LAYER = 'MVT_SINGLE_LAYER',
TILEJSON_SINGLE_LAYER = 'TILEJSON_SINGLE_LAYER',
}

export enum FIELD_ORIGIN {
Expand Down Expand Up @@ -222,6 +223,11 @@ export enum SCALING_TYPES {

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

export enum MVTFieldType {
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 @@ -6,7 +6,14 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions */

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,
MVTFieldType,
} from '../constants';
import { StyleDescriptor, VectorStyleDescriptor } from './style_property_descriptor_types';
import { DataRequestDescriptor } from './data_request_descriptor_types';

Expand Down Expand Up @@ -95,18 +102,43 @@ export type XYZTMSSourceDescriptor = AbstractSourceDescriptor &
urlTemplate: string;
};

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

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 TileJsonVectorSourceSettings = {
url: string;
layerName: string;
};
export type TileJsonVectorSourceDescriptor = AbstractSourceDescriptor &
TileJsonVectorSourceSettings & {
tooltipProperties: string[];
};

export type JoinDescriptor = {
leftField: string;
right: ESTermSourceDescriptor;
Expand All @@ -126,6 +158,7 @@ export type SourceDescriptor =
| EMSFileSourceDescriptor
| ESPewPewSourceDescriptor
| TiledSingleLayerVectorSourceDescriptor
| TileJsonVectorSourceDescriptor
| EMSTMSSourceDescriptor
| EMSFileSourceDescriptor;

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, MVTFieldType } 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: MVTFieldType;
constructor({
fieldName,
type,
source,
origin,
}: {
fieldName: string;
source: ITiledSingleLayerVectorSource;
origin: FIELD_ORIGIN;
type: MVTFieldType;
}) {
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 === MVTFieldType.STRING) {
return 'string';
} else if (this._type === MVTFieldType.NUMBER) {
return 'number';
} else {
throw new Error(`Unrecognized MVT field-type ${this._type}`);
}
}

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

supportsAutoDomain() {
return false;
}
}
54 changes: 54 additions & 0 deletions x-pack/plugins/maps/public/classes/fields/tilejson_field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 } from '../../../common/constants';
import { IVectorSource } from '../sources/vector_source';
import { TileJsonSource } from '../sources/tilejson_source/tilejson_source';

export class TileJsonField extends AbstractField implements IField {
private readonly _source: TileJsonSource;
constructor({
fieldName,
source,
origin,
}: {
fieldName: string;
source: TileJsonSource;
origin: FIELD_ORIGIN;
}) {
super({ fieldName, origin });
this._source = source;
}

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

async getDataType(): Promise<string> {
const layerConfig = await this._source.getLayerConfig();

const type = layerConfig.fields[this.getName()];

if (type === 'String') {
return 'string';
} else if (type === 'Number') {
return 'number';
}

console.warn('unknwonf ield type');
return 'string';

}

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 @@ -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 @@ -27,6 +27,7 @@ import { mvtVectorSourceWizardConfig } from '../sources/mvt_single_layer_vector_
import { ObservabilityLayerWizardConfig } from './solution_layers/observability';
import { SecurityLayerWizardConfig } from './solution_layers/security';
import { getEnableVectorTiles } from '../../kibana_services';
import {tileJsonLayerWizardConfig} from "../sources/tilejson_source/tilejson_layer_wizard";

let registered = false;
export function registerLayerWizards() {
Expand Down Expand Up @@ -62,6 +63,7 @@ export function registerLayerWizards() {
// eslint-disable-next-line no-console
console.warn('Vector tiles are an experimental feature and should not be used in production.');
registerLayerWizard(mvtVectorSourceWizardConfig);
registerLayerWizard(tileJsonLayerWizardConfig);
}
registered = true;
}
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