我有10-15个不同的layerId图层,并从deck.gl/mapbox子模块api refreence创建MapboxLayer并添加到mapbox地图实例中。
通过调用 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;
}
}
地图框实例:
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 });
}
注意: -i尝试通过将图层布局属性的可见性设置为“可见”或“无”,但是在这种情况下,即使隐藏了图层,工具提示也会出现。
能否请您建议我最好的方法,如何为MapboxLayer的hexagonLayer类型设置图层visible属性的真/假。
答案 0 :(得分:1)
试试这个,它对我有用。
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 })