Я открываю вопрос в Github: https://github.com/tomchentw/react-google-maps/issues/1035#issuecomment -597227861
Я выбираю использовать другую библиотеку, имя @react-google-maps/api
Теперь я могу изменить мои реквизиты DrawingManager
Мой код:
Родитель:
const onLoadDrawing = useCallback(
(drawingManager) => {
if (drawingManager) {
drawingManager.setOptions({
polygonOptions: {
fillColor: values.cor,
strokeColor: values.cor,
...polygonOptions,
},
})
}
setDrawingManager(drawingManager)
},
[setDrawingManager, values.cor],
) <
GoogleMap mapContainerStyle = {
mapStyle
}
center = {
center
}
zoom = {
15
}
onLoad = {
onLoad
} > {
loadingMap && !polygonComplete && ( <
DrawingManager onPolygonComplete = {
onPolygonComplete
}
onLoad = {
onLoadDrawing
}
options = {
{
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [google.maps.drawing.OverlayType.POLYGON],
},
}
}
/>
)
} <
/GoogleMap>
Дети
import React, {
memo
} from 'react'
import {
GoogleMap,
useLoadScript,
DrawingManager
} from '@react-google-maps/api'
import {
Spin
} from 'antd'
import _ from 'lodash'
interface MapProps {
mapContainerStyle: {}
zoom: number
center: {
lat: number;lng: number
}
children ? : React.ReactElement[] | React.ReactElement | boolean
onLoad ? : (map: google.maps.Map < Element > ) => void | Promise < void >
}
const Map: React.FC < MapProps > = ({
mapContainerStyle,
zoom,
center,
onLoad,
children
}) => {
return ( <
GoogleMap id = "drawing-manager-example"
mapTypeId = "satellite"
mapContainerStyle = {
mapContainerStyle
}
zoom = {
zoom
}
center = {
center
}
onLoad = {
onLoad
} > {
children
} <
/GoogleMap>
)
}
const libraries = ['drawing']
const GoogleMapComponent: React.FC < MapProps > = (props) => {
const {
isLoaded,
loadError
} = useLoadScript({
id: 'script-google-map-loader',
googleMapsApiKey: process.env.REACT_APP_PROVIDER_GOOGLE,
libraries,
})
if (loadError) {
return <div > Mapa não pode ser carregado neste momento, desculpe: ( < /div>
}
return isLoaded ? ( <
Map {
...props
}
/>
) : ( <
div style = {
{
textAlign: 'center',
background: 'rgba(0, 0, 0, 0.05)',
borderRadius: 4,
marginBottom: 20,
padding: 30,
margin: 20,
}
} >
<
Spin / >
<
/div>
)
}
export default memo(GoogleMapComponent, _.isEqual)