我正在使用google-maps-react并尝试在选择时更改覆盖多边形的颜色。多边形也是 google-maps-react 的一部分。
多边形接受新的选定状态,setColor 函数甚至返回正确的颜色。它只是在地图本身上没有改变。
代码如下:
setColor = (selected, index) => {
if (selected) {
return "blue" //Even when blue is returned, no color change is visible
} else {
return "red"
}
}
render() {
return (
<Polygon
paths={this.props.paths}
onClick={() => this.handleClick()}
strokeColor="#2A2A57"
strokeOpacity={0.8}
strokeWeight={2}
fillColor = {this.setColor(this.state.isSelected, this.state.index)}
fillOpacity={0.35}
{...this.props}
/>
)
}