Skip to content

Commit

Permalink
[Maps] Enable geo-point for mvt scaling type (#79733) (#79771)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck authored Oct 6, 2020
1 parent 2f0c8c6 commit 9622102
Show file tree
Hide file tree
Showing 14 changed files with 15 additions and 138 deletions.

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

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 @@ -19,8 +19,6 @@ import {
getTermsFields,
getGeoTileAggNotSupportedReason,
supportsGeoTileAgg,
supportsMvt,
getMvtDisabledReason,
} from '../../../index_pattern_util';

function doesGeoFieldSupportGeoTileAgg(indexPattern, geoFieldName) {
Expand Down Expand Up @@ -149,7 +147,6 @@ export class CreateSourceEditor extends Component {
return null;
}

const mvtSupported = supportsMvt(this.state.indexPattern, this.state.geoFieldName);
return (
<Fragment>
<EuiSpacer size="m" />
Expand All @@ -162,8 +159,6 @@ export class CreateSourceEditor extends Component {
this.state.indexPattern,
this.state.geoFieldName
)}
supportsMvt={mvtSupported}
mvtDisabledReason={mvtSupported ? null : getMvtDisabledReason()}
clusteringDisabledReason={
this.state.indexPattern
? getGeoTileAggNotSupportedReason(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,9 @@ export class ESSearchSource extends AbstractESSource {
`/${GIS_API_PATH}/${MVT_GETTILE_API_PATH}`
);

const urlTemplate = `${mvtUrlServicePath}?x={x}&y={y}&z={z}&geometryFieldName=${this._descriptor.geoField}&index=${indexPattern.title}&requestBody=${risonDsl}`;
const geoField = await this._getGeoField();

const urlTemplate = `${mvtUrlServicePath}?x={x}&y={y}&z={z}&geometryFieldName=${this._descriptor.geoField}&index=${indexPattern.title}&requestBody=${risonDsl}&geoFieldType=${geoField.type}`;
return {
layerName: this.getLayerName(),
minSourceZoom: this.getMinZoom(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('ESSearchSource', () => {
);
const urlTemplateWithMeta = await esSearchSource.getUrlTemplateWithMeta(searchFilters);
expect(urlTemplateWithMeta.urlTemplate).toBe(
`rootdir/api/maps/mvt/getTile;?x={x}&y={y}&z={z}&geometryFieldName=bar&index=foobar-title-*&requestBody=(foobar:ES_DSL_PLACEHOLDER,params:('0':('0':index,'1':(fields:(),title:'foobar-title-*')),'1':('0':size,'1':1000),'2':('0':filter,'1':!()),'3':('0':query),'4':('0':index,'1':(fields:(),title:'foobar-title-*')),'5':('0':query,'1':(language:KQL,query:'tooltipField: foobar',queryLastTriggeredAt:'2019-04-25T20:53:22.331Z')),'6':('0':fields,'1':!(tooltipField,styleField)),'7':('0':source,'1':!(tooltipField,styleField))))`
`rootdir/api/maps/mvt/getTile;?x={x}&y={y}&z={z}&geometryFieldName=bar&index=foobar-title-*&requestBody=(foobar:ES_DSL_PLACEHOLDER,params:('0':('0':index,'1':(fields:(),title:'foobar-title-*')),'1':('0':size,'1':1000),'2':('0':filter,'1':!()),'3':('0':query),'4':('0':index,'1':(fields:(),title:'foobar-title-*')),'5':('0':query,'1':(language:KQL,query:'tooltipField: foobar',queryLastTriggeredAt:'2019-04-25T20:53:22.331Z')),'6':('0':fields,'1':!(tooltipField,styleField)),'7':('0':source,'1':!(tooltipField,styleField))))&geoFieldType=geo_shape`
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const defaultProps = {
termFields: [],
topHitsSplitField: null,
topHitsSize: 1,
supportsMvt: true,
mvtDisabledReason: null,
};

describe('scaling form', () => {
Expand Down Expand Up @@ -57,16 +55,4 @@ describe('scaling form', () => {

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

test('should disable mvt option when mvt is not supported', async () => {
const component = shallow(
<ScalingForm
{...defaultProps}
supportsMvt={false}
mvtDisabledReason={'Simulated mvt disabled'}
/>
);

expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ interface Props {
onChange: (args: OnSourceChangeArgs) => void;
scalingType: SCALING_TYPES;
supportsClustering: boolean;
supportsMvt: boolean;
clusteringDisabledReason?: string | null;
mvtDisabledReason?: string | null;
termFields: IFieldType[];
topHitsSplitField: string | null;
topHitsSize: number;
Expand Down Expand Up @@ -197,7 +195,6 @@ export class ScalingForm extends Component<Props, State> {
label={labelText}
checked={this.props.scalingType === SCALING_TYPES.MVT}
onChange={() => this._onScalingTypeChange(SCALING_TYPES.MVT)}
disabled={!this.props.supportsMvt}
/>
);

Expand All @@ -211,11 +208,7 @@ export class ScalingForm extends Component<Props, State> {
</>
);

return !this.props.supportsMvt ? (
<EuiToolTip position="left" content={this.props.mvtDisabledReason}>
{mvtRadio}
</EuiToolTip>
) : (
return (
<EuiToolTip position="left" content={enabledInfo}>
{mvtRadio}
</EuiToolTip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
getTermsFields,
getSourceFields,
supportsGeoTileAgg,
supportsMvt,
getMvtDisabledReason,
} from '../../../index_pattern_util';
import { SORT_ORDER } from '../../../../common/constants';
import { ESDocField } from '../../fields/es_doc_field';
Expand All @@ -44,7 +42,6 @@ export class UpdateSourceEditor extends Component {
termFields: null,
sortFields: null,
supportsClustering: false,
supportsMvt: false,
mvtDisabledReason: null,
clusteringDisabledReason: null,
};
Expand Down Expand Up @@ -99,12 +96,10 @@ export class UpdateSourceEditor extends Component {
});
});

const mvtSupported = supportsMvt(indexPattern, geoField.name);
this.setState({
supportsClustering: supportsGeoTileAgg(geoField),
supportsMvt: mvtSupported,
clusteringDisabledReason: getGeoTileAggNotSupportedReason(geoField),
mvtDisabledReason: mvtSupported ? null : getMvtDisabledReason(),
mvtDisabledReason: null,
sourceFields: sourceFields,
termFields: getTermsFields(indexPattern.fields), //todo change term fields to use fields
sortFields: indexPattern.fields.filter(
Expand Down Expand Up @@ -215,9 +210,7 @@ export class UpdateSourceEditor extends Component {
onChange={this.props.onChange}
scalingType={this.props.scalingType}
supportsClustering={this.state.supportsClustering}
supportsMvt={this.state.supportsMvt}
clusteringDisabledReason={this.state.clusteringDisabledReason}
mvtDisabledReason={this.state.mvtDisabledReason}
termFields={this.state.termFields}
topHitsSplitField={this.props.topHitsSplitField}
topHitsSize={this.props.topHitsSize}
Expand Down
11 changes: 0 additions & 11 deletions x-pack/plugins/maps/public/index_pattern_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ export function supportsGeoTileAgg(field?: IFieldType): boolean {
);
}

export function supportsMvt(indexPattern: IndexPattern, geoFieldName: string): boolean {
const field = indexPattern.fields.getByName(geoFieldName);
return !!field && field.type === ES_GEO_FIELD_TYPE.GEO_SHAPE;
}

export function getMvtDisabledReason() {
return i18n.translate('xpack.maps.mbt.disabled', {
defaultMessage: 'Display as vector tiles is only supported for geo_shape field-types.',
});
}
// Returns filtered fields list containing only fields that exist in _source.
export function getSourceFields(fields: IFieldType[]): IFieldType[] {
return fields.filter((field) => {
// Multi fields are not stored in _source and only exist in index.
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/maps/server/mvt/get_tile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('getTile', () => {
info: () => {},
} as unknown) as Logger,
callElasticsearch: mockCallElasticsearch,
geoFieldType: ES_GEO_FIELD_TYPE.GEO_SHAPE,
});

compareTiles('./__tests__/pbf/0_0_0_docs.pbf', tile);
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/maps/server/mvt/get_tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import {
SUPER_FINE_ZOOM_DELTA,
} from '../../common/constants';

import { hitsToGeoJson } from '../../common/elasticsearch_util';
import { convertRegularRespToGeoJson, hitsToGeoJson } from '../../common/elasticsearch_util';
import { flattenHit } from './util';
import { convertRegularRespToGeoJson } from '../../common/elasticsearch_util';
import { ESBounds, tile2lat, tile2long, tileToESBbox } from '../../common/geo_tile_utils';

export async function getGridTile({
Expand Down Expand Up @@ -107,6 +106,7 @@ export async function getTile({
y,
z,
requestBody = {},
geoFieldType,
}: {
x: number;
y: number;
Expand All @@ -116,6 +116,7 @@ export async function getTile({
callElasticsearch: (type: string, ...args: any[]) => Promise<unknown>;
logger: Logger;
requestBody: any;
geoFieldType: ES_GEO_FIELD_TYPE;
}): Promise<Buffer | null> {
const geojsonBbox = tileToGeoJsonPolygon(x, y, z);

Expand Down Expand Up @@ -181,7 +182,6 @@ export async function getTile({
},
];
} else {
// Perform actual search
result = await callElasticsearch('search', esSearchQuery);

// Todo: pass in epochMillies-fields
Expand All @@ -192,7 +192,7 @@ export async function getTile({
return flattenHit(geometryFieldName, hit);
},
geometryFieldName,
ES_GEO_FIELD_TYPE.GEO_SHAPE,
geoFieldType,
[]
);

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/maps/server/mvt/mvt_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function initMVTRoutes({ router, logger }: { logger: Logger; router: IRou
geometryFieldName: schema.string(),
requestBody: schema.string(),
index: schema.string(),
geoFieldType: schema.string(),
}),
},
},
Expand All @@ -56,6 +57,7 @@ export function initMVTRoutes({ router, logger }: { logger: Logger; router: IRou
z: query.z as number,
index: query.index as string,
requestBody: requestBodyDSL as any,
geoFieldType: query.geoFieldType as ES_GEO_FIELD_TYPE,
});

return sendResponse(response, tile);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/api_integration/apis/maps/get_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function ({ getService }) {
it('should validate params', async () => {
await supertest
.get(
`/api/maps/mvt/getTile?x=15&y=11&z=5&geometryFieldName=coordinates&index=logstash*&requestBody=(_source:(includes:!(coordinates)),docvalue_fields:!(),query:(bool:(filter:!((match_all:())),must:!(),must_not:!(),should:!())),script_fields:(),size:10000,stored_fields:!(coordinates))`
`/api/maps/mvt/getTile?x=15&y=11&z=5&geometryFieldName=coordinates&index=logstash*&requestBody=(_source:(includes:!(coordinates)),docvalue_fields:!(),query:(bool:(filter:!((match_all:())),must:!(),must_not:!(),should:!())),script_fields:(),size:10000,stored_fields:!(coordinates))&geoFieldType=geo_point`
)
.set('kbn-xsrf', 'kibana')
.expect(200);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/maps/mvt_scaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function ({ getPageObjects, getService }) {

//Source should be correct
expect(mapboxStyle.sources[VECTOR_SOURCE_ID].tiles[0]).to.equal(
'/api/maps/mvt/getTile?x={x}&y={y}&z={z}&geometryFieldName=geometry&index=geo_shapes*&requestBody=(_source:(includes:!(geometry,prop1)),docvalue_fields:!(prop1),query:(bool:(filter:!((match_all:())),must:!(),must_not:!(),should:!())),script_fields:(),size:10000,stored_fields:!(geometry,prop1))'
'/api/maps/mvt/getTile?x={x}&y={y}&z={z}&geometryFieldName=geometry&index=geo_shapes*&requestBody=(_source:(includes:!(geometry,prop1)),docvalue_fields:!(prop1),query:(bool:(filter:!((match_all:())),must:!(),must_not:!(),should:!())),script_fields:(),size:10000,stored_fields:!(geometry,prop1))&geoFieldType=geo_shape'
);

//Should correctly load meta for style-rule (sigma is set to 1, opacity to 1)
Expand Down

0 comments on commit 9622102

Please sign in to comment.