mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
This commit is contained in:
parent
11e02d144f
commit
a64ea796be
3 changed files with 34 additions and 11 deletions
|
@ -115,6 +115,10 @@ export class EMSClient {
|
|||
|
||||
}
|
||||
|
||||
getDefaultLocale() {
|
||||
return DEFAULT_LANGUAGE;
|
||||
}
|
||||
|
||||
getLocale() {
|
||||
return this._language;
|
||||
}
|
||||
|
|
|
@ -29,33 +29,38 @@ export class TMSService {
|
|||
this._emsClient = emsClient;
|
||||
}
|
||||
|
||||
_getFormatsOfType(type) {
|
||||
const formats = this._config.formats.filter(format => {
|
||||
const language = this._emsClient.getLocale();
|
||||
return format.locale === language && format.format === type;
|
||||
_getRasterFormats(locale) {
|
||||
return this._config.formats.filter(format => {
|
||||
return format.locale === locale && format.format === 'raster';
|
||||
});
|
||||
return formats;
|
||||
}
|
||||
|
||||
_getDefaultStyleUrl() {
|
||||
const defaultStyle = this._getFormatsOfType('raster')[0];
|
||||
let rasterFormats = this._getRasterFormats(this._emsClient.getLocale());
|
||||
if (!rasterFormats.length) {//fallback to default locale
|
||||
rasterFormats = this._getRasterFormats(this._emsClient.getDefaultLocale());
|
||||
}
|
||||
if (!rasterFormats.length) {
|
||||
throw new Error(`Cannot find raster tile layer for locale ${this._emsClient.getLocale()} or ${this._emsClient.getDefaultLocale()}`);
|
||||
}
|
||||
const defaultStyle = rasterFormats[0];
|
||||
if (defaultStyle && defaultStyle.hasOwnProperty('url')) {
|
||||
return defaultStyle.url;
|
||||
}
|
||||
}
|
||||
|
||||
async getUrlTemplate() {
|
||||
const tileJson = await this._getTileJson(this._getDefaultStyleUrl());
|
||||
const defaultStyle = this._getDefaultStyleUrl();
|
||||
const tileJson = await this._getTileJson(defaultStyle);
|
||||
return this._emsClient.extendUrlWithParams(tileJson.tiles[0]);
|
||||
}
|
||||
|
||||
getDisplayName() {
|
||||
const serviceName = this._emsClient.getValueInLanguage(this._config.name);
|
||||
return serviceName;
|
||||
return this._emsClient.getValueInLanguage(this._config.name);
|
||||
}
|
||||
|
||||
getAttributions() {
|
||||
const attributions = this._config.attribution.map(attribution => {
|
||||
return this._config.attribution.map(attribution => {
|
||||
const url = this._emsClient.getValueInLanguage(attribution.url);
|
||||
const label = this._emsClient.getValueInLanguage(attribution.label);
|
||||
return {
|
||||
|
@ -63,7 +68,6 @@ export class TMSService {
|
|||
label: label
|
||||
};
|
||||
});
|
||||
return attributions;
|
||||
}
|
||||
|
||||
getHTMLAttribution() {
|
||||
|
|
|
@ -39,8 +39,23 @@ describe('ems_client', () => {
|
|||
expect (await tileService.getMaxZoom()).to.be(10);
|
||||
expect (tileService.hasId('road_map')).to.be(true);
|
||||
|
||||
});
|
||||
|
||||
it('tile service- localized (fallback)', async () => {
|
||||
const emsClient = getEMSClient({
|
||||
language: 'zz'//madeup
|
||||
});
|
||||
const tiles = await emsClient.getTMSServices();
|
||||
|
||||
expect(tiles.length).to.be(3);
|
||||
|
||||
const tileService = tiles[0];
|
||||
expect(await tileService.getUrlTemplate()).to.be('https://raster-style.foobar/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=7.x.x');
|
||||
|
||||
expect (tileService.getHTMLAttribution()).to.be('<p><a rel="noreferrer noopener" href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a> | <a rel="noreferrer noopener" href="https://openmaptiles.org">OpenMapTiles</a> | <a rel="noreferrer noopener" href="https://www.maptiler.com">MapTiler</a> | <a rel="noreferrer noopener" href="https://www.elastic.co/elastic-maps-service">Elastic Maps Service</a></p>');
|
||||
expect (await tileService.getMinZoom()).to.be(0);
|
||||
expect (await tileService.getMaxZoom()).to.be(10);
|
||||
expect (tileService.hasId('road_map')).to.be(true);
|
||||
});
|
||||
|
||||
it('.addQueryParams', async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue