Map resetting when clicking on a marker fix (#1299)

This commit is contained in:
vicky-primathon 2020-10-29 23:46:27 +05:30 committed by GitHub
parent 9553fe9b19
commit 75c84cbba7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -73,7 +73,20 @@ const PickMyLocationWrapper = styled.div<PickMyLocationProps>`
`; `;
const MyMapComponent = withScriptjs( const MyMapComponent = withScriptjs(
withGoogleMap((props: any) => ( withGoogleMap((props: any) => {
const [mapCenter, setMapCenter] = React.useState<
| {
lat: number;
lng: number;
title?: string;
description?: string;
}
| undefined
>({
...props.center,
lng: props.center.long,
});
return (
<GoogleMap <GoogleMap
options={{ options={{
zoomControl: props.allowZoom, zoomControl: props.allowZoom,
@ -84,7 +97,7 @@ const MyMapComponent = withScriptjs(
streetViewControl: false, streetViewControl: false,
}} }}
zoom={props.zoom} zoom={props.zoom}
center={{ ...props.center, lng: props.center.long }} center={mapCenter}
onClick={e => { onClick={e => {
if (props.enableCreateMarker) { if (props.enableCreateMarker) {
props.saveMarker(e.latLng.lat(), e.latLng.lng()); props.saveMarker(e.latLng.lat(), e.latLng.lng());
@ -112,6 +125,10 @@ const MyMapComponent = withScriptjs(
props.selectedMarker.long === marker.long props.selectedMarker.long === marker.long
} }
onClick={e => { onClick={e => {
setMapCenter({
...marker,
lng: marker.long,
});
props.selectMarker(marker.lat, marker.long, marker.title); props.selectMarker(marker.lat, marker.long, marker.title);
}} }}
onDragEnd={de => { onDragEnd={de => {
@ -128,7 +145,8 @@ const MyMapComponent = withScriptjs(
</PickMyLocationWrapper> </PickMyLocationWrapper>
)} )}
</GoogleMap> </GoogleMap>
)), );
}),
); );
class MapComponent extends React.Component<MapComponentProps> { class MapComponent extends React.Component<MapComponentProps> {