Mapbox-图层的过滤器组
Mapbox提供了一个示例,演示如何打开和关闭地图图层。有没有一种方法可以轻松地切换图层组而不是单个图层 示例代码如下:Mapbox-图层的过滤器组,mapbox,Mapbox,Mapbox提供了一个示例,演示如何打开和关闭地图图层。有没有一种方法可以轻松地切换图层组而不是单个图层 示例代码如下: // enumerate ids of the layers var toggleableLayerIds = ['contours', 'museums']; // set up the corresponding toggle button for each layer for (var i = 0; i < toggleableLayerIds.length
// enumerate ids of the layers
var toggleableLayerIds = ['contours', 'museums'];
// set up the corresponding toggle button for each layer
for (var i = 0; i < toggleableLayerIds.length; i++) {
var id = toggleableLayerIds[i];
var link = document.createElement('a');
link.href = '#';
link.className = 'active';
link.textContent = id;
link.onclick = function(e) {
var clickedLayer = this.textContent;
e.preventDefault();
e.stopPropagation();
var visibility = map.getLayoutProperty(clickedLayer, 'visibility');
// toggle layer visibility by changing the layout object's visibility property
if (visibility === 'visible') {
map.setLayoutProperty(clickedLayer, 'visibility', 'none');
this.className = '';
} else {
this.className = 'active';
map.setLayoutProperty(clickedLayer, 'visibility', 'visible');
}
};
var layers = document.getElementById('menu');
layers.appendChild(link);
}
//枚举层的ID
var-toggleableLayerIds=[“等高线”、“博物馆”];
//为每个层设置相应的切换按钮
对于(变量i=0;i