Skip to content

Commit

Permalink
Fix TMS not loaded in legacy maps (elastic#73570)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	src/plugins/maps_legacy/public/map/service_settings.js
#	src/plugins/maps_legacy/public/map/service_settings.test.js
#	src/plugins/region_map/public/__tests__/region_map_visualization.js
#	src/plugins/tile_map/config.ts
#	src/plugins/tile_map/public/__tests__/coordinate_maps_visualization.js
#	src/plugins/tile_map/server/index.ts
  • Loading branch information
Aaron Caldwell committed Aug 4, 2020
1 parent 6af4277 commit ce8d2c5
Show file tree
Hide file tree
Showing 6 changed files with 857 additions and 31 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 @@ -32,6 +32,7 @@ export class ServiceSettings {
this.mapConfig = getInjectedVar('mapConfig');
this.tilemapsConfig = getInjectedVar('tilemapsConfig');
const kbnVersion = getInjectedVar('version');
this._hasTmsConfigured = typeof this.tilemapsConfig.url === 'string' && this.tilemapsConfig.url !== '';

this._showZoomMessage = true;
this._emsClient = new EMSClient({
Expand All @@ -55,13 +56,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 @@ -124,7 +122,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 @@ -212,14 +210,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
25 changes: 5 additions & 20 deletions src/plugins/maps_legacy/public/map/service_settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import EMS_TILES from '../__tests__/map/ems_mocks/sample_tiles.json';
import EMS_STYLE_ROAD_MAP_BRIGHT from '../__tests__/map/ems_mocks/sample_style_bright';
import EMS_STYLE_ROAD_MAP_DESATURATED from '../__tests__/map/ems_mocks/sample_style_desaturated';
import EMS_STYLE_DARK_MAP from '../__tests__/map/ems_mocks/sample_style_dark';
import { ORIGIN } from '../common/constants/origin';
import { ServiceSettings } from './service_settings';

describe('service_settings (FKA tile_map test)', function () {
Expand All @@ -53,11 +52,7 @@ describe('service_settings (FKA tile_map test)', function () {
};

const defaultTilemapConfig = {
deprecated: {
config: {
options: {},
},
},
options: {},
};
getInjectedVarFunc.mockImplementation(() => {
return (param) => {
Expand Down Expand Up @@ -176,13 +171,8 @@ describe('service_settings (FKA tile_map test)', function () {

it('should merge in tilemap url', async () => {
tilemapConfigOptions = {
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 },
};
serviceSettings = makeServiceSettings();

Expand Down Expand Up @@ -266,13 +256,8 @@ describe('service_settings (FKA tile_map test)', function () {
includeElasticMapsService: false,
};
tilemapConfigOptions = {
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 },
};
serviceSettings = makeServiceSettings();
const tilemapServices = await serviceSettings.getTMSServices();
Expand Down
Loading

0 comments on commit ce8d2c5

Please sign in to comment.