mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Maps] convert GeojsonFileSource to typescript (#70365)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
eafd2af6aa
commit
006670244a
11 changed files with 93 additions and 82 deletions
|
@ -4,6 +4,7 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { FeatureCollection } from 'geojson';
|
||||
export const EMS_APP_NAME = 'kibana';
|
||||
export const EMS_CATALOGUE_PATH = 'ems/catalogue';
|
||||
|
||||
|
@ -124,7 +125,7 @@ export const POLYGON_COORDINATES_EXTERIOR_INDEX = 0;
|
|||
export const LON_INDEX = 0;
|
||||
export const LAT_INDEX = 1;
|
||||
|
||||
export const EMPTY_FEATURE_COLLECTION = {
|
||||
export const EMPTY_FEATURE_COLLECTION: FeatureCollection = {
|
||||
type: 'FeatureCollection',
|
||||
features: [],
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
/* eslint-disable @typescript-eslint/consistent-type-definitions */
|
||||
|
||||
import { FeatureCollection } from 'geojson';
|
||||
import { Query } from 'src/plugins/data/public';
|
||||
import { AGG_TYPE, GRID_RESOLUTION, RENDER_AS, SORT_ORDER, SCALING_TYPES } from '../constants';
|
||||
import { StyleDescriptor, VectorStyleDescriptor } from './style_property_descriptor_types';
|
||||
|
@ -107,6 +108,12 @@ export type TiledSingleLayerVectorSourceDescriptor = AbstractSourceDescriptor &
|
|||
maxSourceZoom: number;
|
||||
};
|
||||
|
||||
export type GeojsonFileSourceDescriptor = {
|
||||
__featureCollection: FeatureCollection;
|
||||
name: string;
|
||||
type: string;
|
||||
};
|
||||
|
||||
export type JoinDescriptor = {
|
||||
leftField: string;
|
||||
right: ESTermSourceDescriptor;
|
||||
|
@ -127,7 +134,8 @@ export type SourceDescriptor =
|
|||
| ESPewPewSourceDescriptor
|
||||
| TiledSingleLayerVectorSourceDescriptor
|
||||
| EMSTMSSourceDescriptor
|
||||
| EMSFileSourceDescriptor;
|
||||
| EMSFileSourceDescriptor
|
||||
| GeojsonFileSourceDescriptor;
|
||||
|
||||
export type LayerDescriptor = {
|
||||
__dataRequests?: DataRequestDescriptor[];
|
||||
|
|
|
@ -7,11 +7,7 @@
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import React from 'react';
|
||||
import { LayerWizard, RenderWizardArguments } from '../../layers/layer_wizard_registry';
|
||||
import {
|
||||
ClientFileCreateSourceEditor,
|
||||
INDEX_SETUP_STEP_ID,
|
||||
INDEXING_STEP_ID,
|
||||
} from './create_client_file_source_editor';
|
||||
import { ClientFileCreateSourceEditor, INDEX_SETUP_STEP_ID, INDEXING_STEP_ID } from './wizard';
|
||||
|
||||
export const uploadLayerWizardConfig: LayerWizard = {
|
||||
categories: [],
|
|
@ -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 { uploadLayerWizardConfig } from './config';
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import { FeatureCollection } from 'geojson';
|
||||
import { EuiPanel } from '@elastic/eui';
|
||||
import { IFieldType } from 'src/plugins/data/public';
|
||||
import {
|
||||
|
@ -13,11 +14,10 @@ import {
|
|||
SCALING_TYPES,
|
||||
} from '../../../../common/constants';
|
||||
import { getFileUploadComponent } from '../../../kibana_services';
|
||||
// @ts-ignore
|
||||
import { GeojsonFileSource } from './geojson_file_source';
|
||||
import { GeojsonFileSource } from '../../sources/geojson_file_source';
|
||||
import { VectorLayer } from '../../layers/vector_layer/vector_layer';
|
||||
// @ts-ignore
|
||||
import { createDefaultLayerDescriptor } from '../es_search_source';
|
||||
import { createDefaultLayerDescriptor } from '../../sources/es_search_source';
|
||||
import { RenderWizardArguments } from '../../layers/layer_wizard_registry';
|
||||
|
||||
export const INDEX_SETUP_STEP_ID = 'INDEX_SETUP_STEP_ID';
|
||||
|
@ -59,7 +59,7 @@ export class ClientFileCreateSourceEditor extends Component<RenderWizardArgument
|
|||
}
|
||||
}
|
||||
|
||||
_onFileUpload = (geojsonFile: unknown, name: string) => {
|
||||
_onFileUpload = (geojsonFile: FeatureCollection, name: string) => {
|
||||
if (!this._isMounted) {
|
||||
return;
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { registerLayerWizard } from './layer_wizard_registry';
|
||||
import { uploadLayerWizardConfig } from '../sources/client_file_source';
|
||||
import { uploadLayerWizardConfig } from './file_upload_wizard';
|
||||
// @ts-ignore
|
||||
import { esDocumentsLayerWizardConfig } from '../sources/es_search_source';
|
||||
// @ts-ignore
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import { AbstractVectorSource } from '../vector_source';
|
||||
import { SOURCE_TYPES } from '../../../../common/constants';
|
||||
import { registerSource } from '../source_registry';
|
||||
|
||||
export class GeojsonFileSource extends AbstractVectorSource {
|
||||
static type = SOURCE_TYPES.GEOJSON_FILE;
|
||||
|
||||
static createDescriptor(geoJson, name) {
|
||||
// Wrap feature as feature collection if needed
|
||||
let featureCollection;
|
||||
|
||||
if (!geoJson) {
|
||||
featureCollection = {
|
||||
type: 'FeatureCollection',
|
||||
features: [],
|
||||
};
|
||||
} else if (geoJson.type === 'FeatureCollection') {
|
||||
featureCollection = geoJson;
|
||||
} else if (geoJson.type === 'Feature') {
|
||||
featureCollection = {
|
||||
type: 'FeatureCollection',
|
||||
features: [geoJson],
|
||||
};
|
||||
} else {
|
||||
// Missing or incorrect type
|
||||
featureCollection = {
|
||||
type: 'FeatureCollection',
|
||||
features: [],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: GeojsonFileSource.type,
|
||||
__featureCollection: featureCollection,
|
||||
name,
|
||||
};
|
||||
}
|
||||
|
||||
async getGeoJsonWithMeta() {
|
||||
return {
|
||||
data: this._descriptor.__featureCollection,
|
||||
meta: {},
|
||||
};
|
||||
}
|
||||
|
||||
async getDisplayName() {
|
||||
return this._descriptor.name;
|
||||
}
|
||||
|
||||
canFormatFeatureProperties() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
registerSource({
|
||||
ConstructorFunction: GeojsonFileSource,
|
||||
type: SOURCE_TYPES.GEOJSON_FILE,
|
||||
});
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import { Feature, FeatureCollection } from 'geojson';
|
||||
import { AbstractVectorSource } from '../vector_source';
|
||||
import { EMPTY_FEATURE_COLLECTION, SOURCE_TYPES } from '../../../../common/constants';
|
||||
import { GeojsonFileSourceDescriptor } from '../../../../common/descriptor_types';
|
||||
import { registerSource } from '../source_registry';
|
||||
|
||||
function getFeatureCollection(geoJson: Feature | FeatureCollection | null): FeatureCollection {
|
||||
if (!geoJson) {
|
||||
return EMPTY_FEATURE_COLLECTION;
|
||||
}
|
||||
|
||||
if (geoJson.type === 'FeatureCollection') {
|
||||
return geoJson;
|
||||
}
|
||||
|
||||
if (geoJson.type === 'Feature') {
|
||||
return {
|
||||
type: 'FeatureCollection',
|
||||
features: [geoJson],
|
||||
};
|
||||
}
|
||||
|
||||
return EMPTY_FEATURE_COLLECTION;
|
||||
}
|
||||
|
||||
export class GeojsonFileSource extends AbstractVectorSource {
|
||||
static type = SOURCE_TYPES.GEOJSON_FILE;
|
||||
|
||||
static createDescriptor(
|
||||
geoJson: Feature | FeatureCollection | null,
|
||||
name: string
|
||||
): GeojsonFileSourceDescriptor {
|
||||
return {
|
||||
type: GeojsonFileSource.type,
|
||||
__featureCollection: getFeatureCollection(geoJson),
|
||||
name,
|
||||
};
|
||||
}
|
||||
|
||||
async getGeoJsonWithMeta() {
|
||||
return {
|
||||
data: (this._descriptor as GeojsonFileSourceDescriptor).__featureCollection,
|
||||
meta: {},
|
||||
};
|
||||
}
|
||||
|
||||
async getDisplayName() {
|
||||
return (this._descriptor as GeojsonFileSourceDescriptor).name;
|
||||
}
|
||||
|
||||
canFormatFeatureProperties() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
registerSource({
|
||||
ConstructorFunction: GeojsonFileSource,
|
||||
type: SOURCE_TYPES.GEOJSON_FILE,
|
||||
});
|
|
@ -4,6 +4,4 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
// @ts-ignore
|
||||
export { GeojsonFileSource } from './geojson_file_source';
|
||||
export { uploadLayerWizardConfig } from './upload_layer_wizard';
|
|
@ -133,7 +133,7 @@ export class AbstractSource implements ISource {
|
|||
}
|
||||
|
||||
getApplyGlobalQuery(): boolean {
|
||||
return !!this._descriptor.applyGlobalQuery;
|
||||
return 'applyGlobalQuery' in this._descriptor ? !!this._descriptor.applyGlobalQuery : false;
|
||||
}
|
||||
|
||||
getIndexPatternIds(): string[] {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
import { createSelector } from 'reselect';
|
||||
import { FeatureCollection } from 'geojson';
|
||||
import _ from 'lodash';
|
||||
import { Adapters } from 'src/plugins/inspector/public';
|
||||
import { TileLayer } from '../classes/layers/tile_layer/tile_layer';
|
||||
|
@ -22,8 +23,7 @@ import { copyPersistentState, TRACKED_LAYER_DESCRIPTOR } from '../reducers/util'
|
|||
import { IJoin } from '../classes/joins/join';
|
||||
import { InnerJoin } from '../classes/joins/inner_join';
|
||||
import { getSourceByType } from '../classes/sources/source_registry';
|
||||
// @ts-ignore
|
||||
import { GeojsonFileSource } from '../classes/sources/client_file_source';
|
||||
import { GeojsonFileSource } from '../classes/sources/geojson_file_source';
|
||||
import {
|
||||
LAYER_TYPE,
|
||||
SOURCE_DATA_REQUEST_ID,
|
||||
|
@ -247,7 +247,7 @@ export const getSpatialFiltersLayer = createSelector(
|
|||
getFilters,
|
||||
getMapSettings,
|
||||
(filters, settings) => {
|
||||
const featureCollection = {
|
||||
const featureCollection: FeatureCollection = {
|
||||
type: 'FeatureCollection',
|
||||
features: extractFeaturesFromFilters(filters),
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue