2016-04-21 990 views
6

如何为mapbox-gl ..中的图层文本字段添加背景颜色或如何完成,以便在文本字段上有背景框如何在mapbox-gl中为图层文本字段添加背景颜色

map.addLayer({ 
    "id": "markers", 
    "type": "symbol", 
    "source": "markers", 
    "layout": { 
     "icon-image": "{marker-symbol}-15", 
     "text-field": "{title}", 
     "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], 
     "text-offset": [0, 0.6], 
     "text-anchor": "top" 
    } 
}); 

回答

1

虽然我也不知道如何绘制背景中,我们可能会寻找它掩盖了自定义标签下的任何其他文本,使其弹出,更清晰的同样的事情。如果是这样,我确实发现你可以添加一个“光环”来达到预期的效果。

"layout": { 
       "icon-image": symbol + "-15", 
       "icon-allow-overlap": true, 
       "text-field": symbol, 
       "text-font": ["Open Sans Bold", "Arial Unicode MS Bold"], 
       "text-size": 11, 
       "text-transform": "uppercase", 
       "text-letter-spacing": 0.05, 
       "text-offset": [0, 1.5] 
      }, 
      "paint": { 
       "text-color": "#202", 
       "text-halo-color": "#fff", 
       "text-halo-width": 2 
      }, 

这是从他们的网站上的this example