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] Fix icon palettes are not working #69937

Merged
merged 3 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,15 @@ export enum LAYER_WIZARD_CATEGORY {
REFERENCE = 'REFERENCE',
SOLUTIONS = 'SOLUTIONS',
}

export enum VECTOR_SHAPE_TYPE {
POINT = 'POINT',
LINE = 'LINE',
POLYGON = 'POLYGON',
}

// https://docs.mapbox.com/mapbox-gl-js/style-spec/expressions/#data-expressions
export enum MB_LOOKUP_FUNCTION {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider exporting as string constant 'get' | 'feature-state'.

If this is an enumeration, I feel like we should use it consistently:

  • in the match and to-string expressions of dynamic_*_property.
  • in the geometry-type in mb_filter_expression.

GET = 'get',
FEATURE_STATE = 'feature-state',
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { Adapters } from 'src/plugins/inspector/public';
import { FileLayer } from '@elastic/ems-client';
import { Attribution, ImmutableSourceProperty, SourceEditorArgs } from '../source';
import { AbstractVectorSource, GeoJsonWithMeta, IVectorSource } from '../vector_source';
import { VECTOR_SHAPE_TYPES } from '../vector_feature_types';
import { SOURCE_TYPES, FIELD_ORIGIN } from '../../../../common/constants';
import { SOURCE_TYPES, FIELD_ORIGIN, VECTOR_SHAPE_TYPE } from '../../../../common/constants';
import { getEmsFileLayers } from '../../../meta';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
import { UpdateSourceEditor } from './update_source_editor';
Expand Down Expand Up @@ -179,8 +178,8 @@ export class EMSFileSource extends AbstractVectorSource implements IEmsFileSourc
return Promise.all(promises);
}

async getSupportedShapeTypes(): Promise<VECTOR_SHAPE_TYPES[]> {
return [VECTOR_SHAPE_TYPES.POLYGON];
async getSupportedShapeTypes(): Promise<VECTOR_SHAPE_TYPE[]> {
return [VECTOR_SHAPE_TYPE.POLYGON];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import React from 'react';
import uuid from 'uuid/v4';

import { VECTOR_SHAPE_TYPES } from '../vector_feature_types';
import { convertCompositeRespToGeoJson, convertRegularRespToGeoJson } from './convert_to_geojson';
import { UpdateSourceEditor } from './update_source_editor';
import {
SOURCE_TYPES,
DEFAULT_MAX_BUCKETS_LIMIT,
RENDER_AS,
GRID_RESOLUTION,
VECTOR_SHAPE_TYPE,
} from '../../../../common/constants';
import { i18n } from '@kbn/i18n';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
Expand Down Expand Up @@ -326,10 +326,10 @@ export class ESGeoGridSource extends AbstractESAggSource {

async getSupportedShapeTypes() {
if (this._descriptor.requestType === RENDER_AS.GRID) {
return [VECTOR_SHAPE_TYPES.POLYGON];
return [VECTOR_SHAPE_TYPE.POLYGON];
}

return [VECTOR_SHAPE_TYPES.POINT];
return [VECTOR_SHAPE_TYPE.POINT];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import React from 'react';
import uuid from 'uuid/v4';

import { VECTOR_SHAPE_TYPES } from '../vector_feature_types';
import { UpdateSourceEditor } from './update_source_editor';
import { i18n } from '@kbn/i18n';
import { SOURCE_TYPES } from '../../../../common/constants';
import { SOURCE_TYPES, VECTOR_SHAPE_TYPE } from '../../../../common/constants';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
import { convertToLines } from './convert_to_lines';
import { AbstractESAggSource } from '../es_agg_source';
Expand Down Expand Up @@ -61,7 +60,7 @@ export class ESPewPewSource extends AbstractESAggSource {
}

async getSupportedShapeTypes() {
return [VECTOR_SHAPE_TYPES.LINE];
return [VECTOR_SHAPE_TYPE.LINE];
}

async getImmutableProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import _ from 'lodash';
import React from 'react';

import { VECTOR_SHAPE_TYPES } from '../vector_feature_types';
import { AbstractESSource } from '../es_source';
import { getSearchService } from '../../../kibana_services';
import { hitsToGeoJson } from '../../../elasticsearch_geo_utils';
Expand All @@ -18,6 +17,7 @@ import {
DEFAULT_MAX_BUCKETS_LIMIT,
SORT_ORDER,
SCALING_TYPES,
VECTOR_SHAPE_TYPE,
} from '../../../../common/constants';
import { i18n } from '@kbn/i18n';
import { getDataSourceLabel } from '../../../../common/i18n_getters';
Expand Down Expand Up @@ -471,10 +471,10 @@ export class ESSearchSource extends AbstractESSource {
}

if (geoFieldType === ES_GEO_FIELD_TYPE.GEO_POINT) {
return [VECTOR_SHAPE_TYPES.POINT];
return [VECTOR_SHAPE_TYPE.POINT];
}

return [VECTOR_SHAPE_TYPES.POINT, VECTOR_SHAPE_TYPES.LINE, VECTOR_SHAPE_TYPES.POLYGON];
return [VECTOR_SHAPE_TYPE.POINT, VECTOR_SHAPE_TYPE.LINE, VECTOR_SHAPE_TYPE.POLYGON];
}

getSourceTooltipContent(sourceDataRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { i18n } from '@kbn/i18n';
import uuid from 'uuid/v4';
import { AbstractSource, ImmutableSourceProperty } from '../source';
import { BoundsFilters, GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source';
import { MAX_ZOOM, MIN_ZOOM, SOURCE_TYPES } from '../../../../common/constants';
import { VECTOR_SHAPE_TYPES } from '../vector_feature_types';
import { MAX_ZOOM, MIN_ZOOM, SOURCE_TYPES, VECTOR_SHAPE_TYPE } from '../../../../common/constants';
import { IField } from '../../fields/field';
import { registerSource } from '../source_registry';
import { getDataSourceLabel, getUrlLabel } from '../../../../common/i18n_getters';
Expand Down Expand Up @@ -116,8 +115,8 @@ export class MVTSingleLayerVectorSource extends AbstractSource
};
}

async getSupportedShapeTypes(): Promise<VECTOR_SHAPE_TYPES[]> {
return [VECTOR_SHAPE_TYPES.POINT, VECTOR_SHAPE_TYPES.LINE, VECTOR_SHAPE_TYPES.POLYGON];
async getSupportedShapeTypes(): Promise<VECTOR_SHAPE_TYPE[]> {
return [VECTOR_SHAPE_TYPE.POINT, VECTOR_SHAPE_TYPE.LINE, VECTOR_SHAPE_TYPE.POLYGON];
}

canFormatFeatureProperties() {
Expand Down
11 changes: 0 additions & 11 deletions x-pack/plugins/maps/public/classes/sources/vector_feature_types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
VectorSourceRequestMeta,
VectorSourceSyncMeta,
} from '../../../../common/descriptor_types';
import { VECTOR_SHAPE_TYPES } from '../vector_feature_types';
import { VECTOR_SHAPE_TYPE } from '../../../../common/constants';
import { ITooltipProperty } from '../../tooltips/tooltip_property';

export type GeoJsonFetchMeta = ESSearchSourceResponseMeta;
Expand Down Expand Up @@ -68,7 +68,7 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc
getFields(): Promise<IField[]>;
getFieldByName(fieldName: string): IField | null;
getSyncMeta(): VectorSourceSyncMeta;
getSupportedShapeTypes(): Promise<VECTOR_SHAPE_TYPES[]>;
getSupportedShapeTypes(): Promise<VECTOR_SHAPE_TYPE[]>;
canFormatFeatureProperties(): boolean;
getApplyGlobalQuery(): boolean;
getFieldNames(): string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AbstractSource } from './../source';
import * as topojson from 'topojson-client';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { VECTOR_SHAPE_TYPES } from './../vector_feature_types';
import { VECTOR_SHAPE_TYPE } from '../../../../common/constants';

export class AbstractVectorSource extends AbstractSource {
static async getGeoJson({ format, featureCollectionPath, fetchUrl }) {
Expand Down Expand Up @@ -127,7 +127,7 @@ export class AbstractVectorSource extends AbstractSource {
}

async getSupportedShapeTypes() {
return [VECTOR_SHAPE_TYPES.POINT, VECTOR_SHAPE_TYPES.LINE, VECTOR_SHAPE_TYPES.POLYGON];
return [VECTOR_SHAPE_TYPE.POINT, VECTOR_SHAPE_TYPE.LINE, VECTOR_SHAPE_TYPE.POLYGON];
}

getSourceTooltipContent(/* sourceDataRequest */) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { VectorStyleLabelBorderSizeEditor } from './label/vector_style_label_bor
import { OrientationEditor } from './orientation/orientation_editor';
import { getDefaultDynamicProperties, getDefaultStaticProperties } from '../vector_style_defaults';
import { DEFAULT_FILL_COLORS, DEFAULT_LINE_COLORS } from '../../color_utils';
import { VECTOR_SHAPE_TYPES } from '../../../sources/vector_feature_types';
import { i18n } from '@kbn/i18n';

import { EuiSpacer, EuiButtonGroup, EuiFormRow, EuiSwitch } from '@elastic/eui';
Expand All @@ -26,6 +25,7 @@ import {
LABEL_BORDER_SIZES,
VECTOR_STYLES,
STYLE_TYPE,
VECTOR_SHAPE_TYPE,
} from '../../../../../common/constants';

export class VectorStyleEditor extends Component {
Expand Down Expand Up @@ -96,11 +96,11 @@ export class VectorStyleEditor extends Component {
}

if (this.state.selectedFeature === null) {
let selectedFeature = VECTOR_SHAPE_TYPES.POLYGON;
let selectedFeature = VECTOR_SHAPE_TYPE.POLYGON;
if (this.props.isPointsOnly) {
selectedFeature = VECTOR_SHAPE_TYPES.POINT;
selectedFeature = VECTOR_SHAPE_TYPE.POINT;
} else if (this.props.isLinesOnly) {
selectedFeature = VECTOR_SHAPE_TYPES.LINE;
selectedFeature = VECTOR_SHAPE_TYPE.LINE;
}
this.setState({
selectedFeature: selectedFeature,
Expand Down Expand Up @@ -414,40 +414,40 @@ export class VectorStyleEditor extends Component {

if (supportedFeatures.length === 1) {
switch (supportedFeatures[0]) {
case VECTOR_SHAPE_TYPES.POINT:
case VECTOR_SHAPE_TYPE.POINT:
return this._renderPointProperties();
case VECTOR_SHAPE_TYPES.LINE:
case VECTOR_SHAPE_TYPE.LINE:
return this._renderLineProperties();
case VECTOR_SHAPE_TYPES.POLYGON:
case VECTOR_SHAPE_TYPE.POLYGON:
return this._renderPolygonProperties();
}
}

const featureButtons = [
{
id: VECTOR_SHAPE_TYPES.POINT,
id: VECTOR_SHAPE_TYPE.POINT,
label: i18n.translate('xpack.maps.vectorStyleEditor.pointLabel', {
defaultMessage: 'Points',
}),
},
{
id: VECTOR_SHAPE_TYPES.LINE,
id: VECTOR_SHAPE_TYPE.LINE,
label: i18n.translate('xpack.maps.vectorStyleEditor.lineLabel', {
defaultMessage: 'Lines',
}),
},
{
id: VECTOR_SHAPE_TYPES.POLYGON,
id: VECTOR_SHAPE_TYPE.POLYGON,
label: i18n.translate('xpack.maps.vectorStyleEditor.polygonLabel', {
defaultMessage: 'Polygons',
}),
},
];

let styleProperties = this._renderPolygonProperties();
if (selectedFeature === VECTOR_SHAPE_TYPES.LINE) {
if (selectedFeature === VECTOR_SHAPE_TYPE.LINE) {
styleProperties = this._renderLineProperties();
} else if (selectedFeature === VECTOR_SHAPE_TYPES.POINT) {
} else if (selectedFeature === VECTOR_SHAPE_TYPE.POINT) {
styleProperties = this._renderPointProperties();
}

Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
GRADIENT_INTERVALS,
} from '../../color_utils';
import React from 'react';
import { COLOR_MAP_TYPE } from '../../../../../common/constants';
import { COLOR_MAP_TYPE, MB_LOOKUP_FUNCTION } from '../../../../../common/constants';
import {
isCategoricalStopsInvalid,
getOtherCategoryLabel,
Expand Down Expand Up @@ -152,7 +152,7 @@ export class DynamicColorProperty extends DynamicStyleProperty {
makeMbClampedNumberExpression({
minValue: rangeFieldMeta.min,
maxValue: rangeFieldMeta.max,
lookupFunction: 'feature-state',
lookupFunction: MB_LOOKUP_FUNCTION.FEATURE_STATE,
fallback: lessThanFirstStopValue,
fieldName: targetName,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class DynamicIconProperty extends DynamicStyleProperty {

getNumberOfCategories() {
const palette = getIconPalette(this._options.iconPaletteId);
return palette ? palette.length : 0;
return palette.length;
}

syncIconWithMb(symbolLayerId, mbMap, iconPixelSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const makeProperty = (options: Partial<IconDynamicOptions>, field: IField = mock
);
};

describe('DynamicIconProperty', () => {
it('should derive category number from palettes', async () => {
describe('getNumberOfCategories', () => {
test('should derive category number from palettes', async () => {
const filled = makeProperty({
iconPaletteId: 'filledShapes',
});
Expand All @@ -47,15 +47,53 @@ describe('DynamicIconProperty', () => {
});
});

test('Should render categorical legend with breaks', async () => {
const iconStyle = makeProperty({
iconPaletteId: 'filledShapes',
describe('renderLegendDetailRow', () => {
test('Should render categorical legend with breaks', async () => {
const iconStyle = makeProperty({
iconPaletteId: 'filledShapes',
});

const legendRow = iconStyle.renderLegendDetailRow({ isPointsOnly: true, isLinesOnly: false });
const component = shallow(legendRow);
await new Promise((resolve) => process.nextTick(resolve));
component.update();

expect(component).toMatchSnapshot();
});
});

const legendRow = iconStyle.renderLegendDetailRow({ isPointsOnly: true, isLinesOnly: false });
const component = shallow(legendRow);
await new Promise((resolve) => process.nextTick(resolve));
component.update();
describe('get mapbox icon-image expression (via internal _getMbIconImageExpression)', () => {
describe('categorical icon palette', () => {
test('should return mapbox expression for pre-defined icon palette', async () => {
const iconStyle = makeProperty({
iconPaletteId: 'filledShapes',
});
expect(iconStyle._getMbIconImageExpression(15)).toEqual([
'match',
['to-string', ['get', 'foobar']],
'US',
'circle-15',
'CN',
'marker-15',
'square-15',
]);
});

expect(component).toMatchSnapshot();
test('should return mapbox expression for custom icon palette', async () => {
const iconStyle = makeProperty({
useCustomIconMap: true,
customIconStops: [
{ stop: null, icon: 'circle' },
{ stop: 'MX', icon: 'marker' },
],
});
expect(iconStyle._getMbIconImageExpression(15)).toEqual([
'match',
['to-string', ['get', 'foobar']],
'MX',
'marker-15',
'circle-15',
]);
});
});
});
Loading