Skip to content

Commit

Permalink
moved tilemap config from kibana.yml to settings -> advanced. fixes e…
Browse files Browse the repository at this point in the history
  • Loading branch information
jayeshmori committed Aug 3, 2016
1 parent 6d890ad commit 7f54d21
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/core_plugins/kbn_vislib_vis_types/public/tile_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default function TileMapVisType(Private, getAppState, courier, config) {
heatNormalizeData: true,
mapZoom: 2,
mapCenter: [15, 5],
wms: config.get('visualization:tileMap:WMSdefaults')
wms: config.get('visualization:tileMap:WMSdefaults'),
tms: config.get('visualization:tileMap:TMSdefaults')
},
mapTypes: ['Scaled Circle Markers', 'Shaded Circle Markers', 'Shaded Geohash Grid', 'Heatmap'],
canDesaturate: !!supports.cssFilters,
Expand Down
3 changes: 1 addition & 2 deletions src/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ module.exports = function (kibana) {
injectVars: function (server, options) {
let config = server.config();
return {
kbnDefaultAppId: config.get('kibana.defaultAppId'),
tilemap: config.get('tilemap')
kbnDefaultAppId: config.get('kibana.defaultAppId')
};
},
},
Expand Down
18 changes: 18 additions & 0 deletions src/fixtures/vislib/_tilemap_tms_fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
"attr": {
"tms": {
"url": "https://tiles.elastic.co/v1/default/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=1.2.3",
"options": {
"attribution": "© [Elastic Tile Service](https://www.elastic.co/elastic_tile_service_tos)",
"subdomains": "1234",
"minZoom": 1,
"maxZoom": 7,
"tileSize": 256,
"errorTileUrl": "",
"tms": false,
"reuseTiles": false,
"bounds": [[180,180],[0,0]]
}
}
}
}
15 changes: 0 additions & 15 deletions src/server/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,6 @@ module.exports = () => Joi.object({

status: Joi.object({
allowAnonymous: Joi.boolean().default(false)
}).default(),

tilemap: Joi.object({
url: Joi.string().default(`https://tiles.elastic.co/v1/default/{z}/{x}/{y}.png?my_app_name=kibana&my_app_version=${pkg.version}&elastic_tile_service_tos=agree`),
options: Joi.object({
attribution: Joi.string().default('© [Elastic Tile Service](https://www.elastic.co/elastic-tile-service)'),
minZoom: Joi.number().min(1, 'Must not be less than 1').default(1),
maxZoom: Joi.number().default(10),
tileSize: Joi.number(),
subdomains: Joi.array().items(Joi.string()).single(),
errorTileUrl: Joi.string().uri(),
tms: Joi.boolean(),
reuseTiles: Joi.boolean(),
bounds: Joi.array().items(Joi.array().items(Joi.number()).min(2).required()).min(2)
}).default()
}).default()

}).default();
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import L from 'leaflet';

import sinon from 'auto-release-sinon';
import geoJsonData from 'fixtures/vislib/mock_data/geohash/_geo_json';
import tileMapServiceConfig from 'fixtures/vislib/_tilemap_tms_fixture';
import $ from 'jquery';
import VislibVisualizationsMapProvider from 'ui/vislib/visualizations/_map';

Expand Down Expand Up @@ -75,7 +76,7 @@ describe('TileMap Map Tests', function () {
attachEvents: sinon.stub(TileMapMap.prototype, '_attachEvents'),
addMarkers: sinon.stub(TileMapMap.prototype, '_addMarkers'),
};
map = new TileMapMap($mockMapEl, geoJsonData, {});
map = new TileMapMap($mockMapEl, geoJsonData, tileMapServiceConfig);
});

it('should create the create leaflet objects', function () {
Expand Down Expand Up @@ -111,7 +112,6 @@ describe('TileMap Map Tests', function () {

describe('attachEvents', function () {
let map;

beforeEach(function () {
sinon.stub(TileMapMap.prototype, '_createMap', function () {
this._tileLayer = leafletMocks.tileLayer;
Expand Down
29 changes: 12 additions & 17 deletions src/ui/public/vislib/visualizations/_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,12 @@ import VislibVisualizationsMarkerTypesScaledCirclesProvider from 'ui/vislib/visu
import VislibVisualizationsMarkerTypesShadedCirclesProvider from 'ui/vislib/visualizations/marker_types/shaded_circles';
import VislibVisualizationsMarkerTypesGeohashGridProvider from 'ui/vislib/visualizations/marker_types/geohash_grid';
import VislibVisualizationsMarkerTypesHeatmapProvider from 'ui/vislib/visualizations/marker_types/heatmap';
export default function MapFactory(Private, tilemap, $sanitize) {
export default function MapFactory(Private) {

let defaultMapZoom = 2;
let defaultMapCenter = [15, 5];
let defaultMarkerType = 'Scaled Circle Markers';

let tilemapOptions = tilemap.options;
let attribution = $sanitize(marked(tilemapOptions.attribution));

let mapTiles = {
url: tilemap.url,
options: _.assign({}, tilemapOptions, { attribution })
};

let markerTypes = {
'Scaled Circle Markers': Private(VislibVisualizationsMarkerTypesScaledCirclesProvider),
'Shaded Circle Markers': Private(VislibVisualizationsMarkerTypesShadedCirclesProvider),
Expand All @@ -46,18 +38,16 @@ export default function MapFactory(Private, tilemap, $sanitize) {
this._chartData = chartData;

// keep a reference to all of the optional params
this._attr = params.attr || {};
this._events = _.get(params, 'events');
this._markerType = markerTypes[params.markerType] ? params.markerType : defaultMarkerType;
this._valueFormatter = params.valueFormatter || _.identity;
this._tooltipFormatter = params.tooltipFormatter || _.identity;
this._geoJson = _.get(this._chartData, 'geoJson');
this._mapZoom = Math.max(Math.min(params.zoom || defaultMapZoom, tilemapOptions.maxZoom), tilemapOptions.minZoom);
this._mapCenter = params.center || defaultMapCenter;
this._attr = params.attr || {};
this._mapZoom = params.mapZoom || defaultMapZoom;

let mapOptions = {
minZoom: tilemapOptions.minZoom,
maxZoom: tilemapOptions.maxZoom,
noWrap: true,
maxBounds: L.latLngBounds([-90, -220], [90, 220]),
scrollWheelZoom: false,
Expand Down Expand Up @@ -286,10 +276,15 @@ export default function MapFactory(Private, tilemap, $sanitize) {
maxZoom: 18
});
this._tileLayer = L.tileLayer.wms(this._attr.wms.url, this._attr.wms.options);
} else {
this._tileLayer = L.tileLayer(mapTiles.url, mapTiles.options);
} else if (this._attr.tms) {
_.assign(mapOptions, {
minZoom: this._attr.tms.options.minZoom,
maxZoom: this._attr.tms.options.maxZoom
});
// calculate default map zoom level for the tile layer
this._mapZoom = Math.max(Math.min(this._mapZoom, this._attr.tms.options.maxZoom), this._attr.tms.options.minZoom);
this._tileLayer = L.tileLayer(this._attr.tms.url, this._attr.tms.options);
}

// append tile layers, center and zoom to the map options
mapOptions.layers = this._tileLayer;
mapOptions.center = this._mapCenter;
Expand Down Expand Up @@ -322,4 +317,4 @@ export default function MapFactory(Private, tilemap, $sanitize) {
};

return TileMapMap;
};
}
18 changes: 18 additions & 0 deletions src/ui/settings/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ export default function defaultSettingsProvider() {
type: 'json',
description: 'Default <a href="http://leafletjs.com/reference.html#tilelayer-wms" target="_blank">properties</a> for the WMS map server support in the tile map'
},
'visualization:tileMap:TMSdefaults': {
value: JSON.stringify({
url: 'https://tiles.elastic.co/v1/default/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=kibana&my_app_version=1.2.3',
options: {
attribution: '© <a href="https://www.elastic.co/elastic_tile_service_tos">[Elastic Tile Service]</a> ',
subdomains: '1234',
minZoom: 1,
maxZoom: 7,
tileSize: 256,
errorTileUrl: '',
tms: false,
reuseTiles: false,
bounds: null
}
}, null, ' '),
type: 'json',
description: 'Default properties for the map tiles service to use in the tile map visualizations'
},
'visualization:colorMapping': {
type: 'json',
value: JSON.stringify({
Expand Down

0 comments on commit 7f54d21

Please sign in to comment.