其他分享
首页 > 其他分享> > 【Mapbox】建筑矢量切片拾取、高亮、信息弹窗

【Mapbox】建筑矢量切片拾取、高亮、信息弹窗

作者:互联网

1、数据源加载

                map.addSource('building', {
                    type: 'vector',
                    tiles: ['http://192.168.182.1:6767/{z}/{x}/{y}.pbf']
                })

2、建筑图层加载

map.addLayer({
                    "id": "guanzhou",
                    "type": "fill-extrusion",
                    "source": "building", 
                    "source-layer": "广州",
                    'layout': {},
                    'paint': {
 

                        'fill-extrusion-color': [
                            "interpolate",
                            ["exponential", 0.99],
                            ["get", "Floor"],
                            0,
                            "#FFF6B7",
                            100,
                            "#F6416C"
                        ],
                        'fill-extrusion-height': [
                            "interpolate", ["linear"],
                            ["zoom"],
                            15, 0,
                            15.05, ["get", "Floor"]
                        ],
                        'fill-extrusion-base': 0,
                        'fill-extrusion-opacity': 0.6
                    }
                });

3、拾取图层加载

                map.addLayer({
                    'id': 'layerHighlight',
                    'type': 'fill-extrusion',
                    'source': "building",
                    "source-layer": "广州",
                    'paint': {
                        'fill-extrusion-color': '#088', 
                        'fill-extrusion-height': [
                            "interpolate", ["linear"],
                            ["zoom"],
                            15, 0,
                            15.05, ["get", "Floor"]
                        ],
                        'fill-extrusion-base': 0,
                        'fill-extrusion-opacity': 0.6
                    },
                    "filter": ["in", "Id", ""]
                });

4、建筑图层点击

            map.on('click', 'guanzhou', function(e) {
                var feature = e.features[0];
                map.setFilter('layerHighlight', ['in', 'Id', feature.properties.Id]);
                var popup = new mapboxgl.Popup({
                    closeButton: true,
                    closeOnClick: true,
                });
                popup.setLngLat(feature.geometry.coordinates[0][0])
                    .setHTML('<strong> Id: </strong>' + feature.properties.Id +
                        '<p> <strong> Floor: </strong>' + feature.properties.Floor + '</p>')
                    .addTo(map);
            });

5、效果显示

 

 6、矢量切片描述文件

source:mapbox中的source的Id,此处为building

source-layer:图层ID

Id、Floor:为原数据的字段

guanzhou:建筑切片图层Id

layerHighlight:拾取高亮显示图层Id

 

标签:extrusion,Floor,source,Mapbox,高亮,图层,Id,弹窗,fill
来源: https://www.cnblogs.com/defineconst/p/15024060.html