Skip to content

Commit

Permalink
add source for kbn yml tilemap configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck authored and Aaron Caldwell committed Jun 12, 2018
1 parent 646f0de commit b9a0d80
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
20 changes: 16 additions & 4 deletions x-pack/plugins/gis/public/components/gis_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import React from 'react';
import { KibanaMap } from './kibana_map';
import { LayerControl } from './layer_control';

import { TMSSource } from '../sources/tms_source';
import { EMSVectorSource } from '../sources/ems_vector_source';
import { EMSTMSSource } from '../sources/ems_tms_source';
import { KbnYmlTMSSource } from '../sources/kbnyml_tms_source';

import { TileLayer } from '../layers/tile_layer';
import { VectorLayer } from '../layers/vector_layer';

Expand All @@ -25,17 +28,26 @@ export class GISApp extends React.Component {
async _createPlaceholders() {

//todo: some hardcoded example layers
const defaultEmsTMSSource = new EMSTMSSource({
const emsTMSSource = new EMSTMSSource({
kbnCoreAPI: this.props.kbnCoreAPI,
serviceId: "road_map"
});
const tmsLayer = new TileLayer(defaultEmsTMSSource);
const tmsLayer = new TileLayer(emsTMSSource);
await this._kbnMap.addLayer(tmsLayer);
const osmSource = new TMSSource({
urlTemplate: "https://a.tile.openstreetmap.org/{z}/{x}/{y}.png"
});
const tmsLayer2 = new TileLayer(osmSource);
await this._kbnMap.addLayer(tmsLayer2);

const omsLayer = new TileLayer(osmSource);
await this._kbnMap.addLayer(omsLayer);

try {
const kbnymlTmsSource = new KbnYmlTMSSource({ kbnCoreAPI: this.props.kbnCoreAPI });
const tmsLayer = new TileLayer(kbnymlTmsSource);
await this._kbnMap.addLayer(tmsLayer);
} catch(e) {
console.warn('no valid tms configuration in yml');
}

const vectorSource = new EMSVectorSource({
kbnCoreAPI: this.props.kbnCoreAPI,
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/gis/public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ uiModules
.get('kibana')
.run((Private, $injector) => {
const serviceSettings = $injector.get('serviceSettings');
const mapConfig = $injector.get('mapConfig');
kbnCoreAPI = {
serviceSettings: serviceSettings
serviceSettings: serviceSettings,
mapConfig: mapConfig
};
});

Expand Down
33 changes: 33 additions & 0 deletions x-pack/plugins/gis/public/sources/kbnyml_tms_source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { ASource } from './source';
import { parse as parseUrl } from 'url';

/**
* There's only single TMS configuration in kibana.yml
*/
export class KbnYmlTMSSource extends ASource {

constructor(options) {
super();
this._kbnCoreAPI = options.kbnCoreAPI;
this._urlTemplate = (this._kbnCoreAPI.mapConfig.tilemap && this._kbnCoreAPI.mapConfig.tilemap.url) ?
this._kbnCoreAPI.mapConfig.tilemap.url : null;
}

getDisplayName() {
const parsedUrl = parseUrl(this._urlTemplate);
return parsedUrl.hostname;
}

async getUrlTemplate() {
if (!this._kbnCoreAPI.mapConfig.tilemap || !this._kbnCoreAPI.mapConfig.tilemap.url) {
throw new Error('no tilemap configuration');
}
return this._urlTemplate;
}
}

0 comments on commit b9a0d80

Please sign in to comment.