React-leaflet、GeoJson:从 Cascader 选择选项后着色层出现问题
我的交互式地图有问题,我有一个带有 GeoJSON 图层的反应传单地图。另外,我添加了一些状态组件,例如带有一些国家名称选项的 Cascader,例如奥地利、比利时等......我想要这样的。级联状态完成后(因此,在级联中单击一个国家/地区后),我想更改该级联中所选国家/地区的颜色并将其显示在地图上。例如,如果我选择奥地利,我想在地图上为奥地利着色。另外,cascader 来自 Ant Desing 库。 selectedCountries
是另一个不重要的状态。
function onEachCountry(country, layer) {
const countryName = country.properties.ADMIN
if (currentValueCascader.includes(countryName)) {
layer.setStyle({ fillColor: 'yellow', weight: 2, fillOpacity: 5 })
} else {
layer.setStyle({ color: "#000000", fillColor: "white", weight: 1 })
}
}
return(
<Cascader
showSearch
style={{ width: 256 }}
options={countries}
onChange={(e) => {
setCurrentValueCascader(e)
}}
placeholder="Search country"
value={currentValueCascader}
multiple
/>
<MapContainer
style={{ height: "80vh", width: "auto" }}
zoom={2.3}
scrollWheelZoom={true}
minZoom={2.3}
center={[30, 0]}>
<TileLayer url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' />
<GeoJSON data={features} onEachFeature={(a, b) => { onEachCountry(a, b, selectedCountries) }} style={(a, b) => { onEachCountry(a, b, selectedCountries) }}} />
</MapContainer>
)
我认为不知何故,Leaflet 地图没有重新渲染所选选项或 GeoJSON,但不知道如何解决它。
I have an issue with my interactive map, I have a react-leaflet map with GeoJSON layers. Also, I have added some state components like cascader with some name of countries options, like Austria, Belgium, etc... I want to have it like this. After the state from cascader is done (so after I click on a country in cascader), I want to change the color of the selected country from that cascader and display it on the map. For example, if I choose Austria, I want to have colored Austria on the map. Also, cascader is from the Ant Desing library. And selectedCountries
is another state that is not important.
function onEachCountry(country, layer) {
const countryName = country.properties.ADMIN
if (currentValueCascader.includes(countryName)) {
layer.setStyle({ fillColor: 'yellow', weight: 2, fillOpacity: 5 })
} else {
layer.setStyle({ color: "#000000", fillColor: "white", weight: 1 })
}
}
return(
<Cascader
showSearch
style={{ width: 256 }}
options={countries}
onChange={(e) => {
setCurrentValueCascader(e)
}}
placeholder="Search country"
value={currentValueCascader}
multiple
/>
<MapContainer
style={{ height: "80vh", width: "auto" }}
zoom={2.3}
scrollWheelZoom={true}
minZoom={2.3}
center={[30, 0]}>
<TileLayer url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' />
<GeoJSON data={features} onEachFeature={(a, b) => { onEachCountry(a, b, selectedCountries) }} style={(a, b) => { onEachCountry(a, b, selectedCountries) }}} />
</MapContainer>
)
I think that somehow the Leaflet map is not re-rendering that chosen option or maybe that GeoJSON, but don't know how to solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论