【问题标题】:'use of "text-field" requires a style "glyphs" property' when using a plain background\'使用 \"text-field\" 在使用纯背景时需要样式 \"glyphs\" 属性\'
【发布时间】:2023-02-20 19:38:01
【问题描述】:

根据this answer,我使用的是纯背景,而不是 MapBox 样式

var map = new mapboxgl.Map({
    container: 'map',
    style: {
      version: 8,
      sources: {},
      layers: [
        {
          id: 'background',
          type: 'background',
          paint: {'background-color': 'white'}
        }
      ]
    }
});

我添加了一个 GeoJSON 点层,我正在尝试标记它:

'layout': {
  'text-field': ['get', 'name'],
  'text-font': ['Open Sans Semibold', 'Arial Unicode MS Bold'],
},

如果我为地图使用标准的 MapBox 样式,则该层被正确标记。但是如果我使用前面提到的空白底图,该层将返回错误:

使用“文本字段”需要样式“字形”属性

Searching这个错误信息表明我需要添加一个glyphs选项:

"glyphs":"mapbox://fonts/mapbox/{fontstack}/{range}.pbf""glyphs":"https://fonts.openmaptiles.org/{fontstack}/{range}.pbf"

但是,这些选项都不能阻止错误消息,并且图层不会被标记。

使用空底图时,glyphs 参数的正确语法是什么?

【问题讨论】:

    标签: mapbox mapbox-gl-js


    【解决方案1】:

    作为解决方法,我在 MapBox Studio 中创建了一个新的空白样式并将其用作底图。在此之后,标签正确显示。

    var map = new mapboxgl.Map({
      style: mapbox://styles/my-blank-map,
      ...
    })
    

    不过,我仍然想知道是否有一种编程方式可以使用 MapBox GL-JS API 来执行此操作。

    【讨论】:

      【解决方案2】:

      我为我的样式选项复制了它,当我以前遇到与您相同的错误时,它工作正常,没有错误:

      {
        "version": 8,
        "name": "Empty",
        "metadata": {
          "mapbox:autocomposite": true
        },
        "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf",
        "sources": {},
        "layers": [
          {
            "id": "background",
            "type": "background",
            "paint": {
              "background-color": "rgba(0,0,0,0)"
            }
          }
        ]
      }
      

      https://github.com/mapbox/mapbox-gl-styles/blob/master/styles/empty-v8.json

      【讨论】:

        猜你喜欢
        • 2015-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-07
        • 1970-01-01
        • 2016-07-24
        • 2019-02-19
        • 2019-03-02
        相关资源
        最近更新 更多