与 olms 一起使用时,OpenLayers t.getScaleArray 不是函数

OpenLayers t.getScaleArray is not a function when using with olms

我想在 OpenLayers 中包含一个矢量切片地图,并使用 GL 样式文件来设置地图样式。因此,我正在使用 ol mapbox 样式(olms)。我包括了 ol 版本 6.4.3 和 olms 版本 6.1.3。我想在 ID 为“map”的 DOM 对象中渲染我的地图。我从 OpenMapTiles 服务器获取我的图块,我自己托管(在 localhost:32768 上)。 这是我的代码:

const vectorTileLayer = new ol.layer.VectorTile({
  source: new ol.source.VectorTile({
    attributions: [
      '<a href="http://www.openmaptiles.org/" target="_blank">&copy; OpenMapTiles</a>',
      '<a href="http://www.openstreetmap.org/about/" target="_blank">&copy; OpenStreetMap contributors</a>',
    ],
    format: new ol.format.MVT(),
    url: 'http://localhost:32768/data/v3/{z}/{x}/{y}.pbf',
    maxZoom: 18,
  }),
});

this.map = new ol.Map({
  target: 'map',
  loadTilesWhileAnimating: true,
  loadTilesWhileInteracting: true,
  view: new ol.View(this.viewConfig),
});

fetch('http://localhost:32768/styles/osm-bright/style.json').then(function(response) {
  response.json().then(function(glStyle) {
    olms.applyStyle(vectorTileLayer, glStyle, 'openmaptiles').then(function() {
      me.map.addLayer(vectorTileLayer);
    });
  });
});

我尝试了不同来源的不同实现(使用 stylefunction() 函数,使用 apply() 函数)并排除了所有其他可能导致错误的因素。

如果我用地图加载页面,我会收到以下错误:

TextBuilder.js:502 Uncaught TypeError: t.getScaleArray is not a function
at e.setTextStyle (TextBuilder.js:502)
at Point (vector.js:239)
at vector.js:123
at Fo (vector.js:102)
at e.renderFeature (VectorTileLayer.js:565)
at e.x (VectorTileLayer.js:258)
at d (VectorTileLayer.js:271)
at e.updateExecutorGroup_ (VectorTileLayer.js:286)
at e.prepareTile (VectorTileLayer.js:131)
at e.dispatchEvent (Target.js:114)

当我没有从我的 Tile Server 获取样式(并使用 olms 应用它们),并在创建地图后立即添加图层时,我没有收到错误,但当然我也没有样式。

我还在这个样式文件中包含了需要的字体。

对于所有遇到相同问题的人,请查看 Mike 对该问题的评论。

You will need to use OpenLayers version 6.3.1 as olms appears to be based on version 6.1.0 https://github.com/openlayers/ol-mapbox-style/blob/master/package.json#L36 so it doesn't support two dimensional icon and text scale introduced in version 6.4.0

这似乎解决了大部分问题。