Skip to content

Commit

Permalink
add vector source for layers in kibana.yml
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 b9a0d80 commit 61d6d84
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 19 deletions.
17 changes: 16 additions & 1 deletion x-pack/plugins/gis/public/components/gis_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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 { KbnYmlVectorSource } from '../sources/kbnyml_vector_source';

import { TileLayer } from '../layers/tile_layer';
import { VectorLayer } from '../layers/vector_layer';
Expand Down Expand Up @@ -46,7 +47,8 @@ export class GISApp extends React.Component {
const tmsLayer = new TileLayer(kbnymlTmsSource);
await this._kbnMap.addLayer(tmsLayer);
} catch(e) {
console.warn('no valid tms configuration in yml');
console.error(e);
console.warn('Missing map.tilemap configuration in yml');
}

const vectorSource = new EMSVectorSource({
Expand All @@ -58,6 +60,19 @@ export class GISApp extends React.Component {
await this._kbnMap.addLayer(vectorLayer);


try {
const vectorSource = new KbnYmlVectorSource({
layerName: "foobar (self hosted)",
kbnCoreAPI: this.props.kbnCoreAPI
});

const vectorLayer = new VectorLayer(vectorSource);
await this._kbnMap.addLayer(vectorLayer);
} catch(e) {
console.error(e);
console.warn('Missing regionmap configuration in yml');
}

}


Expand Down
23 changes: 5 additions & 18 deletions x-pack/plugins/gis/public/sources/ems_vector_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ASource } from './source';
import { AVectorSource } from './vector_source';

export class EMSVectorSource extends ASource {
export class EMSVectorSource extends AVectorSource {

constructor(options) {
super();
this._kbnCoreAPI = options.kbnCoreAPI;
this._layerName = options.layerName;
super(options);
}

getDisplayName() {
return `EMS: ${this._layerName}`;
}

async getGeoJsonFeatureCollection() {

const files = await this._kbnCoreAPI.serviceSettings.getFileLayers();
const layer = files.find((file) => {
return file.name === this._layerName;
});

if (layer.format && layer.format !== "geojson") {
throw new Error('Only geojson is implemented now');
}

const response = await fetch(layer.url);
return response.json();
async getAvailableLayers() {
return await this._kbnCoreAPI.serviceSettings.getFileLayers();
}
}
20 changes: 20 additions & 0 deletions x-pack/plugins/gis/public/sources/kbnyml_vector_source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { AVectorSource } from './vector_source';

export class KbnYmlVectorSource extends AVectorSource {

constructor(options) {
super(options);
}

async getAvailableLayers() {
return this._kbnCoreAPI.mapConfig.regionmap.layers;
}


}
1 change: 1 addition & 0 deletions x-pack/plugins/gis/public/sources/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export class ASource {
}

}

54 changes: 54 additions & 0 deletions x-pack/plugins/gis/public/sources/vector_source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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';

export class AVectorSource extends ASource {

constructor(options) {
super(options);
this._kbnCoreAPI = options.kbnCoreAPI;
this._layerName = options.layerName;
}

getDisplayName() {
return this._layerName;
}

async getAvailableLayers() {
return [];
}

async getGeoJsonFeatureCollection() {

const files = await this.getAvailableLayers();
const layer = files.find((file) => {
return file.name === this._layerName;
});

if (!layer) {
return null;
}

if (layer.format) {
if (
(layer.format.type && layer.format.type !== 'geojson') ||
(!layer.format.type && layer.format !== 'geojson')
) {
console.log('is not geojson');
throw new Error('Only geojson is implemented now');
}
}

const response = await fetch(layer.url);
return response.json();

}


}

0 comments on commit 61d6d84

Please sign in to comment.