Skip to content

Commit

Permalink
[Maps] Surface on prem EMS (#85729) (#85892)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
thomasneirynck and kibanamachine authored Dec 15, 2020
1 parent 4bcf39f commit a3a2891
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 86 deletions.
28 changes: 16 additions & 12 deletions x-pack/plugins/maps/common/ems_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,38 @@ export class EMSSettings {
this._getIsEnterprisePlus = getIsEnterPrisePlus;
}

_isEMSUrlSet() {
isEMSUrlSet() {
return !!this._config.emsUrl;
}

_getEMSRoot() {
getEMSRoot() {
return this._config.emsUrl!.replace(/\/$/, '');
}

isOnPrem(): boolean {
return this._isEMSUrlSet();
return this.isEMSUrlSet();
}

isIncludeElasticMapsService() {
return !!this._config.includeElasticMapsService;
}

hasOnPremLicense() {
return this._getIsEnterprisePlus();
}

isEMSEnabled(): boolean {
if (this._isEMSUrlSet()) {
if (this.isEMSUrlSet()) {
return this._getIsEnterprisePlus();
}
return this.isIncludeElasticMapsService();
}

getEMSFileApiUrl(): string {
if (this._config.emsFileApiUrl !== DEFAULT_EMS_FILE_API_URL || !this._isEMSUrlSet()) {
if (this._config.emsFileApiUrl !== DEFAULT_EMS_FILE_API_URL || !this.isEMSUrlSet()) {
return this._config.emsFileApiUrl!;
} else {
return `${this._getEMSRoot()}/file`;
return `${this.getEMSRoot()}/file`;
}
}

Expand All @@ -67,25 +71,25 @@ export class EMSSettings {
}

getEMSTileApiUrl(): string {
if (this._config.emsTileApiUrl !== DEFAULT_EMS_TILE_API_URL || !this._isEMSUrlSet()) {
if (this._config.emsTileApiUrl !== DEFAULT_EMS_TILE_API_URL || !this.isEMSUrlSet()) {
return this._config.emsTileApiUrl!;
} else {
return `${this._getEMSRoot()}/tile`;
return `${this.getEMSRoot()}/tile`;
}
}
getEMSLandingPageUrl(): string {
if (this._config.emsLandingPageUrl !== DEFAULT_EMS_LANDING_PAGE_URL || !this._isEMSUrlSet()) {
if (this._config.emsLandingPageUrl !== DEFAULT_EMS_LANDING_PAGE_URL || !this.isEMSUrlSet()) {
return this._config.emsLandingPageUrl!;
} else {
return `${this._getEMSRoot()}/maps`;
return `${this.getEMSRoot()}/maps`;
}
}

getEMSFontLibraryUrl(): string {
if (this._config.emsFontLibraryUrl !== DEFAULT_EMS_FONT_LIBRARY_URL || !this._isEMSUrlSet()) {
if (this._config.emsFontLibraryUrl !== DEFAULT_EMS_FONT_LIBRARY_URL || !this.isEMSUrlSet()) {
return this._config.emsFontLibraryUrl!;
} else {
return `${this._getEMSRoot()}/tile/fonts/{fontstack}/{range}.pbf`;
return `${this.getEMSRoot()}/tile/fonts/{fontstack}/{range}.pbf`;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ jest.mock('../../../kibana_services', () => {
getIndexPatternSelectComponent: () => {
return MockIndexPatternSelect;
},
getEMSSettings() {
return {
isEMSUrlSet() {
return false;
},
};
},
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ jest.mock('../../../../kibana_services', () => {
getIsDarkMode() {
return false;
},
getEMSSettings() {
return {
isEMSUrlSet() {
return false;
},
};
},
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ jest.mock('../../../../kibana_services', () => {
getIsDarkMode() {
return false;
},
getEMSSettings() {
return {
isEMSUrlSet() {
return false;
},
};
},
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,38 @@ import { i18n } from '@kbn/i18n';
import { VectorLayer } from '../../layers/vector_layer/vector_layer';
import { LayerWizard, RenderWizardArguments } from '../../layers/layer_wizard_registry';
import { EMSFileCreateSourceEditor } from './create_source_editor';
import { EMSFileSource, sourceTitle } from './ems_file_source';
import { EMSFileSource, getSourceTitle } from './ems_file_source';

// @ts-ignore
import { getEMSSettings } from '../../../kibana_services';
import { EMSFileSourceDescriptor } from '../../../../common/descriptor_types';
import { LAYER_WIZARD_CATEGORY } from '../../../../common/constants';
import { EMSBoundariesLayerIcon } from '../../layers/icons/ems_boundaries_layer_icon';

function getDescription() {
const emsSettings = getEMSSettings();
return i18n.translate('xpack.maps.source.emsFileSourceDescription', {
defaultMessage: 'Administrative boundaries from {host}',
values: {
host: emsSettings.isEMSUrlSet() ? emsSettings.getEMSRoot() : 'Elastic Maps Service',
},
});
}

export const emsBoundariesLayerWizardConfig: LayerWizard = {
categories: [LAYER_WIZARD_CATEGORY.REFERENCE],
checkVisibility: async () => {
const emsSettings = getEMSSettings();
return emsSettings!.isEMSEnabled();
return emsSettings.isIncludeElasticMapsService();
},
description: i18n.translate('xpack.maps.source.emsFileDescription', {
defaultMessage: 'Administrative boundaries from Elastic Maps Service',
description: getDescription(),
disabledReason: i18n.translate('xpack.maps.source.emsFileDisabledReason', {
defaultMessage: 'Elastic Maps Server requires an Enterprise license',
}),
getIsDisabled: () => {
const emsSettings = getEMSSettings();
return emsSettings.isEMSUrlSet() && !emsSettings.hasOnPremLicense();
},
icon: EMSBoundariesLayerIcon,
renderWizard: ({ previewLayers, mapColors }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: Partial<EMSFileSourceDescriptor>) => {
Expand All @@ -34,5 +50,5 @@ export const emsBoundariesLayerWizardConfig: LayerWizard = {
};
return <EMSFileCreateSourceEditor onSourceConfigChange={onSourceConfigChange} />;
},
title: sourceTitle,
title: getSourceTitle(),
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,35 @@ import { registerSource } from '../source_registry';
import { IField } from '../../fields/field';
import { EMSFileSourceDescriptor } from '../../../../common/descriptor_types';
import { ITooltipProperty } from '../../tooltips/tooltip_property';
import { getEMSSettings } from '../../../kibana_services';
import { getEmsUnavailableMessage } from '../../../components/ems_unavailable_message';

function getErrorInfo(fileId: string) {
return i18n.translate('xpack.maps.source.emsFile.unableToFindFileIdErrorMessage', {
defaultMessage: `Unable to find EMS vector shapes for id: {id}. {info}`,
values: {
id: fileId,
info: getEmsUnavailableMessage(),
},
});
}

export interface IEmsFileSource extends IVectorSource {
getEmsFieldLabel(emsFieldName: string): Promise<string>;
}

export const sourceTitle = i18n.translate('xpack.maps.source.emsFileTitle', {
defaultMessage: 'EMS Boundaries',
});
export function getSourceTitle() {
const emsSettings = getEMSSettings();
if (emsSettings.isEMSUrlSet()) {
return i18n.translate('xpack.maps.source.emsOnPremFileTitle', {
defaultMessage: 'Elastic Maps Server Boundaries',
});
} else {
return i18n.translate('xpack.maps.source.emsFileTitle', {
defaultMessage: 'EMS Boundaries',
});
}
}

export class EMSFileSource extends AbstractVectorSource implements IEmsFileSource {
static createDescriptor({ id, tooltipProperties = [] }: Partial<EMSFileSourceDescriptor>) {
Expand Down Expand Up @@ -74,19 +95,19 @@ export class EMSFileSource extends AbstractVectorSource implements IEmsFileSourc
}

async getEMSFileLayer(): Promise<FileLayer> {
const emsFileLayers = await getEmsFileLayers();
let emsFileLayers: FileLayer[];
try {
emsFileLayers = await getEmsFileLayers();
} catch (e) {
throw new Error(`${getErrorInfo(this._descriptor.id)} - ${e.message}`);
}

const emsFileLayer = emsFileLayers.find((fileLayer) => fileLayer.hasId(this._descriptor.id));
if (!emsFileLayer) {
throw new Error(
i18n.translate('xpack.maps.source.emsFile.unableToFindIdErrorMessage', {
defaultMessage: `Unable to find EMS vector shapes for id: {id}`,
values: {
id: this._descriptor.id,
},
})
);
if (emsFileLayer) {
return emsFileLayer;
}
return emsFileLayer;

throw new Error(getErrorInfo(this._descriptor.id));
}

// Map EMS field name to language specific label
Expand Down Expand Up @@ -129,10 +150,10 @@ export class EMSFileSource extends AbstractVectorSource implements IEmsFileSourc
// ignore error if EMS layer id could not be found
}

return [
const props = [
{
label: getDataSourceLabel(),
value: sourceTitle,
value: getSourceTitle(),
},
{
label: i18n.translate('xpack.maps.source.emsFile.layerLabel', {
Expand All @@ -142,6 +163,17 @@ export class EMSFileSource extends AbstractVectorSource implements IEmsFileSourc
link: emsLink,
},
];

const emsSettings = getEMSSettings();
if (emsSettings.isEMSUrlSet()) {
props.push({
label: i18n.translate('xpack.maps.source.emsFile.emsOnPremLabel', {
defaultMessage: `Elastic Maps Server`,
}),
value: emsSettings.getEMSRoot(),
});
}
return props;
}

async getDisplayName(): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n';
import { EuiPanel } from '@elastic/eui';
import { LayerWizard, RenderWizardArguments } from '../../layers/layer_wizard_registry';
// @ts-ignore
import { EMSTMSSource, sourceTitle } from './ems_tms_source';
import { EMSTMSSource, getSourceTitle } from './ems_tms_source';
// @ts-ignore
import { VectorTileLayer } from '../../layers/vector_tile_layer/vector_tile_layer';
// @ts-ignore
Expand All @@ -17,15 +17,30 @@ import { getEMSSettings } from '../../../kibana_services';
import { LAYER_WIZARD_CATEGORY } from '../../../../common/constants';
import { WorldMapLayerIcon } from '../../layers/icons/world_map_layer_icon';

function getDescription() {
const emsSettings = getEMSSettings();
return i18n.translate('xpack.maps.source.emsTileSourceDescription', {
defaultMessage: 'Basemap service from {host}',
values: {
host: emsSettings.isEMSUrlSet() ? emsSettings.getEMSRoot() : 'Elastic Maps Service',
},
});
}

export const emsBaseMapLayerWizardConfig: LayerWizard = {
categories: [LAYER_WIZARD_CATEGORY.REFERENCE],
checkVisibility: async () => {
const emsSettings = getEMSSettings();
return emsSettings!.isEMSEnabled();
return emsSettings.isIncludeElasticMapsService();
},
description: i18n.translate('xpack.maps.source.emsTileDescription', {
defaultMessage: 'Tile map service from Elastic Maps Service',
description: getDescription(),
disabledReason: i18n.translate('xpack.maps.source.emsTileDisabledReason', {
defaultMessage: 'Elastic Maps Server requires an Enterprise license',
}),
getIsDisabled: () => {
const emsSettings = getEMSSettings();
return emsSettings.isEMSUrlSet() && !emsSettings.hasOnPremLicense();
},
icon: WorldMapLayerIcon,
renderWizard: ({ previewLayers }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: unknown) => {
Expand All @@ -41,5 +56,5 @@ export const emsBaseMapLayerWizardConfig: LayerWizard = {
</EuiPanel>
);
},
title: sourceTitle,
title: getSourceTitle(),
};
Loading

0 comments on commit a3a2891

Please sign in to comment.