Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
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 {
Comment on lines -51 to -58
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impossible case. for all cases if (!baseMapOpts) { returns false

Copy link
Contributor

@nreese nreese Jan 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that this logic is an impossible case (which is causing a bug), but a warning should be logged if const mapOptions = tmsServices.find((s) => s.id === mapStyle); returns undefined.

To view the issue, add map.includeElasticMapsService: false to your kibana.dev.yml. Then remove map.tilemap.url as well. This will disable EMS so mapOptions will be undefined. Then, running vega will fail because baseMapOpts is not properly defined
Screen Shot 2021-01-14 at 7 12 07 AM

I would recommend returning null from getMapStyleOptions if mapOptions is undefined. Then, add logic to the caller of getMapStyleOptions to check for null and log the warning if the return is null.

I am ok if you do not want to fix this issue in this PR, instead, we can just create a new issue and tackle this in a separate thread.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was fixed it that PR

baseMapOpts = await this.getMapStyleOptions();

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