У меня есть 10-15 различных слоев layerId и я создаю MapboxLayer из подмодуля deck.gl/mapbox api refrence и добавлен в экземпляр карты mapbox.
Попытка установить видимость слоя на основе передачи layerId и propertyValue как флажка true / false из пользовательского интерфейса, вызвав layerVisibility метод, но он не работает.
Класс 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 });
}
Примечание:
-Я попытался установить видимость свойства макета слоя как «видимый» или «нет», но в этом случае всплывающая подсказка появляется даже при скрытии слоя.
Не могли бы вы предложить мне лучший подход, как установить слой видимое свойство true / false для типа hexagonLayer MapboxLayer.