图层数据过滤
可只显示符合自定义设置属性条件的图层数据。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>图层数据过滤</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
color: #f8f8f2;
}
.btn-group {
position: absolute;
top: 20px;
left: 20px;
}
</style>
<script src="https://delivery.mapmost.com/cdn/sdk/webgl/v9.14.0-beta/mapmost-webgl-min.js"></script>
</head>
<body>
<div id="map"></div>
<div class="btn-group">
<button onClick="showBuildingLow(this)">仅显示高度小于10的建筑物</button>
</div>
<script>
let map = new mapmost.Map({
container: 'map',
style: "<your style url>",
center: [120.72541613154851, 31.31171803927643],
zoom: 14,
pitch: 59.48725112156901,
bearing: -54.10626584095007,
userId: '***', // 授权码
});
map.on('load', function () {
map.addLayer( {
"id": "buildings",
"type": "fill-extrusion",
"source": "cultural",
"source-layer": "b_buildings",
"layout": {"visibility": "visible"},
"paint": {
"fill-extrusion-height": ["get", "jzzgdgd"],
"fill-extrusion-color": {
"stops": [
[
14.5,
"rgba(252, 254, 255, 1)"
],
[
16,
"rgba(255, 255, 255, 1)"
]
]
},
"fill-extrusion-opacity": 1
}
})
})
function showBuildingLow(e) {
if (e.innerHTML == "仅显示高度小于10的建筑物") {
map.setFilter('buildings', ["<", 'ztykgd', 10]);
e.innerHTML = "全部显示"
} else {
map.setFilter('buildings', null);
e.innerHTML = "仅显示高度小于10的建筑物"
}
}
</script>
</body>
</html>