Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mapbox-图层的过滤器组_Mapbox - Fatal编程技术网

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

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; 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