Skip to content

Commit c00b36e

Browse files
author
Aaron Caldwell
authored
Migrate Coordinate Maps to NP (#64668)
1 parent 402df7f commit c00b36e

Some content is hidden

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

67 files changed

+527
-269
lines changed

.i18nrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"src/plugins/telemetry",
4444
"src/plugins/telemetry_management_section"
4545
],
46-
"tileMap": "src/legacy/core_plugins/tile_map",
46+
"tileMap": "src/plugins/tile_map",
4747
"timelion": ["src/legacy/core_plugins/timelion", "src/plugins/vis_type_timelion"],
4848
"uiActions": "src/plugins/ui_actions",
4949
"visDefaultEditor": "src/plugins/vis_default_editor",

src/legacy/core_plugins/kibana/public/__tests__/vis_type_vega/vega_visualization.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import Bluebird from 'bluebird';
2121
import expect from '@kbn/expect';
2222
import ngMock from 'ng_mock';
2323
import $ from 'jquery';
24+
25+
import 'leaflet/dist/leaflet.js';
26+
import 'leaflet-vega';
2427
// Will be replaced with new path when tests are moved
2528
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
2629
import { createVegaVisualization } from '../../../../../../plugins/vis_type_vega/public/vega_visualization';
@@ -100,6 +103,39 @@ describe('VegaVisualizations', () => {
100103
setSavedObjects(npStart.core.savedObjects);
101104
setNotifications(npStart.core.notifications);
102105

106+
const mockMapConfig = {
107+
includeElasticMapsService: true,
108+
proxyElasticMapsServiceInMaps: false,
109+
tilemap: {
110+
deprecated: {
111+
config: {
112+
options: {
113+
attribution: '',
114+
},
115+
},
116+
},
117+
options: {
118+
attribution: '',
119+
minZoom: 0,
120+
maxZoom: 10,
121+
},
122+
},
123+
regionmap: {
124+
includeElasticMapsService: true,
125+
layers: [],
126+
},
127+
manifestServiceUrl: '',
128+
emsFileApiUrl: 'https://vector.maps.elastic.co',
129+
emsTileApiUrl: 'https://tiles.maps.elastic.co',
130+
emsLandingPageUrl: 'https://maps.elastic.co/v7.7',
131+
emsFontLibraryUrl: 'https://tiles.maps.elastic.co/fonts/{fontstack}/{range}.pbf',
132+
emsTileLayerId: {
133+
bright: 'road_map',
134+
desaturated: 'road_map_desaturated',
135+
dark: 'dark_map',
136+
},
137+
};
138+
103139
beforeEach(ngMock.module('kibana'));
104140
beforeEach(
105141
ngMock.inject(() => {
@@ -127,7 +163,7 @@ describe('VegaVisualizations', () => {
127163
return 'not found';
128164
}
129165
});
130-
const serviceSettings = new ServiceSettings();
166+
const serviceSettings = new ServiceSettings(mockMapConfig, mockMapConfig.tilemap);
131167
vegaVisualizationDependencies = {
132168
serviceSettings,
133169
core: {

src/legacy/core_plugins/kibana/public/kibana.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import 'ui/autoload/all';
4545
import './management';
4646
import './dev_tools';
4747
import { showAppRedirectNotification } from '../../../../plugins/kibana_legacy/public';
48-
import 'leaflet';
4948
import { localApplicationService } from './local_application_service';
5049

5150
npSetup.plugins.kibanaLegacy.registerLegacyAppAlias('doc', 'discover', { keepPrefix: true });

src/legacy/core_plugins/region_map/public/__tests__/region_map_visualization.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import expect from '@kbn/expect';
2121
import ngMock from 'ng_mock';
2222
import _ from 'lodash';
23+
2324
import ChoroplethLayer from '../choropleth_layer';
2425
import { ImageComparator } from 'test_utils/image_comparator';
2526
import worldJson from './world.json';
@@ -103,31 +104,29 @@ describe('RegionMapsVisualizationTests', function() {
103104
let getManifestStub;
104105
beforeEach(
105106
ngMock.inject(() => {
107+
const mapConfig = {
108+
emsFileApiUrl: '',
109+
emsTileApiUrl: '',
110+
emsLandingPageUrl: '',
111+
};
112+
const tilemapsConfig = {
113+
deprecated: {
114+
config: {
115+
options: {
116+
attribution: '123',
117+
},
118+
},
119+
},
120+
};
106121
setInjectedVarFunc(injectedVar => {
107122
switch (injectedVar) {
108-
case 'mapConfig':
109-
return {
110-
emsFileApiUrl: '',
111-
emsTileApiUrl: '',
112-
emsLandingPageUrl: '',
113-
};
114-
case 'tilemapsConfig':
115-
return {
116-
deprecated: {
117-
config: {
118-
options: {
119-
attribution: '123',
120-
},
121-
},
122-
},
123-
};
124123
case 'version':
125124
return '123';
126125
default:
127126
return 'not found';
128127
}
129128
});
130-
const serviceSettings = new ServiceSettings();
129+
const serviceSettings = new ServiceSettings(mapConfig, tilemapsConfig);
131130
const regionmapsConfig = {
132131
includeElasticMapsService: true,
133132
layers: [],

src/legacy/core_plugins/region_map/public/choropleth_layer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
import $ from 'jquery';
21-
import L from 'leaflet';
2221
import _ from 'lodash';
2322
import d3 from 'd3';
2423
import { i18n } from '@kbn/i18n';
@@ -86,6 +85,7 @@ export default class ChoroplethLayer extends KibanaMapLayer {
8685
this._layerName = name;
8786
this._layerConfig = layerConfig;
8887

88+
// eslint-disable-next-line no-undef
8989
this._leafletLayer = L.geoJson(null, {
9090
onEachFeature: (feature, layer) => {
9191
layer.on('click', () => {
@@ -96,6 +96,7 @@ export default class ChoroplethLayer extends KibanaMapLayer {
9696
mouseover: () => {
9797
const tooltipContents = this._tooltipFormatter(feature);
9898
if (!location) {
99+
// eslint-disable-next-line no-undef
99100
const leafletGeojson = L.geoJson(feature);
100101
location = leafletGeojson.getBounds().getCenter();
101102
}
@@ -428,13 +429,15 @@ CORS configuration of the server permits requests from the Kibana application on
428429

429430
const { min, max } = getMinMax(this._metrics);
430431

432+
// eslint-disable-next-line no-undef
431433
const boundsOfAllFeatures = new L.LatLngBounds();
432434
return {
433435
leafletStyleFunction: geojsonFeature => {
434436
const match = geojsonFeature.__kbnJoinedMetric;
435437
if (!match) {
436438
return emptyStyle();
437439
}
440+
// eslint-disable-next-line no-undef
438441
const boundsOfFeature = L.geoJson(geojsonFeature).getBounds();
439442
boundsOfAllFeatures.extend(boundsOfFeature);
440443

src/legacy/core_plugins/tile_map/index.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/plugins/maps_legacy/config.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 { schema, TypeOf } from '@kbn/config-schema';
21+
import { configSchema as tilemapSchema } from '../tile_map/config';
22+
23+
// TODO: Pull this portion from region_map
24+
export const regionmapSchema = schema.object({
25+
includeElasticMapsService: schema.boolean({ defaultValue: true }),
26+
layers: schema.arrayOf(
27+
schema.object({
28+
url: schema.string(),
29+
format: schema.object({
30+
type: schema.string({ defaultValue: 'geojson' }),
31+
}),
32+
meta: schema.object({
33+
feature_collection_path: schema.string({ defaultValue: 'data' }),
34+
}),
35+
attribution: schema.string(),
36+
name: schema.string(),
37+
fields: schema.arrayOf(
38+
schema.object({
39+
name: schema.string(),
40+
description: schema.string(),
41+
})
42+
),
43+
}),
44+
{ defaultValue: [] }
45+
),
46+
});
47+
48+
export const configSchema = schema.object({
49+
includeElasticMapsService: schema.boolean({ defaultValue: true }),
50+
proxyElasticMapsServiceInMaps: schema.boolean({ defaultValue: false }),
51+
tilemap: tilemapSchema,
52+
regionmap: regionmapSchema,
53+
manifestServiceUrl: schema.string({ defaultValue: '' }),
54+
emsFileApiUrl: schema.string({ defaultValue: 'https://vector.maps.elastic.co' }),
55+
emsTileApiUrl: schema.string({ defaultValue: 'https://tiles.maps.elastic.co' }),
56+
emsLandingPageUrl: schema.string({ defaultValue: 'https://maps.elastic.co/v7.7' }),
57+
emsFontLibraryUrl: schema.string({
58+
defaultValue: 'https://tiles.maps.elastic.co/fonts/{fontstack}/{range}.pbf',
59+
}),
60+
emsTileLayerId: schema.object({
61+
bright: schema.string({ defaultValue: 'road_map' }),
62+
desaturated: schema.string({ defaultValue: 'road_map_desaturated' }),
63+
dark: schema.string({ defaultValue: 'dark_map' }),
64+
}),
65+
});
66+
67+
export type ConfigSchema = TypeOf<typeof configSchema>;

src/plugins/maps_legacy/kibana.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
"id": "mapsLegacy",
33
"version": "8.0.0",
44
"kibanaVersion": "kibana",
5-
"ui": true
5+
"configPath": ["map"],
6+
"ui": true,
7+
"server": true
68
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import expect from '@kbn/expect';
2121
import { KibanaMap } from '../../map/kibana_map';
2222
import { KibanaMapLayer } from '../../map/kibana_map_layer';
23-
import L from 'leaflet';
2423

2524
describe('kibana_map tests', function() {
2625
let domNode;
@@ -218,6 +217,7 @@ describe('kibana_map tests', function() {
218217
function makeMockLayer(attribution) {
219218
const layer = new KibanaMapLayer();
220219
layer._attribution = attribution;
220+
// eslint-disable-next-line no-undef
221221
layer._leafletLayer = L.geoJson(null);
222222
return layer;
223223
}

src/plugins/maps_legacy/public/index.ts

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

20-
import { CoreSetup } from 'kibana/public';
21-
import { bindSetupCoreAndPlugins, MapsLegacyPlugin } from './plugin';
2220
// @ts-ignore
23-
import * as colorUtil from './map/color_util';
21+
import { CoreSetup, PluginInitializerContext } from 'kibana/public';
22+
// @ts-ignore
23+
import { L } from './leaflet';
2424
// @ts-ignore
2525
import { KibanaMap } from './map/kibana_map';
26+
import { bindSetupCoreAndPlugins, MapsLegacyPlugin } from './plugin';
27+
// @ts-ignore
28+
import * as colorUtil from './map/color_util';
2629
// @ts-ignore
2730
import { KibanaMapLayer } from './map/kibana_map_layer';
2831
// @ts-ignore
@@ -41,8 +44,15 @@ import {
4144
// @ts-ignore
4245
import { mapTooltipProvider } from './tooltip_provider';
4346

44-
export function plugin() {
45-
return new MapsLegacyPlugin();
47+
export interface MapsLegacyConfigType {
48+
emsTileLayerId: string;
49+
includeElasticMapsService: boolean;
50+
proxyElasticMapsServiceInMaps: boolean;
51+
tilemap: any;
52+
}
53+
54+
export function plugin(initializerContext: PluginInitializerContext) {
55+
return new MapsLegacyPlugin(initializerContext);
4656
}
4757

4858
/** @public */
@@ -59,6 +69,7 @@ export {
5969
FileLayer,
6070
TmsLayer,
6171
mapTooltipProvider,
72+
L,
6273
};
6374

6475
// Due to a leaflet/leaflet-draw bug, it's not possible to consume leaflet maps w/ draw control

0 commit comments

Comments
 (0)