我试图通过分配一个全局定义的数组 salesPropertyInfoWindowOut 来更改 salesPropertyInfoWindowIn 的状态。
的初始值
salesPropertyInfoWindowIn :
[false,false,false,false,false,false,false,false,false,false]
onMarkerClick 方法更改作为参数传递的索引的值,然后在 salesPropertyInfoWindowIn 中分配该值。但是,这不会重新渲染地图。请通过提出一些解决方案来帮助我。
const MapWithAMarkerClusterer = compose(
withProps({
googleMapURL:
"https://maps.googleapis.com/maps/api/js?key=AIzaSyDlMypBHZKOOgwp7PBHrQSvf75Y1sM2gnU&v=3.exp&libraries=geometry,drawing,places",
loadingElement: <div style={{ height: `100%` }} />,
containerElement: <div style={{ height: `390px` }} />,
mapElement: <div style={{ height: `100%` }} />
}),
withStateHandlers(
() => ({
salesPropertyInfoWindowIn: salesPropertyInfoWindowOut,
isOpen: false,
}),
{
onToggleOpen: ({isOpen}) => () => ({
isOpen: !isOpen
}),
onMarkerClick: ({salesPropertyInfoWindowIn}) => (marker, i) => (
salesPropertyInfoWindowOut[i] = !salesPropertyInfoWindowOut[i],
{salesPropertyInfoWindowIn: salesPropertyInfoWindowOut}
)
}),
withScriptjs,
withGoogleMap)(props => (
<GoogleMap
defaultZoom={15}
defaultCenter={
home.currentProperty != null
? {
lat: parseFloat(home.currentProperty.property.location.lat),
lng: parseFloat(home.currentProperty.property.location.lon)
}
: ""
}
>
<MarkerClusterer averageCenter enableRetinaIcons gridSize={10}>
{home.propSalesData != undefined || home.propSalesData != null
? props.markers.map((marker, i) => (
<Marker
icon={salesPropertyMarkerImage}
onClick={() => props.onMarkerClick(marker, i)}
key={i}
position={{
lat: parseFloat(marker.location.lat),
lng: parseFloat(marker.location.lon)
}}
>
{(props.salesPropertyInfoWindowIn[i] == true) ?
(console.log('Inside', props.salesPropertyInfoWindowIn[i]),
<InfoWindow>
<text>
{home.propSalesData[i].agent.name != undefined ||
home.propSalesData[i].agent.name != null
? "Agent: " + home.propSalesData[i].agent.name
: "Purchaser: " +
home.propSalesData[i].saleParticipants
.purchasersSummary}
</text>
</InfoWindow>
) : ""}
</Marker>
))
: ""}