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] Implement fields and bounds retrieval on GeoJsonFileSource #88294

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { i18n } from '@kbn/i18n';
import uuid from 'uuid/v4';
import { Filter, IFieldType, IndexPattern, ISearchSource } from 'src/plugins/data/public';
import { AbstractVectorSource, BoundsFilters } from '../vector_source';
import { AbstractVectorSource, ESGlobalFilters } from '../vector_source';
import {
getAutocompleteService,
getIndexPatternService,
Expand Down Expand Up @@ -211,7 +211,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource
}

async makeSearchSource(
searchFilters: VectorSourceRequestMeta | VectorJoinSourceRequestMeta | BoundsFilters,
searchFilters: VectorSourceRequestMeta | VectorJoinSourceRequestMeta | ESGlobalFilters,
limit: number,
initialSearchContext?: object
): Promise<ISearchSource> {
Expand Down Expand Up @@ -264,7 +264,7 @@ export class AbstractESSource extends AbstractVectorSource implements IESSource
}

async getBoundsForFilters(
boundsFilters: BoundsFilters,
boundsFilters: ESGlobalFilters,
registerCancelCallback: (callback: () => void) => void
): Promise<MapExtent | null> {
const searchSource = await this.makeSearchSource(boundsFilters, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*/

import { Feature, FeatureCollection } from 'geojson';
import { AbstractVectorSource, GeoJsonWithMeta } from '../vector_source';
import { AbstractVectorSource, ESGlobalFilters, GeoJsonWithMeta } from '../vector_source';
import { EMPTY_FEATURE_COLLECTION, SOURCE_TYPES } from '../../../../common/constants';
import { GeojsonFileSourceDescriptor } from '../../../../common/descriptor_types';
import { GeojsonFileSourceDescriptor, MapExtent } from '../../../../common/descriptor_types';
import { registerSource } from '../source_registry';
import { IField } from '../../fields/field';
import { getFeatureCollectionBounds } from '../../util/get_feature_collection_bounds';

function getFeatureCollection(geoJson: Feature | FeatureCollection | null): FeatureCollection {
if (!geoJson) {
Expand Down Expand Up @@ -42,6 +43,18 @@ export class GeojsonFileSource extends AbstractVectorSource {
};
}

isBoundsAware(): boolean {
return true;
}

async getBoundsForFilters(
boundsFilters: ESGlobalFilters,
registerCancelCallback: (callback: () => void) => void
): Promise<MapExtent | null> {
const featureCollection = (this._descriptor as GeojsonFileSourceDescriptor).__featureCollection;
return getFeatureCollectionBounds(featureCollection, false);
}

async getGeoJsonWithMeta(): Promise<GeoJsonWithMeta> {
return {
data: (this._descriptor as GeojsonFileSourceDescriptor).__featureCollection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import uuid from 'uuid/v4';
import React from 'react';
import { GeoJsonProperties } from 'geojson';
import { AbstractSource, ImmutableSourceProperty, SourceEditorArgs } from '../source';
import { BoundsFilters, GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source';
import { ESGlobalFilters, GeoJsonWithMeta, ITiledSingleLayerVectorSource } from '../vector_source';
import {
FIELD_ORIGIN,
MAX_ZOOM,
Expand Down Expand Up @@ -179,7 +179,7 @@ export class MVTSingleLayerVectorSource
}

async getBoundsForFilters(
boundsFilters: BoundsFilters,
boundsFilters: ESGlobalFilters,
registerCancelCallback: (callback: () => void) => void
): Promise<MapExtent | null> {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface GeoJsonWithMeta {
meta?: GeoJsonFetchMeta;
}

export interface BoundsFilters {
export interface ESGlobalFilters {
applyGlobalQuery: boolean;
applyGlobalTime: boolean;
filters: Filter[];
Expand All @@ -47,7 +47,7 @@ export interface BoundsFilters {
export interface IVectorSource extends ISource {
getTooltipProperties(properties: GeoJsonProperties): Promise<ITooltipProperty[]>;
getBoundsForFilters(
boundsFilters: BoundsFilters,
boundsFilters: ESGlobalFilters,
registerCancelCallback: (callback: () => void) => void
): Promise<MapExtent | null>;
getGeoJsonWithMeta(
Expand Down Expand Up @@ -147,7 +147,7 @@ export class AbstractVectorSource extends AbstractSource implements IVectorSourc
}

async getBoundsForFilters(
boundsFilters: BoundsFilters,
boundsFilters: ESGlobalFilters,
registerCancelCallback: (callback: () => void) => void
): Promise<MapExtent | null> {
return null;
Expand Down
35 changes: 25 additions & 10 deletions x-pack/plugins/maps/public/licensed_features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ export const LICENCED_FEATURES_DETAILS: Record<LICENSED_FEATURES, LicensedFeatur

thomasneirynck marked this conversation as resolved.
Show resolved Hide resolved
let licenseId: string | undefined;
let isGoldPlus: boolean = false;

let isEnterprisePlus: boolean = false;

export const getLicenseId = () => licenseId;
export const getIsGoldPlus = () => isGoldPlus;

let initializeLicense: (value: unknown) => void;
const licenseInitialized = new Promise((resolve) => {
initializeLicense = resolve;
});

export const getIsEnterprisePlus = () => isEnterprisePlus;
export const whenLicenseInitialized = async (): Promise<void> => {
await licenseInitialized;
};

export function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup) {
for (const licensedFeature of Object.values(LICENSED_FEATURES)) {
Expand All @@ -54,17 +61,25 @@ export function registerLicensedFeatures(licensingPlugin: LicensingPluginSetup)
}

let licensingPluginStart: LicensingPluginStart;
export function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) {
licensingPluginStart = licensingPlugin;
licensingPluginStart.license$.subscribe((license: ILicense) => {
const gold = license.check(APP_ID, 'gold');
isGoldPlus = gold.state === 'valid';

const enterprise = license.check(APP_ID, 'enterprise');
isEnterprisePlus = enterprise.state === 'valid';
function updateLicenseState(license: ILicense) {
const gold = license.check(APP_ID, 'gold');
isGoldPlus = gold.state === 'valid';

const enterprise = license.check(APP_ID, 'enterprise');
isEnterprisePlus = enterprise.state === 'valid';

licenseId = license.uid;
}

export async function setLicensingPluginStart(licensingPlugin: LicensingPluginStart) {
const license = await licensingPlugin.refresh();
updateLicenseState(license);

licensingPluginStart = licensingPlugin;
licensingPluginStart.license$.subscribe(updateLicenseState);

licenseId = license.uid;
});
initializeLicense(undefined);
}

export function notifyLicensedFeatureUsage(licensedFeature: LICENSED_FEATURES) {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class MapsPlugin
});
}

public start(core: CoreStart, plugins: MapsPluginStartDependencies): MapsStartApi {
public start(core: CoreStart, plugins: MapsPluginStartDependencies): Promise<MapsStartApi> {
setLicensingPluginStart(plugins.licensing);
plugins.uiActions.addTriggerAction(VISUALIZE_GEO_FIELD_TRIGGER, visualizeGeoFieldAction);
setStartServices(core, plugins);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { copyPersistentState } from '../../../reducers/util';
import { getBreadcrumbs } from './get_breadcrumbs';
import { DEFAULT_IS_LAYER_TOC_OPEN } from '../../../reducers/ui';
import { createBasemapLayerDescriptor } from '../../../classes/layers/create_basemap_layer_descriptor';
import { whenLicenseInitialized } from '../../../licensed_features';

export class SavedMap {
private _attributes: MapSavedObjectAttributes | null = null;
Expand Down Expand Up @@ -87,6 +88,8 @@ export class SavedMap {
}

async whenReady() {
await whenLicenseInitialized();

if (!this._mapEmbeddableInput) {
this._attributes = {
title: '',
Expand Down