如何用OpenLayers对接tilemaker-server?仅显示部分水多边形问题排查
仅能看到tilemaker-server部分水多边形的问题排查
我的tilemaker-server已正常运行,可通过http://localhost:8080/访问地图。参考OpenLayers示例编写代码调用该服务,但仅能看到部分水多边形,请问问题出在哪里?
代码如下:
import MVT from 'ol/format/MVT.js'; import Map from 'ol/Map.js'; import VectorTileLayer from 'ol/layer/VectorTile.js'; import VectorTileSource from 'ol/source/VectorTile.js'; import View from 'ol/View.js'; import {Fill, Icon, Stroke, Style, Text} from 'ol/style.js'; const map = new Map({ layers: [ new VectorTileLayer({ declutter: true, source: new VectorTileSource({ attributions: '© <a href="https://www.mapbox.com/map-feedback/">Mapbox</a> ' + '© <a href="https://www.openstreetmap.org/copyright">' + 'OpenStreetMap contributors</a>', format: new MVT(), url: 'http://localhost:8080/{z}/{x}/{-y}.pbf', }), style: createMapboxStreetsV6Style(Style, Fill, Stroke, Icon, Text), }), ], target: 'map', view: new View({ center: [0, 0], zoom: 2, }), });
可能的问题及解决方向:
样式函数与tilemaker图层不匹配
你用的createMapboxStreetsV6Style是为Mapbox Streets V6瓦片设计的,而tilemaker生成的瓦片图层命名(比如水域类)大概率和Mapbox不一致。Mapbox的水域图层可能叫water、waterway,但tilemaker默认配置里可能是ocean、lake等,导致样式函数没匹配到这些图层,只有部分被识别的水多边形显示。瓦片坐标系/URL规则不兼容
检查tilemaker的瓦片坐标系是否为Web墨卡托(EPSG:3857),OpenLayers默认用这个,但如果tilemaker配置了其他坐标系会出问题。另外,试试把URL里的{-y}改成{y},部分瓦片服务不使用翻转的Y轴规则。tilemaker配置过滤了水域要素
查看tilemaker的config.json,是否在生成瓦片时过滤了部分水域?比如只保留了大尺度海洋,却过滤了湖泊、河流等小水域,或者某些缩放级别下没包含全部水域数据。自定义样式函数适配tilemaker图层
替换原有的createMapboxStreetsV6Style,针对tilemaker的实际图层名写样式:style: function(feature) { const layerName = feature.get('layer'); // 根据tilemaker实际图层名调整判断条件 if (['water', 'lake', 'ocean', 'river'].includes(layerName)) { return new Style({ fill: new Fill({ color: '#a8d1ff' }) }); } // 其他图层样式按需添加 }
内容的提问来源于stack exchange,提问作者Jarek
相关产品推荐
相关产品推荐

