Skip to content

Commit

Permalink
Fix TMS not loaded in legacy maps (#73570)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Aaron Caldwell and elasticmachine committed Aug 4, 2020
1 parent 8ca6677 commit e319582
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 52 deletions.
18 changes: 7 additions & 11 deletions src/plugins/maps_legacy/public/map/service_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class ServiceSettings {
constructor(mapConfig, tilemapsConfig) {
this._mapConfig = mapConfig;
this._tilemapsConfig = tilemapsConfig;
this._hasTmsConfigured = typeof tilemapsConfig.url === 'string' && tilemapsConfig.url !== '';

this._showZoomMessage = true;
this._emsClient = new EMSClient({
Expand All @@ -53,13 +54,10 @@ export class ServiceSettings {
linkify: true,
});

// TMS attribution
const attributionFromConfig = _.escape(
markdownIt.render(this._tilemapsConfig.deprecated.config.options.attribution || '')
);
// TMS Options
this.tmsOptionsFromConfig = _.assign({}, this._tilemapsConfig.deprecated.config.options, {
attribution: attributionFromConfig,
this.tmsOptionsFromConfig = _.assign({}, this._tilemapsConfig.options, {
attribution: _.escape(markdownIt.render(this._tilemapsConfig.options.attribution || '')),
url: this._tilemapsConfig.url,
});
}

Expand Down Expand Up @@ -122,7 +120,7 @@ export class ServiceSettings {
*/
async getTMSServices() {
let allServices = [];
if (this._tilemapsConfig.deprecated.isOverridden) {
if (this._hasTmsConfigured) {
//use tilemap.* settings from yml
const tmsService = _.cloneDeep(this.tmsOptionsFromConfig);
tmsService.id = TMS_IN_YML_ID;
Expand Down Expand Up @@ -210,14 +208,12 @@ export class ServiceSettings {
if (tmsServiceConfig.origin === ORIGIN.EMS) {
return this._getAttributesForEMSTMSLayer(isDesaturated, isDarkMode);
} else if (tmsServiceConfig.origin === ORIGIN.KIBANA_YML) {
const config = this._tilemapsConfig.deprecated.config;
const attrs = _.pick(config, ['url', 'minzoom', 'maxzoom', 'attribution']);
const attrs = _.pick(this._tilemapsConfig, ['url', 'minzoom', 'maxzoom', 'attribution']);
return { ...attrs, ...{ origin: ORIGIN.KIBANA_YML } };
} else {
//this is an older config. need to resolve this dynamically.
if (tmsServiceConfig.id === TMS_IN_YML_ID) {
const config = this._tilemapsConfig.deprecated.config;
const attrs = _.pick(config, ['url', 'minzoom', 'maxzoom', 'attribution']);
const attrs = _.pick(this._tilemapsConfig, ['url', 'minzoom', 'maxzoom', 'attribution']);
return { ...attrs, ...{ origin: ORIGIN.KIBANA_YML } };
} else {
//assume ems
Expand Down
24 changes: 5 additions & 19 deletions src/plugins/maps_legacy/public/map/service_settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ describe('service_settings (FKA tile_map test)', function () {
};

const defaultTilemapConfig = {
deprecated: {
config: {
options: {},
},
},
options: {},
};

function makeServiceSettings(mapConfigOptions = {}, tilemapOptions = {}) {
Expand Down Expand Up @@ -160,13 +156,8 @@ describe('service_settings (FKA tile_map test)', function () {
serviceSettings = makeServiceSettings(
{},
{
deprecated: {
isOverridden: true,
config: {
url: 'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
options: { minZoom: 0, maxZoom: 20 },
},
},
url: 'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
options: { minZoom: 0, maxZoom: 20 },
}
);

Expand Down Expand Up @@ -251,13 +242,8 @@ describe('service_settings (FKA tile_map test)', function () {
includeElasticMapsService: false,
},
{
deprecated: {
isOverridden: true,
config: {
url: 'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
options: { minZoom: 0, maxZoom: 20 },
},
},
url: 'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
options: { minZoom: 0, maxZoom: 20 },
}
);
const tilemapServices = await serviceSettings.getTMSServices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,8 @@ describe('RegionMapsVisualizationTests', function () {
emsLandingPageUrl: '',
};
const tilemapsConfig = {
deprecated: {
config: {
options: {
attribution: '123',
},
},
options: {
attribution: '123',
},
};
const serviceSettings = new ServiceSettings(mapConfig, tilemapsConfig);
Expand Down
9 changes: 0 additions & 9 deletions src/plugins/tile_map/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
url: schema.maybe(schema.string()),
deprecated: schema.any({
defaultValue: {
config: {
options: {
attribution: '',
},
},
},
}),
options: schema.object({
attribution: schema.string({ defaultValue: '' }),
minZoom: schema.number({ defaultValue: 0, min: 0 }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,8 @@ describe('CoordinateMapsVisualizationTest', function () {
emsLandingPageUrl: '',
};
const tilemapsConfig = {
deprecated: {
config: {
options: {
attribution: '123',
},
},
options: {
attribution: '123',
},
};

Expand Down
1 change: 0 additions & 1 deletion src/plugins/tile_map/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { configSchema, ConfigSchema } from '../config';
export const config: PluginConfigDescriptor<ConfigSchema> = {
exposeToBrowser: {
url: true,
deprecated: true,
options: true,
},
schema: configSchema,
Expand Down

0 comments on commit e319582

Please sign in to comment.