SOU*_*ROY 5 html javascript css reactjs react-leaflet
我是反应传单的新手。所以在下面的代码中,我没有找到问题出在哪里。为什么color和fillColor属性没有在React-leaflet 的<Circle />组件中更新。但是当我执行console.log(casesTypeColors[casesType].hex)时,当caseType更改时,该值正在更新,但它没有反映在屏幕上。但其他属性正在更新。所以,请帮助我了解我在哪里做错了。提前致谢。
import { Circle } from "react-leaflet";
const casesTypeColors = {
cases: {
hex: "#CC1034",
rgb: "rgb(204, 16, 52)",
half_op: "rgba(204, 16, 52, 0.5)",
multiplier: 800,
},
recovered: {
hex: "#7dd71d",
rgb: "rgb(125, 215, 29)",
half_op: "rgba(125, 215, 29, 0.5)",
multiplier: 1200,
},
deaths: {
hex: "#fb4443",
rgb: "rgb(251, 68, 67)",
half_op: "rgba(251, 68, 67, 0.5)",
multiplier: 2000,
},
};
// Draw circles on the map with interactive tooptip
export const showDataOnMap = (data, casesType = "cases") =>
data.map((country, index) => (
<Circle
key={index}
center={[country.countryInfo.lat, country.countryInfo.long]}
fillOpacity={0.4}
color={casesTypeColors[casesType].hex}
fillColor={casesTypeColors[casesType].hex}
radius={
Math.sqrt(country[casesType] / 10) *
casesTypeColors[casesType].multiplier
}
>
</Circle>
));
Run Code Online (Sandbox Code Playgroud)
小智 8
在showDataOnMap函数中写入:
<Circle pathOptions={{color: casesTypeColors[casesType].hex,
fillColor: casesTypeColors[casesType].hex }}>
Run Code Online (Sandbox Code Playgroud)
代替
<Circle color={casesTypeColors[casesType].hex}
fillColor={casesTypeColors[casesType].hex}>
Run Code Online (Sandbox Code Playgroud)