Skip to content

Commit

Permalink
[Maps] create MVT_VECTOR when using choropleth wizard (#132648)
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese authored May 20, 2022
1 parent 46cd729 commit e55bf40
Showing 1 changed file with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
AGG_TYPE,
COLOR_MAP_TYPE,
FIELD_ORIGIN,
LAYER_TYPE,
SCALING_TYPES,
SOURCE_TYPES,
STYLE_TYPE,
Expand All @@ -21,10 +22,11 @@ import {
CountAggDescriptor,
EMSFileSourceDescriptor,
ESSearchSourceDescriptor,
JoinDescriptor,
VectorStylePropertiesDescriptor,
} from '../../../../../common/descriptor_types';
import { VectorStyle } from '../../../styles/vector/vector_style';
import { GeoJsonVectorLayer } from '../../vector_layer';
import { GeoJsonVectorLayer, MvtVectorLayer } from '../../vector_layer';
import { EMSFileSource } from '../../../sources/ems_file_source';
// @ts-ignore
import { ESSearchSource } from '../../../sources/es_search_source';
Expand All @@ -38,14 +40,14 @@ function createChoroplethLayerDescriptor({
rightIndexPatternId,
rightIndexPatternTitle,
rightTermField,
setLabelStyle,
layerType,
}: {
sourceDescriptor: EMSFileSourceDescriptor | ESSearchSourceDescriptor;
leftField: string;
rightIndexPatternId: string;
rightIndexPatternTitle: string;
rightTermField: string;
setLabelStyle: boolean;
layerType: LAYER_TYPE.GEOJSON_VECTOR | LAYER_TYPE.MVT_VECTOR;
}) {
const metricsDescriptor: CountAggDescriptor = { type: AGG_TYPE.COUNT };
const joinId = uuid();
Expand Down Expand Up @@ -75,7 +77,8 @@ function createChoroplethLayerDescriptor({
},
},
};
if (setLabelStyle) {
// Styling label by join metric with MVT is not supported
if (layerType === LAYER_TYPE.GEOJSON_VECTOR) {
styleProperties[VECTOR_STYLES.LABEL_TEXT] = {
type: STYLE_TYPE.DYNAMIC,
options: {
Expand All @@ -88,26 +91,34 @@ function createChoroplethLayerDescriptor({
};
}

return GeoJsonVectorLayer.createDescriptor({
joins: [
{
leftField,
right: {
type: SOURCE_TYPES.ES_TERM_SOURCE,
id: joinId,
indexPatternId: rightIndexPatternId,
indexPatternTitle: rightIndexPatternTitle,
term: rightTermField,
metrics: [metricsDescriptor],
applyGlobalQuery: true,
applyGlobalTime: true,
applyForceRefresh: true,
},
const joins = [
{
leftField,
right: {
type: SOURCE_TYPES.ES_TERM_SOURCE,
id: joinId,
indexPatternId: rightIndexPatternId,
indexPatternTitle: rightIndexPatternTitle,
term: rightTermField,
metrics: [metricsDescriptor],
applyGlobalQuery: true,
applyGlobalTime: true,
applyForceRefresh: true,
},
],
sourceDescriptor,
style: VectorStyle.createDescriptor(styleProperties),
});
} as JoinDescriptor,
];

return layerType === LAYER_TYPE.MVT_VECTOR
? MvtVectorLayer.createDescriptor({
joins,
sourceDescriptor,
style: VectorStyle.createDescriptor(styleProperties),
})
: GeoJsonVectorLayer.createDescriptor({
joins,
sourceDescriptor,
style: VectorStyle.createDescriptor(styleProperties),
});
}

export function createEmsChoroplethLayerDescriptor({
Expand All @@ -132,7 +143,7 @@ export function createEmsChoroplethLayerDescriptor({
rightIndexPatternId,
rightIndexPatternTitle,
rightTermField,
setLabelStyle: true,
layerType: LAYER_TYPE.GEOJSON_VECTOR,
});
}

Expand Down Expand Up @@ -165,6 +176,6 @@ export function createEsChoroplethLayerDescriptor({
rightIndexPatternId,
rightIndexPatternTitle,
rightTermField,
setLabelStyle: false, // Styling label by join metric with MVT is not supported
layerType: LAYER_TYPE.MVT_VECTOR,
});
}

0 comments on commit e55bf40

Please sign in to comment.