Map resetting when clicking on a marker fix (#1299)
This commit is contained in:
parent
9553fe9b19
commit
75c84cbba7
|
|
@ -73,7 +73,20 @@ const PickMyLocationWrapper = styled.div<PickMyLocationProps>`
|
|||
`;
|
||||
|
||||
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
|
||||
options={{
|
||||
zoomControl: props.allowZoom,
|
||||
|
|
@ -84,7 +97,7 @@ const MyMapComponent = withScriptjs(
|
|||
streetViewControl: false,
|
||||
}}
|
||||
zoom={props.zoom}
|
||||
center={{ ...props.center, lng: props.center.long }}
|
||||
center={mapCenter}
|
||||
onClick={e => {
|
||||
if (props.enableCreateMarker) {
|
||||
props.saveMarker(e.latLng.lat(), e.latLng.lng());
|
||||
|
|
@ -112,6 +125,10 @@ const MyMapComponent = withScriptjs(
|
|||
props.selectedMarker.long === marker.long
|
||||
}
|
||||
onClick={e => {
|
||||
setMapCenter({
|
||||
...marker,
|
||||
lng: marker.long,
|
||||
});
|
||||
props.selectMarker(marker.lat, marker.long, marker.title);
|
||||
}}
|
||||
onDragEnd={de => {
|
||||
|
|
@ -128,7 +145,8 @@ const MyMapComponent = withScriptjs(
|
|||
</PickMyLocationWrapper>
|
||||
)}
|
||||
</GoogleMap>
|
||||
)),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
class MapComponent extends React.Component<MapComponentProps> {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user