Mapbox GL-JS:在标签下添加新的瓷砖集覆盖
我有一个瓷砖集,我正在加载到我的地图(地图称为topleftmap)。我希望城市和其他标签加载到瓷砖上,而不是像Mapbox中的示例中那样,加载到下面: 我如何使用tilesets进行此操作?我有一个外部JS文件,用于加载到TileSet中,如下所示:Mapbox GL-JS:在标签下添加新的瓷砖集覆盖,mapbox,mapbox-gl-js,Mapbox,Mapbox Gl Js,我有一个瓷砖集,我正在加载到我的地图(地图称为topleftmap)。我希望城市和其他标签加载到瓷砖上,而不是像Mapbox中的示例中那样,加载到下面: 我如何使用tilesets进行此操作?我有一个外部JS文件,用于加载到TileSet中,如下所示: topleftmapbox.addLayer({ "id": "currentProduct", "type": "raster", "source": { "type": "raster",
topleftmapbox.addLayer({
"id": "currentProduct",
"type": "raster",
"source": {
"type": "raster",
"tiles": ["tiles/" + productSelection + "/" + productLocation + "/{z}/{x}/{y}.png"],
"minzoom": 8,
"maxzoom": 10,
"scheme": "tms",
"tileSize": 256,
}});
所以这当然很好,但是标签在瓷砖下面。我在下面尝试过(使用Mapbox中的示例),但似乎不起作用:
var layers = topleftmapbox.getStyle().layers;
// Find the index of the first symbol layer in the map style
var firstSymbolId;
for (var i = 0; i < layers.length; i++) {
if (layers[i].type === 'symbol') {
firstSymbolId = layers[i].id;
break;
}
}
topleftmapbox.addLayer({
"id": "currentProduct",
"type": "raster",
"source": {
"type": "raster",
"tiles": ["tiles/" + productSelection + "/" + productLocation + "/{z}/{x}/{y}.png"],
"minzoom": 8,
"maxzoom": 10,
"scheme": "tms",
"tileSize": 256,
},firstSymbolId});
var layers=topleftmapbox.getStyle().layers;
//查找地图样式中第一个符号图层的索引
第一符号变量;
对于(变量i=0;i
最后,这里有一张图片显示了它的外观。我的磁贴有点透明,但是标签应该是亮白色的,就像远离数据的标签一样。有什么想法吗
你做的一切都对。您只是有一个轻微的语法错误:
},firstSymbolId});
这应该是:
}}, firstSymbolId);
这就是我醒得太久的时候发生的事!谢谢你再看一眼。