我正在使用 deck.gl GeoJsonLayer 在地图上显示区域。通过一个事件,我能够使这些区域可选。我正在努力解决的问题是在单击后更改特征选择中的特征颜色。
这是渲染层功能(改编自此处)
_renderLayers(props) {
const { geofeats } = props;
return [
new GeoJsonLayer({
id: 'geojson',
data: geofeats,
opacity: 0.8,
stroked: true,
filled: true,
extruded: true,
wireframe: true,
getElevation: f => 10000,
getFillColor: f =>
{
if(f.properties.selected)
{
return [200, 200, 100];
} else return [200, 100, 150];
},
getLineColor: [255, 255, 255],
pickable: true,
onHover: this._onHover,
onClick: this._onClick
})
];
}
问题是,当我通过 setState() 更新特征集合中特征的选择状态时,即使数据中表示状态更改,渲染也不会更新。
这就是我传递“geofeats”对象的方式:
render() {
const {features} = this.state;
const {mapStyle = 'mapbox://styles/mapbox/light-v9'} = this.props;
return (
<DeckGL
layers={this._renderLayers({geofeats: features})}
effects={this._effects}
initialViewState={INITIAL_VIEW_STATE}
controller={true}
>
<StaticMap
reuseMaps
mapStyle={mapStyle}
preventStyleDiffing={true}
mapboxApiAccessToken={MAPBOX_TOKEN}
/>
{this._renderTooltip}
</DeckGL>
);
}
我通过 setState 而不是通过 props 尝试了它 - 但结果是一样的。特征集合被移交给 GeoJsonLayer 但从未更新。
有人可以告诉我,我做错了什么吗?
更新:带有错误再现的要点示例:https ://gist.github.com/jaronimoe/efdbb58b3f52c2aac63362a921802cfe