Skip to content

Commit

Permalink
Use Kibana locale when loading content from the Elastic Maps Service (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck authored Feb 5, 2019
1 parent 8006e43 commit c412915
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/legacy/core_plugins/tile_map/common/ems_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ const unescapeTemplateVars = url => {
};


//this is not the default locale from Kibana, but the default locale supported by the Elastic Maps Service
const DEFAULT_LANGUAGE = 'en';



export class EMSClientV66 {

EMS_LOAD_TIMEOUT = 32000;
Expand All @@ -107,13 +106,16 @@ export class EMSClientV66 {
this._manifestServiceUrl = manifestServiceUrl;
this._loadFileLayers = null;
this._loadTMSServices = null;
this._emsLandingPageUrl = landingPageUrl;
this._emsLandingPageUrl = typeof landingPageUrl === 'string' ? landingPageUrl : '';
this._language = typeof language === 'string' ? language : DEFAULT_LANGUAGE;

this._invalidateSettings();

}

getLocale() {
return this._language;
}

getValueInLanguage(i18nObject) {
if (!i18nObject) {
Expand Down
11 changes: 9 additions & 2 deletions src/legacy/core_plugins/tile_map/common/file_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


import { ORIGIN } from './origin';
import url from 'url';

export class FileLayer {

Expand Down Expand Up @@ -84,8 +85,14 @@ export class FileLayer {
}

getEMSHotLink() {
const id = `file/${this.getId()}`;
return `${this._emsClient.getLandingPageUrl()}#${id}`;
const landingPageString = this._emsClient.getLandingPageUrl();
const urlObject = url.parse(landingPageString);
urlObject.hash = `file/${this.getId()}`;
urlObject.query = {
...urlObject.query,
locale: this._emsClient.getLocale()
};
return url.format(urlObject);
}

getDefaultFormatType() {
Expand Down
2 changes: 1 addition & 1 deletion src/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export default () => Joi.object({
tilemap: tilemapSchema,
regionmap: regionmapSchema,
manifestServiceUrl: Joi.string().default('https://catalogue.maps.elastic.co/v6.6/manifest'),
emsLandingPageUrl: Joi.string().default('https://maps.elastic.co/v6.6'),
emsLandingPageUrl: Joi.string().default('https://maps.elastic.co/v6.7'),
}).default(),
tilemap: tilemapSchema.notes('Deprecated'),
regionmap: regionmapSchema.notes('Deprecated'),
Expand Down
3 changes: 2 additions & 1 deletion src/ui/public/vis/__tests__/map/ems_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('ems_client', () => {
{ name: 'name', description: 'name', type: 'property' } ]);


expect((await layer.getEMSHotLink())).to.be('https://landing.foobar#file/world_countries');
expect((await layer.getEMSHotLink())).to.be('https://landing.foobar/?locale=zz#file/world_countries');

});

Expand All @@ -182,6 +182,7 @@ describe('ems_client', () => {
function getEMSClient(options = {}) {

const emsClient = new EMSClientV66({
language: 'en',
kbnVersion: '6.x.x',
manifestServiceUrl: 'https://foobar',
htmlSanitizer: x => x,
Expand Down
3 changes: 1 addition & 2 deletions src/ui/public/vis/__tests__/map/service_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,9 @@ describe('service_settings (FKA tilemaptest)', function () {
});

it ('should get hotlink', async () => {
mapConfig.emsLandingPageUrl = 'https://foo/bar';
const fileLayers = await serviceSettings.getFileLayers();
const hotlink = await serviceSettings.getEMSHotLink(fileLayers[0]);
expect(hotlink).to.eql('undefined#file/world_countries');//undefined becuase emsLandingPageUrl is set at kibana-load
expect(hotlink).to.eql('?locale=en#file/world_countries');//url host undefined becuase emsLandingPageUrl is set at kibana-load

});

Expand Down
2 changes: 2 additions & 0 deletions src/ui/public/vis/map/service_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import _ from 'lodash';
import MarkdownIt from 'markdown-it';
import { ORIGIN } from '../../../../legacy/core_plugins/tile_map/common/origin';
import { EMSClientV66 } from '../../../../legacy/core_plugins/tile_map/common/ems_client';
import { i18n } from '@kbn/i18n';

const markdownIt = new MarkdownIt({
html: false,
Expand All @@ -43,6 +44,7 @@ uiModules.get('kibana')
this._showZoomMessage = true;

this._emsClient = new EMSClientV66({
language: i18n.getLocale(),
kbnVersion: kbnVersion,
manifestServiceUrl: mapConfig.manifestServiceUrl,
htmlSanitizer: $sanitize,
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/maps/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { GIS_API_PATH } from '../common/constants';
import fetch from 'node-fetch';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';

const ROOT = `/${GIS_API_PATH}`;

Expand All @@ -17,6 +18,7 @@ export function initRoutes(server, licenseUid) {
const mapConfig = serverConfig.get('map');

const emsClient = new server.plugins.tile_map.ems_client.EMSClientV66({
language: i18n.getLocale(),
kbnVersion: serverConfig.get('pkg.version'),
manifestServiceUrl: mapConfig.manifestServiceUrl,
landingPageUrl: mapConfig.emsLandingPageUrl
Expand Down

0 comments on commit c412915

Please sign in to comment.