Skip to content

Commit

Permalink
Vega Maps Referencing from kibana.yml (#88316)
Browse files Browse the repository at this point in the history
* Vega Maps Referencing from kibana.yml

Closes: #87853

* update translations

* fix PR comments
  • Loading branch information
alexwizp authored Jan 15, 2021
1 parent 6beef61 commit bc0368f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 27 deletions.
22 changes: 22 additions & 0 deletions src/plugins/maps_legacy/public/common/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const TMS_IN_YML_ID = 'TMS in config/kibana.yml';

export { ORIGIN } from './origin';
2 changes: 1 addition & 1 deletion src/plugins/maps_legacy/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export {

export * from '../common';
export * from './common/types';
export { ORIGIN } from './common/constants/origin';
export { ORIGIN, TMS_IN_YML_ID } from './common/constants';

export { WmsOptions } from './components/wms_options';
export { LegacyMapDeprecationMessage } from './components/legacy_map_deprecation_message';
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/maps_legacy/public/map/service_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import MarkdownIt from 'markdown-it';
import { EMSClient } from '@elastic/ems-client';
import { i18n } from '@kbn/i18n';
import { getKibanaVersion } from '../kibana_services';
import { ORIGIN } from '../common/constants/origin';

const TMS_IN_YML_ID = 'TMS in config/kibana.yml';
import { ORIGIN, TMS_IN_YML_ID } from '../common/constants';

export class ServiceSettings {
constructor(mapConfig, tilemapsConfig) {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/vis_type_vega/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ export const [getMapsLegacyConfig, setMapsLegacyConfig] = createGetterSetter<Map
);

export const getEnableExternalUrls = () => getInjectedVars().enableExternalUrls;
export const getEmsTileLayerId = () => getMapsLegacyConfig().emsTileLayerId;
68 changes: 46 additions & 22 deletions src/plugins/vis_type_vega/public/vega_view/vega_map_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,65 @@ import { i18n } from '@kbn/i18n';
import { vega } from '../lib/vega';
import { VegaBaseView } from './vega_base_view';
import { VegaMapLayer } from './vega_map_layer';
import { getEmsTileLayerId, getUISettings } from '../services';
import { lazyLoadMapsLegacyModules } from '../../../maps_legacy/public';
import { getMapsLegacyConfig, getUISettings } from '../services';
import { lazyLoadMapsLegacyModules, TMS_IN_YML_ID } from '../../../maps_legacy/public';

const isUserConfiguredTmsLayer = ({ tilemap }) => Boolean(tilemap.url);

export class VegaMapView extends VegaBaseView {
constructor(opts) {
super(opts);
}

async getMapStyleOptions() {
const isDarkMode = getUISettings().get('theme:darkMode');
const mapsLegacyConfig = getMapsLegacyConfig();
const tmsServices = await this._serviceSettings.getTMSServices();
const mapConfig = this._parser.mapConfig;

let mapStyle;

if (mapConfig.mapStyle !== 'default') {
mapStyle = mapConfig.mapStyle;
} else {
if (isUserConfiguredTmsLayer(mapsLegacyConfig)) {
mapStyle = TMS_IN_YML_ID;
} else {
mapStyle = mapsLegacyConfig.emsTileLayerId.bright;
}
}

const mapOptions = tmsServices.find((s) => s.id === mapStyle);

if (!mapOptions) {
this.onWarn(
i18n.translate('visTypeVega.mapView.mapStyleNotFoundWarningMessage', {
defaultMessage: '{mapStyleParam} was not found',
values: { mapStyleParam: `"mapStyle":${mapStyle}` },
})
);
return null;
}

return {
...mapOptions,
...(await this._serviceSettings.getAttributesForTMSLayer(mapOptions, true, isDarkMode)),
};
}

async _initViewCustomizations() {
const mapConfig = this._parser.mapConfig;
let baseMapOpts;
let limitMinZ = 0;
let limitMaxZ = 25;

// In some cases, Vega may be initialized twice, e.g. after awaiting...
if (!this._$container) return;

if (mapConfig.mapStyle !== false) {
const tmsServices = await this._serviceSettings.getTMSServices();
// In some cases, Vega may be initialized twice, e.g. after awaiting...
if (!this._$container) return;
const emsTileLayerId = getEmsTileLayerId();
const mapStyle =
mapConfig.mapStyle === 'default' ? emsTileLayerId.bright : mapConfig.mapStyle;
const isDarkMode = getUISettings().get('theme:darkMode');
baseMapOpts = tmsServices.find((s) => s.id === mapStyle);
baseMapOpts = {
...baseMapOpts,
...(await this._serviceSettings.getAttributesForTMSLayer(baseMapOpts, true, isDarkMode)),
};
if (!baseMapOpts) {
this.onWarn(
i18n.translate('visTypeVega.mapView.mapStyleNotFoundWarningMessage', {
defaultMessage: '{mapStyleParam} was not found',
values: { mapStyleParam: `"mapStyle": ${JSON.stringify(mapStyle)}` },
})
);
} else {
baseMapOpts = await this.getMapStyleOptions();

if (baseMapOpts) {
limitMinZ = baseMapOpts.minZoom;
limitMaxZ = baseMapOpts.maxZoom;
}
Expand Down

0 comments on commit bc0368f

Please sign in to comment.