gpt4 book ai didi

mapbox-gl - 如何更新 deckgl-mapbox MapboxLayer 的可见 Prop

转载 作者:行者123 更新时间:2023-12-05 05:10:44 27 4
gpt4 key购买 nike

我有 10-15 个不同的 layerId 图层并创建 MapboxLayer来自 deck.gl/mapbox 子模块 api 引用并添加到 mapbox map 实例中。

尝试通过调用 layerVisibility 方法从 UI 传递 layerId 和 propertyValue 作为 true/false 复选框来设置层的可见性,但它不起作用。

DeckglLayer 类:

declare let deck;
export class DeckglLayer {
constructor() {

}
createDeckglMapboxLayer(layerId, data) {
const { MapboxLayer, HexagonLayer } = deck;
const options = {
radius: 1000,
coverage: 1,
upperPercentile: 100
};
...
...
const hexagonLayer = new MapboxLayer({
type: HexagonLayer,
id: layerId,
data,
colorRange: COLOR_RANGE,
elevationRange: [0, 20000],
elevationScale: 4,
extruded: true,
getPosition: d => d.COORDINATES,
getElevationValue: e => Math.sqrt(e[0].properties.height) * 10,
getColorValue: this.getColorValue,
lightSettings: LIGHT_SETTINGS,
pickable: true,
onHover: setTooltip,
opacity: 1,
visible: true,
...options
});
return hexagonLayer;
}
}

Mapbox 实例:

 createMap(mapOptions) {
this.mapInstance = new MapboxGl.Map(mapOptions);
}

addDeckglLayer(layerId, data) {
var hexalayer = new DeckglLayer().createDeckglMapboxLayer(layerId, data);
this.mapInstance.addLayer(hexalayer);
}

layerVisibility(layerId,propertyValue) {
var ll: any = this.mapInstance.getLayer(layerId);
//***********first way
// ll.implementation.props.visible = propertyValue;
//this.mapInstance.addLayer(ll);

//*******second way
//ll.setProps({ visible: propertyValue });
}

注意: - 我尝试将图层布局属性可见性设置为“可见”或“无”,但在这种情况下,即使图层隐藏,工具提示也会出现。

你能给我建议最好的方法吗,如何设置图层visible MapboxLayer 的 hexagonLayer 类型的属性 true/false。

最佳答案

试试这个,它对我有用。

let refreshedLayers = [];
let currLayers = map.__deck.layerManager.getLayers();
let layer = currLayers[0];

// make it visible
// newLayer = layer.clone({ visible: true });
// make it unvisible
newLayer = layer.clone({ visible: false });
refreshedLayers.push(newLayer);

map.__deck.setProps({ layers: refreshedLayers })

关于mapbox-gl - 如何更新 deckgl-mapbox MapboxLayer 的可见 Prop ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56364705/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com