From b20d83a3793d3c87af035c0187924b1fb55668b3 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Tue, 18 Aug 2015 12:03:03 -0700 Subject: [PATCH 1/5] Add WMS map server support on a per-map basis --- .../public/editors/tile_map.html | 81 ++++++++++++++++++- .../kbn_vislib_vis_types/public/tileMap.js | 11 +++ src/ui/public/vislib/visualizations/_map.js | 6 +- 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/plugins/kbn_vislib_vis_types/public/editors/tile_map.html b/src/plugins/kbn_vislib_vis_types/public/editors/tile_map.html index 3bdb8d15a705f..7a41c443a00bc 100644 --- a/src/plugins/kbn_vislib_vis_types/public/editors/tile_map.html +++ b/src/plugins/kbn_vislib_vis_types/public/editors/tile_map.html @@ -113,6 +113,85 @@ Desaturate map tiles - + +
+ +
+ +
+
+ +

+ WMS maps are 3rd party mapping services that have not been verified to work with Kibana. + These should be considered expert settings. +

+ + + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +

* if this parameter is incorrect, maps will fail to load.

+ + +
diff --git a/src/plugins/kbn_vislib_vis_types/public/tileMap.js b/src/plugins/kbn_vislib_vis_types/public/tileMap.js index 8a3046561b968..b341f11825ad5 100644 --- a/src/plugins/kbn_vislib_vis_types/public/tileMap.js +++ b/src/plugins/kbn_vislib_vis_types/public/tileMap.js @@ -22,6 +22,17 @@ define(function (require) { heatRadius: 25, heatBlur: 15, heatNormalizeData: true, + wms: { + url: 'http://basemap.nationalmap.gov/arcgis/services/USGSTopo/MapServer/WMSServer', + options: { + version: '1.3.0', + layers: '0,1,2', + format: 'image/png', + transparent: true, + attribution: 'Maps provided by USGS', + styles: '', + } + } }, mapTypes: ['Scaled Circle Markers', 'Shaded Circle Markers', 'Shaded Geohash Grid', 'Heatmap'], canDesaturate: !!supports.cssFilters, diff --git a/src/ui/public/vislib/visualizations/_map.js b/src/ui/public/vislib/visualizations/_map.js index 1078731bd621c..40206856fa8b6 100644 --- a/src/ui/public/vislib/visualizations/_map.js +++ b/src/ui/public/vislib/visualizations/_map.js @@ -264,7 +264,11 @@ define(function (require) { this._mapZoom = _.get(this._geoJson, 'properties.zoom') || defaultMapZoom; // add map tiles layer, using the mapTiles object settings - this._tileLayer = L.tileLayer(mapTiles.url, mapTiles.options); + if (this._attr.isWMS) { + this._tileLayer = L.tileLayer.wms(this._attr.wms.url, this._attr.wms.options); + } else { + this._tileLayer = L.tileLayer(mapTiles.url, mapTiles.options); + } // append tile layers, center and zoom to the map options mapOptions.layers = this._tileLayer; From 7fbce63e0b2808fa66f5be428191745021b3a1a9 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Wed, 19 Aug 2015 15:09:42 -0700 Subject: [PATCH 2/5] Add setting WMS defaults --- .../public/editors/tile_map.html | 10 +++++----- .../kbn_vislib_vis_types/public/tileMap.js | 12 +----------- src/ui/public/config/defaults.js | 16 ++++++++++++++++ src/ui/public/vislib/visualizations/_map.js | 2 +- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/plugins/kbn_vislib_vis_types/public/editors/tile_map.html b/src/plugins/kbn_vislib_vis_types/public/editors/tile_map.html index 7a41c443a00bc..e4b1f6091afc4 100644 --- a/src/plugins/kbn_vislib_vis_types/public/editors/tile_map.html +++ b/src/plugins/kbn_vislib_vis_types/public/editors/tile_map.html @@ -120,8 +120,8 @@
-
+

@@ -150,7 +150,7 @@ WMS layers*

@@ -184,7 +184,7 @@
Date: Wed, 19 Aug 2015 16:07:53 -0700 Subject: [PATCH 3/5] Ensure wms is called when wms is enabled --- .../vislib/__tests__/visualizations/tile_maps/map.js | 10 ++++++++++ src/ui/public/vislib/visualizations/_map.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ui/public/vislib/__tests__/visualizations/tile_maps/map.js b/src/ui/public/vislib/__tests__/visualizations/tile_maps/map.js index 3a276f0d04149..c10ef8dde5dff 100644 --- a/src/ui/public/vislib/__tests__/visualizations/tile_maps/map.js +++ b/src/ui/public/vislib/__tests__/visualizations/tile_maps/map.js @@ -35,6 +35,8 @@ describe('TileMap Map Tests', function () { leafletMocks.tileLayer = { on: sinon.stub() }; leafletMocks.map = { on: sinon.stub() }; leafletStubs.tileLayer = sinon.stub(L, 'tileLayer', _.constant(leafletMocks.tileLayer)); + leafletStubs.tileLayer.wms = sinon.stub(L.tileLayer, 'wms', _.constant(leafletMocks.tileLayer)); + leafletStubs.map = sinon.stub(L, 'map', _.constant(leafletMocks.map)); TileMapMap = Private(require('ui/vislib/visualizations/_map')); @@ -96,6 +98,14 @@ describe('TileMap Map Tests', function () { map._createMap({}); expect(mapStubs.destroy.callCount).to.equal(1); }); + + it('should create a WMS layer if WMS is enabled', function () { + expect(L.tileLayer.wms.called).to.be(false); + map = new TileMapMap($mockMapEl, geoJsonData, {attr: {wms: {enabled: true}}}); + map._createMap({}); + expect(L.tileLayer.wms.called).to.be(true); + L.tileLayer.restore(); + }); }); describe('attachEvents', function () { diff --git a/src/ui/public/vislib/visualizations/_map.js b/src/ui/public/vislib/visualizations/_map.js index 08554e433ecfd..3cdbe743bb10e 100644 --- a/src/ui/public/vislib/visualizations/_map.js +++ b/src/ui/public/vislib/visualizations/_map.js @@ -264,7 +264,7 @@ define(function (require) { this._mapZoom = _.get(this._geoJson, 'properties.zoom') || defaultMapZoom; // add map tiles layer, using the mapTiles object settings - if (this._attr.wms.enabled) { + if (this._attr.wms && this._attr.wms.enabled) { this._tileLayer = L.tileLayer.wms(this._attr.wms.url, this._attr.wms.options); } else { this._tileLayer = L.tileLayer(mapTiles.url, mapTiles.options); From cd6cc6c251ff22a6e46712f3f84c1332290ddf3a Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Tue, 1 Sep 2015 10:38:21 -0700 Subject: [PATCH 4/5] Clone vis type defaults so that editableVis and vis have different copies --- src/ui/public/Vis/Vis.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/public/Vis/Vis.js b/src/ui/public/Vis/Vis.js index cdfddd4246496..79f7b6bcf5d1b 100644 --- a/src/ui/public/Vis/Vis.js +++ b/src/ui/public/Vis/Vis.js @@ -70,7 +70,10 @@ define(function (require) { if (_.isString(this.type)) this.type = visTypes.byName[this.type]; this.listeners = _.assign({}, state.listeners, this.type.listeners); - this.params = _.defaults({}, _.cloneDeep(state.params || {}), this.type.params.defaults || {}); + this.params = _.defaults({}, + _.cloneDeep(state.params || {}), + _.cloneDeep(this.type.params.defaults || {}) + ); this.aggs = new AggConfigs(this, state.aggs); }; From 22269a5ab22812b357b9f7dad51e18eec647df97 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 2 Sep 2015 11:13:12 -0700 Subject: [PATCH 5/5] Change default WMS settings to use https URL instead of http --- src/ui/public/config/defaults.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/public/config/defaults.js b/src/ui/public/config/defaults.js index 0054a125742a6..f1e90f22aadbb 100644 --- a/src/ui/public/config/defaults.js +++ b/src/ui/public/config/defaults.js @@ -80,7 +80,7 @@ define(function () { 'visualization:tileMap:WMSdefaults': { value: JSON.stringify({ enabled: false, - url: 'http://basemap.nationalmap.gov/arcgis/services/USGSTopo/MapServer/WMSServer', + url: 'https://basemap.nationalmap.gov/arcgis/services/USGSTopo/MapServer/WMSServer', options: { version: '1.3.0', layers: '0',