如何解决与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">© OpenMapTiles</a>','<a href="http://www.openstreetmap.org/about/" target="_blank">© 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中引入的二维图标和文本比例
这似乎在很大程度上解决了这个问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。