Skip to content

Commit a9b9b7f

Browse files
author
Liza K
committed
Merge branch 'master' of github.com:elastic/kibana into search/error-alignment
2 parents f3b5e62 + 846300d commit a9b9b7f

File tree

45 files changed

+429
-333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+429
-333
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { lazyLoadMapsLegacyModules } from './lazy_load_bundle';
21+
// @ts-expect-error
22+
import { getMapsLegacyConfig } from './kibana_services';
23+
import { IServiceSettings } from './map/service_settings_types';
24+
25+
let loadPromise: Promise<IServiceSettings>;
26+
27+
export async function getServiceSettings(): Promise<IServiceSettings> {
28+
if (typeof loadPromise !== 'undefined') {
29+
return loadPromise;
30+
}
31+
32+
loadPromise = new Promise(async (resolve) => {
33+
const modules = await lazyLoadMapsLegacyModules();
34+
const config = getMapsLegacyConfig();
35+
// @ts-expect-error
36+
resolve(new modules.ServiceSettings(config, config.tilemap));
37+
});
38+
return loadPromise;
39+
}

src/plugins/maps_legacy/public/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
// @ts-ignore
2121
import { PluginInitializerContext } from 'kibana/public';
22-
// @ts-ignore
23-
import { L } from './leaflet';
2422
import { MapsLegacyPlugin } from './plugin';
2523
// @ts-ignore
2624
import * as colorUtil from './map/color_util';
@@ -29,14 +27,14 @@ import { KibanaMapLayer } from './map/kibana_map_layer';
2927
// @ts-ignore
3028
import { convertToGeoJson } from './map/convert_to_geojson';
3129
// @ts-ignore
32-
import { scaleBounds, getPrecision, geoContains } from './map/decode_geo_hash';
30+
import { getPrecision, geoContains } from './map/decode_geo_hash';
3331
import {
3432
VectorLayer,
3533
FileLayerField,
3634
FileLayer,
3735
TmsLayer,
3836
IServiceSettings,
39-
} from './map/service_settings';
37+
} from './map/service_settings_types';
4038
// @ts-ignore
4139
import { mapTooltipProvider } from './tooltip_provider';
4240

@@ -48,7 +46,6 @@ export function plugin(initializerContext: PluginInitializerContext) {
4846

4947
/** @public */
5048
export {
51-
scaleBounds,
5249
getPrecision,
5350
geoContains,
5451
colorUtil,
@@ -60,13 +57,14 @@ export {
6057
FileLayer,
6158
TmsLayer,
6259
mapTooltipProvider,
63-
L,
6460
};
6561

6662
export * from './common/types';
6763
export { ORIGIN } from './common/constants/origin';
6864

6965
export { WmsOptions } from './components/wms_options';
7066

67+
export { lazyLoadMapsLegacyModules } from './lazy_load_bundle';
68+
7169
export type MapsLegacyPluginSetup = ReturnType<MapsLegacyPlugin['setup']>;
7270
export type MapsLegacyPluginStart = ReturnType<MapsLegacyPlugin['start']>;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
let loadModulesPromise: Promise<LazyLoadedMapsLegacyModules>;
21+
22+
interface LazyLoadedMapsLegacyModules {
23+
KibanaMap: unknown;
24+
L: unknown;
25+
ServiceSettings: unknown;
26+
}
27+
28+
export async function lazyLoadMapsLegacyModules(): Promise<LazyLoadedMapsLegacyModules> {
29+
if (typeof loadModulesPromise !== 'undefined') {
30+
return loadModulesPromise;
31+
}
32+
33+
loadModulesPromise = new Promise(async (resolve) => {
34+
const { KibanaMap, L, ServiceSettings } = await import('./lazy');
35+
36+
resolve({
37+
KibanaMap,
38+
L,
39+
ServiceSettings,
40+
});
41+
});
42+
return loadModulesPromise;
43+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
// @ts-expect-error
21+
export { KibanaMap } from '../../map/kibana_map';
22+
// @ts-expect-error
23+
export { ServiceSettings } from '../../map/service_settings';
24+
// @ts-expect-error
25+
export { L } from '../../leaflet';

src/plugins/maps_legacy/public/map/base_maps_visualization.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,22 @@
1717
* under the License.
1818
*/
1919

20-
import _ from 'lodash';
2120
import { i18n } from '@kbn/i18n';
2221
import * as Rx from 'rxjs';
2322
import { filter, first } from 'rxjs/operators';
2423
import { getEmsTileLayerId, getUiSettings, getToasts } from '../kibana_services';
24+
import { lazyLoadMapsLegacyModules } from '../lazy_load_bundle';
25+
import { getServiceSettings } from '../get_service_settings';
2526

2627
const WMS_MINZOOM = 0;
2728
const WMS_MAXZOOM = 22; //increase this to 22. Better for WMS
2829

29-
export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings) {
30+
export function BaseMapsVisualizationProvider() {
3031
/**
3132
* Abstract base class for a visualization consisting of a map with a single baselayer.
3233
* @class BaseMapsVisualization
3334
* @constructor
3435
*/
35-
36-
const serviceSettings = mapServiceSettings;
37-
const toastService = getToasts();
38-
3936
return class BaseMapsVisualization {
4037
constructor(element, vis) {
4138
this.vis = vis;
@@ -95,9 +92,9 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
9592
const centerFromUIState = uiState.get('mapCenter');
9693
options.zoom = !isNaN(zoomFromUiState) ? zoomFromUiState : this.vis.params.mapZoom;
9794
options.center = centerFromUIState ? centerFromUIState : this.vis.params.mapCenter;
98-
const services = { toastService };
9995

100-
this._kibanaMap = getKibanaMap(this._container, options, services);
96+
const modules = await lazyLoadMapsLegacyModules();
97+
this._kibanaMap = new modules.KibanaMap(this._container, options);
10198
this._kibanaMap.setMinZoom(WMS_MINZOOM); //use a default
10299
this._kibanaMap.setMaxZoom(WMS_MAXZOOM); //use a default
103100

@@ -138,6 +135,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
138135
const mapParams = this._getMapsParams();
139136
if (!this._tmsConfigured()) {
140137
try {
138+
const serviceSettings = await getServiceSettings();
141139
const tmsServices = await serviceSettings.getTMSServices();
142140
const userConfiguredTmsLayer = tmsServices[0];
143141
const initBasemapLayer = userConfiguredTmsLayer
@@ -147,7 +145,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
147145
this._setTmsLayer(initBasemapLayer);
148146
}
149147
} catch (e) {
150-
toastService.addWarning(e.message);
148+
getToasts().addWarning(e.message);
151149
return;
152150
}
153151
return;
@@ -174,7 +172,7 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
174172
this._setTmsLayer(selectedTmsLayer);
175173
}
176174
} catch (tmsLoadingError) {
177-
toastService.addWarning(tmsLoadingError.message);
175+
getToasts().addWarning(tmsLoadingError.message);
178176
}
179177
}
180178

@@ -189,13 +187,14 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
189187
isDesaturated = true;
190188
}
191189
const isDarkMode = getUiSettings().get('theme:darkMode');
190+
const serviceSettings = await getServiceSettings();
192191
const meta = await serviceSettings.getAttributesForTMSLayer(
193192
tmsLayer,
194193
isDesaturated,
195194
isDarkMode
196195
);
197196
const showZoomMessage = serviceSettings.shouldShowZoomMessage(tmsLayer);
198-
const options = _.cloneDeep(tmsLayer);
197+
const options = { ...tmsLayer };
199198
delete options.id;
200199
delete options.subdomains;
201200
this._kibanaMap.setBaseLayer({
@@ -228,12 +227,11 @@ export function BaseMapsVisualizationProvider(getKibanaMap, mapServiceSettings)
228227
}
229228

230229
_getMapsParams() {
231-
return _.assign(
232-
{},
233-
this.vis.type.visConfig.defaults,
234-
{ type: this.vis.type.name },
235-
this._params
236-
);
230+
return {
231+
...this.vis.type.visConfig.defaults,
232+
type: this.vis.type.name,
233+
...this._params,
234+
};
237235
}
238236

239237
_whenBaseLayerIsLoaded() {

src/plugins/maps_legacy/public/map/decode_geo_hash.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import _ from 'lodash';
21-
2220
interface DecodedGeoHash {
2321
latitude: number[];
2422
longitude: number[];
@@ -101,33 +99,6 @@ interface GeoBoundingBox {
10199
bottom_right: GeoBoundingBoxCoordinate;
102100
}
103101

104-
export function scaleBounds(bounds: GeoBoundingBox): GeoBoundingBox {
105-
const scale = 0.5; // scale bounds by 50%
106-
107-
const topLeft = bounds.top_left;
108-
const bottomRight = bounds.bottom_right;
109-
let latDiff = _.round(Math.abs(topLeft.lat - bottomRight.lat), 5);
110-
const lonDiff = _.round(Math.abs(bottomRight.lon - topLeft.lon), 5);
111-
// map height can be zero when vis is first created
112-
if (latDiff === 0) latDiff = lonDiff;
113-
114-
const latDelta = latDiff * scale;
115-
let topLeftLat = _.round(topLeft.lat, 5) + latDelta;
116-
if (topLeftLat > 90) topLeftLat = 90;
117-
let bottomRightLat = _.round(bottomRight.lat, 5) - latDelta;
118-
if (bottomRightLat < -90) bottomRightLat = -90;
119-
const lonDelta = lonDiff * scale;
120-
let topLeftLon = _.round(topLeft.lon, 5) - lonDelta;
121-
if (topLeftLon < -180) topLeftLon = -180;
122-
let bottomRightLon = _.round(bottomRight.lon, 5) + lonDelta;
123-
if (bottomRightLon > 180) bottomRightLon = 180;
124-
125-
return {
126-
top_left: { lat: topLeftLat, lon: topLeftLon },
127-
bottom_right: { lat: bottomRightLat, lon: bottomRightLon },
128-
};
129-
}
130-
131102
export function geoContains(collar?: GeoBoundingBox, bounds?: GeoBoundingBox) {
132103
if (!bounds || !collar) return false;
133104
// test if bounds top_left is outside collar

src/plugins/maps_legacy/public/map/grid_dimensions.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import _ from 'lodash';
21-
2220
// geohash precision mapping of geohash grid cell dimensions (width x height, in meters) at equator.
2321
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html#_cell_dimensions_at_the_equator
2422
const gridAtEquator = {
@@ -37,5 +35,5 @@ const gridAtEquator = {
3735
};
3836

3937
export function gridDimensions(precision) {
40-
return _.get(gridAtEquator, precision);
38+
return gridAtEquator[precision];
4139
}

src/plugins/maps_legacy/public/map/kibana_map.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import { EventEmitter } from 'events';
2121
import { createZoomWarningMsg } from './map_messages';
2222
import $ from 'jquery';
23-
import _ from 'lodash';
23+
import { get, isEqual, escape } from 'lodash';
2424
import { zoomToPrecision } from './zoom_to_precision';
2525
import { i18n } from '@kbn/i18n';
2626
import { ORIGIN } from '../common/constants/origin';
@@ -380,7 +380,7 @@ export class KibanaMap extends EventEmitter {
380380

381381
const distanceX = latLngC.distanceTo(latLngX); // calculate distance between c and x (latitude)
382382
const distanceY = latLngC.distanceTo(latLngY); // calculate distance between c and y (longitude)
383-
return _.min([distanceX, distanceY]);
383+
return Math.min(distanceX, distanceY);
384384
}
385385

386386
_getLeafletBounds(resizeOnFail) {
@@ -544,7 +544,7 @@ export class KibanaMap extends EventEmitter {
544544
}
545545

546546
setBaseLayer(settings) {
547-
if (_.isEqual(settings, this._baseLayerSettings)) {
547+
if (isEqual(settings, this._baseLayerSettings)) {
548548
return;
549549
}
550550

@@ -567,7 +567,7 @@ export class KibanaMap extends EventEmitter {
567567
let baseLayer;
568568
if (settings.baseLayerType === 'wms') {
569569
//This is user-input that is rendered with the Leaflet attribution control. Needs to be sanitized.
570-
this._baseLayerSettings.options.attribution = _.escape(settings.options.attribution);
570+
this._baseLayerSettings.options.attribution = escape(settings.options.attribution);
571571
baseLayer = this._getWMSBaseLayer(settings.options);
572572
} else if (settings.baseLayerType === 'tms') {
573573
baseLayer = this._getTMSBaseLayer(settings.options);
@@ -661,7 +661,7 @@ export class KibanaMap extends EventEmitter {
661661
_updateDesaturation() {
662662
const tiles = $('img.leaflet-tile-loaded');
663663
// Don't apply client-side styling to EMS basemaps
664-
if (_.get(this._baseLayerSettings, 'options.origin') === ORIGIN.EMS) {
664+
if (get(this._baseLayerSettings, 'options.origin') === ORIGIN.EMS) {
665665
tiles.addClass('filters-off');
666666
} else {
667667
if (this._baseLayerIsDesaturated) {

0 commit comments

Comments
 (0)