mapbox 笔记

1:mapbox 更改图层属性

map.setPaintProperty(layer, 'fill-opacity', 1);

2:mapbox 更改图层数据源

map.getSource(source).setData(cityHeatDatas);

3:mapbox 获取当前地图已添加的图层layers及数据源sources

const layers = map.getStyle().layers;
const sources= map.getStyle().sources;

4:mapbox添加热力图heat-weight表达式

"heatmap-weight": ["/", ["get", "value"], heatWeight],

5:mapbox更改style

let style =  {
        "version": 8,
        "sources": {
            "raster-tiles": {
                "type": "raster",
                "tiles": ['https://t{s}.tianditu.gov.cn/DataServer?T=' + type + '_w&x={x}&y={y}&l={z}&tk=' + tk ],
                "tileSize": 256,
            }
        },
        "layers": [{
            "id": "tdt-img-tiles",
            "type": "raster",
            "source": "raster-tiles",
            "minzoom": 0,
            "maxzoom": 22
        }]
    };

map.setStyle(style);

6:地图加载完成后执行

window.map.on('load', function() {
    console.log("do something!");    
});

7:判断某个图层是否存在

const layer = map.getLayer("layerId");

8:移除图层或数据源

map.removeLayer(layerId);   // 移除图层

map.removeSource(sourceId);    // 移除数据源

9:根据范围进行定位(含动画)

const bounds = [78.23,27.05,99.25,36.30];
map.fitBounds(bounds);

 

你可能感兴趣的:(mapbox)