Skip to content

Commit

Permalink
[Maps] Fix icon palettes are not working
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Jun 24, 2020
1 parent 14f975c commit 1577507
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 100 deletions.
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 {
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
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 @@ -12,7 +12,7 @@ import {
LARGE_MAKI_ICON_SIZE,
SMALL_MAKI_ICON_SIZE,
} from '../symbol_utils';
import { VECTOR_STYLES } from '../../../../../common/constants';
import { MB_LOOKUP_FUNCTION, VECTOR_STYLES } from '../../../../../common/constants';
import _ from 'lodash';
import React from 'react';

Expand Down Expand Up @@ -60,7 +60,7 @@ export class DynamicSizeProperty extends DynamicStyleProperty {
minValue: rangeFieldMeta.min,
maxValue: rangeFieldMeta.max,
fallback: 0,
lookupFunction: 'get',
lookupFunction: MB_LOOKUP_FUNCTION.GET,
fieldName: targetName,
}),
rangeFieldMeta.min,
Expand Down Expand Up @@ -109,7 +109,9 @@ export class DynamicSizeProperty extends DynamicStyleProperty {
}

_getMbDataDrivenSize({ targetName, minSize, maxSize, minValue, maxValue }) {
const lookup = this.supportsMbFeatureState() ? 'feature-state' : 'get';
const lookup = this.supportsMbFeatureState()
? MB_LOOKUP_FUNCTION.FEATURE_STATE
: MB_LOOKUP_FUNCTION.GET;

const stops =
minValue === maxValue ? [maxValue, maxSize] : [minValue, minSize, maxValue, maxSize];
Expand Down
Loading

0 comments on commit 1577507

Please sign in to comment.