我的问题是在这种情况下如何更改瓦片地图的网址:
function ChangeView({ center, zoom }) {
const map = useMap();
map.setView(center, zoom);
return null;
}
function TrackerMap({ darkMode, countries, casesType, center, zoom}) {
const currentTheme = useContext(ThemeContext);
const mapTheme = darkMode ? `https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/{z}/{x}/{y}{r}.png` : `https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png`;
return (
<MapWrapper currentTheme={currentTheme}>
<MapContainer center={center} zoom={zoom}>
<ChangeView center={center} zoom={zoom} />
<TileLayer
url={mapTheme}
/>
</MapContainer>
</MapWrapper>
)
}
我想根据darkMode
props值切换 TileLayer 样式。但是在那个实现中,darkMode
proprs的新值不会触发更改<TileLayer />