Skip to content
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
6 changes: 6 additions & 0 deletions x-pack/plugins/maps/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,9 @@ export enum SCALING_TYPES {
export const RGBA_0000 = 'rgba(0,0,0,0)';

export const SPATIAL_FILTERS_LAYER_ID = 'SPATIAL_FILTERS_LAYER_ID';

export enum INITIAL_LOCATION {
LAST_SAVED_LOCATION = 'LAST_SAVED_LOCATION',
FIXED_LOCATION = 'FIXED_LOCATION',
BROWSER_LOCATION = 'BROWSER_LOCATION',
}
2 changes: 1 addition & 1 deletion x-pack/plugins/maps/public/actions/map_actions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function trackMapSettings(): AnyAction;

export function updateMapSetting(
settingKey: string,
settingValue: string | boolean | number
settingValue: string | boolean | number | object
): AnyAction;

export function cloneLayer(layerId: string): AnyAction;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { INITIAL_LOCATION } from '../../../../common/constants';
import { Goto, MapCenterAndZoom } from '../../../../common/descriptor_types';
import { MapSettings } from '../../../reducers/map';

export async function getInitialView(
goto: Goto | null,
settings: MapSettings
): Promise<MapCenterAndZoom | null> {
if (settings.initialLocation === INITIAL_LOCATION.FIXED_LOCATION) {
return {
lat: settings.fixedLocation.lat,
lon: settings.fixedLocation.lon,
zoom: settings.fixedLocation.zoom,
};
}

if (settings.initialLocation === INITIAL_LOCATION.BROWSER_LOCATION) {
return await new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(
// success callback
pos => {
resolve({
lat: pos.coords.latitude,
lon: pos.coords.longitude,
zoom: settings.browserLocation.zoom,
});
},
// error callback
() => {
// eslint-disable-next-line no-console
console.warn('Unable to fetch browser location for initial map location');
resolve(null);
}
);
});
}

return goto && goto.center ? goto.center : null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import sprites2 from '@elastic/maki/dist/sprite@2.png';
import { DrawControl } from './draw_control';
import { TooltipControl } from './tooltip_control';
import { clampToLatBounds, clampToLonBounds } from '../../../elasticsearch_geo_utils';
import { getInitialView } from './get_initial_view';

import { getInjectedVarFunc } from '../../../kibana_services';

Expand Down Expand Up @@ -112,6 +113,7 @@ export class MBMapContainer extends React.Component {
}

async _createMbMapInstance() {
const initialView = await getInitialView(this.props.goto, this.props.settings);
return new Promise(resolve => {
const mbStyle = {
version: 8,
Expand All @@ -133,7 +135,6 @@ export class MBMapContainer extends React.Component {
maxZoom: this.props.settings.maxZoom,
minZoom: this.props.settings.minZoom,
};
const initialView = _.get(this.props.goto, 'center');
if (initialView) {
options.zoom = initialView.zoom;
options.center = {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading