[Maps][File upload] Set geojson indexed layer defaults for bounds and global (#41789) (#42533)

* Set 'map bounds' and 'global query' default to 'false' for indexed geojson layers

* Add constants file

* Clean up

* Dynamically determine whether or not to filter by map bounds based upon docCount

# Conflicts:
#	x-pack/legacy/plugins/maps/public/layers/sources/client_file_source/geojson_file_source.js
#	x-pack/legacy/plugins/maps/public/reducers/map.js
This commit is contained in:
Aaron Caldwell 2019-08-02 11:02:46 -06:00 committed by GitHub
parent 990347912b
commit 562cd0af6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 10 deletions

View file

@ -47,19 +47,21 @@ export class AddLayerPanel extends Component {
return panelDescription;
}
_viewLayer = async source => {
_viewLayer = async (source, options = {}) => {
if (!source) {
this.setState({ layer: null });
this.props.removeTransientLayer();
return;
}
const layerOptions = this.state.layer
? { style: this.state.layer.getCurrentStyle().getDescriptor() }
: {};
const newLayer = source.createDefaultLayer(layerOptions, this.props.mapColors);
this.setState({ layer: newLayer }, () =>
this.props.viewLayer(this.state.layer));
const layerInitProps = {
...options,
...(this.state.layer && { style: this.state.layer.getCurrentStyle().getDescriptor() })
};
const newLayer = source.createDefaultLayer(layerInitProps, this.props.mapColors);
this.setState(
{ layer: newLayer },
() => this.props.viewLayer(this.state.layer)
);
};
_clearLayerData = ({ keepSourceType = false }) => {

View file

@ -0,0 +1,7 @@
/*
* 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.
*/
export const DEFAULT_APPLY_GLOBAL_QUERY = false;

View file

@ -6,11 +6,18 @@
import { AbstractVectorSource } from '../vector_source';
import React from 'react';
import { ES_GEO_FIELD_TYPE, GEOJSON_FILE } from '../../../../../common/constants';
import {
ES_GEO_FIELD_TYPE,
GEOJSON_FILE,
ES_SIZE_LIMIT
} from '../../../../../common/constants';
import { ClientFileCreateSourceEditor } from './create_client_file_source_editor';
import { ESSearchSource } from '../es_search_source';
import uuid from 'uuid/v4';
import _ from 'lodash';
import {
DEFAULT_APPLY_GLOBAL_QUERY
} from './constants';
export class GeojsonFileSource extends AbstractVectorSource {
@ -20,6 +27,9 @@ export class GeojsonFileSource extends AbstractVectorSource {
static icon = 'importAction';
static isIndexingSource = true;
static isBeta = true;
static layerDefaults = {
applyGlobalQuery: DEFAULT_APPLY_GLOBAL_QUERY
}
static createDescriptor(geoJson, name) {
// Wrap feature as feature collection if needed
@ -56,12 +66,15 @@ export class GeojsonFileSource extends AbstractVectorSource {
if (!indexPatternId || !geoField) {
addAndViewSource(null);
} else {
// Only turn on bounds filter for large doc counts
const filterByMapBounds = indexDataResp.docCount > ES_SIZE_LIMIT;
const source = new ESSearchSource({
id: uuid(),
indexPatternId,
geoField,
filterByMapBounds
}, inspectorAdapters);
addAndViewSource(source);
addAndViewSource(source, this.layerDefaults);
importSuccessHandler(indexResponses);
}
};