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

问题描述

我想在OpenLayers中包括一个Vector Tile Map,并使用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对这个问题的评论。

您将需要使用OpenLayers版本6.3.1,因为olms似乎基于版本6.1.0 https://github.com/openlayers/ol-mapbox-style/blob/master/package.json#L36,因此它不支持版本6.4.0中引入的二维图标和文本比例

这似乎在很大程度上解决了这个问题。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...