首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何更新deckgl-mapbox MapboxLayer的可视化道具

如何更新deckgl-mapbox MapboxLayer的可视化道具
EN

Stack Overflow用户
提问于 2019-05-29 16:12:14
回答 1查看 913关注 0票数 3

我有10-15个不同的layerId层,并从deck.gl/mapbox子模块MapboxLayer中创建MapboxLayer,并添加到mapbox地图实例中。

试图通过调用layerVisibility方法从UI中将layerId和propertyValue作为真/假复选框来设置层的可见性,但它不起作用。

DeckglLayer类:

代码语言:javascript
运行
复制
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实例:

代码语言:javascript
运行
复制
 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尝试将层布局属性可见性设置为“可见”或“无”,但在本例中,工具提示看起来与图层隐藏相同。

请您建议我最好的方法,如何为hexagonLayer类型的MapboxLayer设置layer MapboxLayer属性true/false。

EN

回答 1

Stack Overflow用户

发布于 2021-03-25 15:59:46

试试这个,它对我有用。

代码语言:javascript
运行
复制
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 })
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56364705

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档