Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tile Map] Shim new Platform #41265

Merged
merged 4 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/legacy/core_plugins/tile_map/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { resolve } from 'path';
import { Legacy } from 'kibana';

// @ts-ignore
import emsClient from './common/ems_client';

import { LegacyPluginApi, LegacyPluginInitializer } from '../../../../src/legacy/types';

const tileMapPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) =>
new Plugin({
id: 'tile_map',
require: ['kibana', 'elasticsearch', 'visualizations', 'interpreter', 'data'],
publicDir: resolve(__dirname, 'public'),
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
hacks: [resolve(__dirname, 'public/legacy')],
injectDefaultVars: server => ({}),
},
init: (server: Legacy.Server) => {
server.expose({
ems_client: emsClient,
});
},
config(Joi: any) {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},
} as Legacy.PluginSpecOptions);

// eslint-disable-next-line import/no-default-export
export default tileMapPluginInitializer;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { CoordinateMapsVisualizationProvider } from '../coordinate_maps_visualization';
import { createTileMapVisualization } from '../tile_map_visualization';
import LogstashIndexPatternStubProvider from 'fixtures/stubbed_logstash_index_pattern';
import * as visModule from 'ui/vis';
import { ImageComparator } from 'test_utils/image_comparator';
Expand Down Expand Up @@ -65,20 +65,25 @@ describe('CoordinateMapsVisualizationTest', function () {
let Vis;
let indexPattern;
let vis;
let dependencies;

let imageComparator;


let getManifestStub;
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject((Private, $injector) => {
const serviceSettings = $injector.get('serviceSettings');

dependencies = {
serviceSettings,
$injector
};

Vis = Private(visModule.VisProvider);
CoordinateMapsVisualization = Private(CoordinateMapsVisualizationProvider);
CoordinateMapsVisualization = createTileMapVisualization(dependencies);
indexPattern = Private(LogstashIndexPatternStubProvider);


const serviceSettings = $injector.get('serviceSettings');
getManifestStub = serviceSettings.__debugStubManifestCalls(async (url) => {
//simulate network calls
if (url.startsWith('https://foobar')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,11 @@ import * as Rx from 'rxjs';
import { filter, first } from 'rxjs/operators';
import 'ui/vis/map/service_settings';
import { toastNotifications } from 'ui/notify';
import { uiModules } from 'ui/modules';
import chrome from 'ui/chrome';

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

const emsServiceSettings = new Promise((resolve) => {
uiModules.get('kibana').run(($injector) => {
Copy link
Contributor Author

@alexwizp alexwizp Jul 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nreese please have a look.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks like that can be safely removed since serviceSettings is getting injected in the current version.

const serviceSttings = $injector.get('serviceSettings');
resolve(serviceSttings);
});
});

export function BaseMapsVisualizationProvider(serviceSettings) {

/**
Expand Down Expand Up @@ -204,7 +196,7 @@ export function BaseMapsVisualizationProvider(serviceSettings) {
isDesaturated = true;
}
const isDarkMode = chrome.getUiSettingsClient().get('theme:darkMode');
const meta = await (await emsServiceSettings).getAttributesForTMSLayer(tmsLayer, isDesaturated, isDarkMode);
const meta = await serviceSettings.getAttributesForTMSLayer(tmsLayer, isDesaturated, isDarkMode);
const showZoomMessage = serviceSettings.shouldShowZoomMessage(tmsLayer);
const options = _.cloneDeep(tmsLayer);
delete options.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ import { i18n } from '@kbn/i18n';

import template from './_tooltip.html';

export function TileMapTooltipFormatterProvider($compile, $rootScope) {
export function TileMapTooltipFormatterProvider($injector) {
const $rootScope = $injector.get('$rootScope');
const $compile = $injector.get('$compile');

const $tooltipScope = $rootScope.$new();
const $el = $('<div>').html(template);

$compile($el)($tooltipScope);

return function tooltipFormatter(aggConfig, metricAgg, feature) {

if (!feature) {
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
* under the License.
*/

import { uiModules } from 'ui/modules';
import tileMapTemplate from './tile_map_vis_params.html';
import './wms_options';
const module = uiModules.get('kibana');
module.directive('tileMapVisParams', function () {

export function TileMapVisParams() {
return {
restrict: 'E',
template: tileMapTemplate,
};
});
}
14 changes: 3 additions & 11 deletions src/legacy/core_plugins/tile_map/public/editors/wms_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
* under the License.
*/

import { uiModules } from 'ui/modules';
import { i18n } from '@kbn/i18n';
import wmsOptionsTemplate from './wms_options.html';
const module = uiModules.get('kibana');

module.directive('wmsOptions', function (serviceSettings) {
export function WmsOptions(serviceSettings) {
return {
restrict: 'E',
template: wmsOptionsTemplate,
Expand All @@ -35,7 +33,6 @@ module.directive('wmsOptions', function (serviceSettings) {
$scope.wmsLinkText = i18n.translate('tileMap.wmsOptions.wmsLinkText', { defaultMessage: 'here' });

new Promise((resolve, reject) => {

serviceSettings
.getTMSServices()
.then((allTMSServices) => {
Expand All @@ -53,16 +50,11 @@ module.directive('wmsOptions', function (serviceSettings) {
$scope.options.selectedTmsLayer = $scope.collections.tmsLayers[0];
}
resolve(true);

})
.catch(function (e) {
reject(e);
});


});


}
},
};
});
}
8 changes: 4 additions & 4 deletions src/legacy/core_plugins/tile_map/public/geohash_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import L from 'leaflet';
import _ from 'lodash';
import { min, isEqual } from 'lodash';
import { i18n } from '@kbn/i18n';

import { KibanaMapLayer } from 'ui/vis/map/kibana_map_layer';
Expand Down Expand Up @@ -70,7 +70,7 @@ export class GeohashLayer extends KibanaMapLayer {

let radius = 15;
if (this._featureCollectionMetaData.geohashGridDimensionsAtEquator) {
const minGridLength = _.min(this._featureCollectionMetaData.geohashGridDimensionsAtEquator);
const minGridLength = min(this._featureCollectionMetaData.geohashGridDimensionsAtEquator);
const metersPerPixel = this._kibanaMap.getMetersPerPixel();
radius = (minGridLength / metersPerPixel) / 2;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ export class GeohashLayer extends KibanaMapLayer {

isReusable(options) {

if (_.isEqual(this._geohashOptions, options)) {
if (isEqual(this._geohashOptions, options)) {
return true;
}

Expand All @@ -144,7 +144,7 @@ export class GeohashLayer extends KibanaMapLayer {
return false;
} else if (this._geohashOptions.mapType !== options.mapType) {
return false;
} else if (this._geohashOptions.mapType === 'Heatmap' && !_.isEqual(this._geohashOptions.heatmap, options)) {
} else if (this._geohashOptions.mapType === 'Heatmap' && !isEqual(this._geohashOptions.heatmap, options)) {
return false;
} else {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,9 @@
* under the License.
*/

import { resolve } from 'path';
import * as emsClient from './common/ems_client';
import { PluginInitializerContext } from '../../../../core/public';
import { TileMapPlugin as Plugin } from './plugin';

export default function (kibana) {

return new kibana.Plugin({
uiExports: {
visTypes: ['plugins/tile_map/tile_map_vis'],
interpreter: ['plugins/tile_map/tilemap_fn'],
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
},
init(server) {
server.expose({
ems_client: emsClient
});
}
});
export function plugin(initializerContext: PluginInitializerContext) {
return new Plugin(initializerContext);
}
40 changes: 40 additions & 0 deletions src/legacy/core_plugins/tile_map/public/legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';

import { visualizations } from '../../visualizations/public';
import { TileMapPluginSetupDependencies } from './plugin';
import { LegacyDependenciesPlugin } from './shim';
import { plugin } from '.';

const plugins: Readonly<TileMapPluginSetupDependencies> = {
visualizations,
data: npSetup.plugins.data,

// Temporary solution
// It will be removed when all dependent services are migrated to the new platform.
__LEGACY: new LegacyDependenciesPlugin(),
};

const pluginInstance = plugin({} as PluginInitializerContext);

export const setup = pluginInstance.setup(npSetup.core, plugins);
export const start = pluginInstance.start(npStart.core);
75 changes: 75 additions & 0 deletions src/legacy/core_plugins/tile_map/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import {
CoreSetup,
CoreStart,
Plugin,
PluginInitializerContext,
UiSettingsClientContract,
} from '../../../../core/public';
import { Plugin as DataPublicPlugin } from '../../../../plugins/data/public';
import { VisualizationsSetup } from '../../visualizations/public';

import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim';

// @ts-ignore
import { createTileMapFn } from './tile_map_fn';
// @ts-ignore
import { createTileMapTypeDefinition } from './tile_map_type';

/** @private */
interface TileMapVisualizationDependencies extends LegacyDependenciesPluginSetup {
uiSettings: UiSettingsClientContract;
}

/** @internal */
export interface TileMapPluginSetupDependencies {
data: ReturnType<DataPublicPlugin['setup']>;
visualizations: VisualizationsSetup;
__LEGACY: LegacyDependenciesPlugin;
}

/** @internal */
export class TileMapPlugin implements Plugin<Promise<void>, void> {
initializerContext: PluginInitializerContext;

constructor(initializerContext: PluginInitializerContext) {
this.initializerContext = initializerContext;
}

public async setup(
core: CoreSetup,
{ data, visualizations, __LEGACY }: TileMapPluginSetupDependencies
) {
const visualizationDependencies: Readonly<TileMapVisualizationDependencies> = {
uiSettings: core.uiSettings,
...(await __LEGACY.setup()),
};

data.expressions.registerFunction(() => createTileMapFn(visualizationDependencies));

visualizations.types.VisTypesRegistryProvider.register(() =>
createTileMapTypeDefinition(visualizationDependencies)
);
}

public start(core: CoreStart) {
// nothing to do here yet
}
}
20 changes: 20 additions & 0 deletions src/legacy/core_plugins/tile_map/public/shim/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export * from './legacy_dependencies_plugin';
Loading