Moving the map center to the current location when required.

This commit is contained in:
vdv committed 2022-11-22 22:10:08 +01:00
1 parent 0ba385c476
commit 1555c00fe8
5 files changed
+219 -39

No files matched your search

+18 -24
View File
@@ -1,36 +1,29 @@
import React from 'react';
// import { Geolocation } from '@awesome-cordova-plugins/geolocation';
import { Geolocation } from '@awesome-cordova-plugins/geolocation';
import style from './GetLocation.module.css';
import style from './GetLocation.module.css';
import { IonButton, IonIcon } from '@ionic/react';
import { locateOutline } from 'ionicons/icons';
// import { useAtom } from 'jotai';
// import { setCenterAtom } from '../../App';
import { useAtom } from 'jotai';
import { stateAtom } from '../map';
// import { locationAtom } from '../map/CurrentLocation';
const GetLocation: React.FC<{}> = () => {
// const [, setCenter] = useAtom(setCenterAtom);
// const [, setLocation] = useAtom(locationAtom);
const [state, setState] = useAtom(stateAtom);
// const onClickHandler = (event: any) => {
// console.log('Click handler');
// Geolocation.getCurrentPosition().then((position) => {
// console.log(
// `Click handler, position: ${position.coords.latitude}, ${position.coords.longitude}`
// );
// setCenter({
// lat: position.coords.latitude,
// lon: position.coords.longitude,
// });
// setLocation({
// lat: position.coords.latitude,
// lon: position.coords.longitude,
// });
// });
// };
// onClick={onClickHandler}
const onClickHandler = (event: any) => {
console.log('Click handler');
Geolocation.getCurrentPosition().then((position) => {
console.log({ caller: 'GetLocation/onClickHandler', position, state });
setState({
zoom: state.zoom,
rotation: state.rotation,
center: [position.coords.longitude, position.coords.latitude],
});
});
};
return (
<IonButton
@@ -38,6 +31,7 @@ const GetLocation: React.FC<{}> = () => {
shape='round'
size='small'
fill='solid'
onClick={onClickHandler}
>
<IonIcon slot='icon-only' icon={locateOutline} color='white' />
</IonButton>