Skip to content

Commit b5e49e4

Browse files
authored
Vega Maps Referencing from kibana.yml (#88316) (#88435)
* Vega Maps Referencing from kibana.yml Closes: #87853 * update translations * fix PR comments
1 parent 93db245 commit b5e49e4

File tree

5 files changed

+70
-27
lines changed

5 files changed

+70
-27
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
export const TMS_IN_YML_ID = 'TMS in config/kibana.yml';
21+
22+
export { ORIGIN } from './origin';

src/plugins/maps_legacy/public/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export {
5353

5454
export * from '../common';
5555
export * from './common/types';
56-
export { ORIGIN } from './common/constants/origin';
56+
export { ORIGIN, TMS_IN_YML_ID } from './common/constants';
5757

5858
export { WmsOptions } from './components/wms_options';
5959
export { LegacyMapDeprecationMessage } from './components/legacy_map_deprecation_message';

src/plugins/maps_legacy/public/map/service_settings.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import MarkdownIt from 'markdown-it';
2222
import { EMSClient } from '@elastic/ems-client';
2323
import { i18n } from '@kbn/i18n';
2424
import { getKibanaVersion } from '../kibana_services';
25-
import { ORIGIN } from '../common/constants/origin';
26-
27-
const TMS_IN_YML_ID = 'TMS in config/kibana.yml';
25+
import { ORIGIN, TMS_IN_YML_ID } from '../common/constants';
2826

2927
export class ServiceSettings {
3028
constructor(mapConfig, tilemapsConfig) {

src/plugins/vis_type_vega/public/services.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,3 @@ export const [getMapsLegacyConfig, setMapsLegacyConfig] = createGetterSetter<Map
4545
);
4646

4747
export const getEnableExternalUrls = () => getInjectedVars().enableExternalUrls;
48-
export const getEmsTileLayerId = () => getMapsLegacyConfig().emsTileLayerId;

src/plugins/vis_type_vega/public/vega_view/vega_map_view.js

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,65 @@ import { i18n } from '@kbn/i18n';
2121
import { vega } from '../lib/vega';
2222
import { VegaBaseView } from './vega_base_view';
2323
import { VegaMapLayer } from './vega_map_layer';
24-
import { getEmsTileLayerId, getUISettings } from '../services';
25-
import { lazyLoadMapsLegacyModules } from '../../../maps_legacy/public';
24+
import { getMapsLegacyConfig, getUISettings } from '../services';
25+
import { lazyLoadMapsLegacyModules, TMS_IN_YML_ID } from '../../../maps_legacy/public';
26+
27+
const isUserConfiguredTmsLayer = ({ tilemap }) => Boolean(tilemap.url);
2628

2729
export class VegaMapView extends VegaBaseView {
2830
constructor(opts) {
2931
super(opts);
3032
}
3133

34+
async getMapStyleOptions() {
35+
const isDarkMode = getUISettings().get('theme:darkMode');
36+
const mapsLegacyConfig = getMapsLegacyConfig();
37+
const tmsServices = await this._serviceSettings.getTMSServices();
38+
const mapConfig = this._parser.mapConfig;
39+
40+
let mapStyle;
41+
42+
if (mapConfig.mapStyle !== 'default') {
43+
mapStyle = mapConfig.mapStyle;
44+
} else {
45+
if (isUserConfiguredTmsLayer(mapsLegacyConfig)) {
46+
mapStyle = TMS_IN_YML_ID;
47+
} else {
48+
mapStyle = mapsLegacyConfig.emsTileLayerId.bright;
49+
}
50+
}
51+
52+
const mapOptions = tmsServices.find((s) => s.id === mapStyle);
53+
54+
if (!mapOptions) {
55+
this.onWarn(
56+
i18n.translate('visTypeVega.mapView.mapStyleNotFoundWarningMessage', {
57+
defaultMessage: '{mapStyleParam} was not found',
58+
values: { mapStyleParam: `"mapStyle":${mapStyle}` },
59+
})
60+
);
61+
return null;
62+
}
63+
64+
return {
65+
...mapOptions,
66+
...(await this._serviceSettings.getAttributesForTMSLayer(mapOptions, true, isDarkMode)),
67+
};
68+
}
69+
3270
async _initViewCustomizations() {
3371
const mapConfig = this._parser.mapConfig;
3472
let baseMapOpts;
3573
let limitMinZ = 0;
3674
let limitMaxZ = 25;
3775

76+
// In some cases, Vega may be initialized twice, e.g. after awaiting...
77+
if (!this._$container) return;
78+
3879
if (mapConfig.mapStyle !== false) {
39-
const tmsServices = await this._serviceSettings.getTMSServices();
40-
// In some cases, Vega may be initialized twice, e.g. after awaiting...
41-
if (!this._$container) return;
42-
const emsTileLayerId = getEmsTileLayerId();
43-
const mapStyle =
44-
mapConfig.mapStyle === 'default' ? emsTileLayerId.bright : mapConfig.mapStyle;
45-
const isDarkMode = getUISettings().get('theme:darkMode');
46-
baseMapOpts = tmsServices.find((s) => s.id === mapStyle);
47-
baseMapOpts = {
48-
...baseMapOpts,
49-
...(await this._serviceSettings.getAttributesForTMSLayer(baseMapOpts, true, isDarkMode)),
50-
};
51-
if (!baseMapOpts) {
52-
this.onWarn(
53-
i18n.translate('visTypeVega.mapView.mapStyleNotFoundWarningMessage', {
54-
defaultMessage: '{mapStyleParam} was not found',
55-
values: { mapStyleParam: `"mapStyle": ${JSON.stringify(mapStyle)}` },
56-
})
57-
);
58-
} else {
80+
baseMapOpts = await this.getMapStyleOptions();
81+
82+
if (baseMapOpts) {
5983
limitMinZ = baseMapOpts.minZoom;
6084
limitMaxZ = baseMapOpts.maxZoom;
6185
}

0 commit comments

Comments
 (0)