forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] initial location map settings (elastic#64336) (elastic#65168)
* [Maps] initial location map settings * fix tslint * add button to set to current view * move button to bottom of form * review feedback Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
35b72b4
commit 90a4a5e
Showing
11 changed files
with
620 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
x-pack/plugins/maps/public/connected_components/map/mb/get_initial_view.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import sprites2 from '@elastic/maki/dist/[email protected]'; | |
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'; | ||
|
||
|
@@ -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, | ||
|
@@ -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 = { | ||
|
292 changes: 292 additions & 0 deletions
292
...blic/connected_components/map_settings_panel/__snapshots__/navigation_panel.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.