【问题标题】:Visible 1-pixel offset when switching between WMS and WMTS layers from the same source in Openlayers在 Openlayers 中从同一源在 WMS 和 WMTS 层之间切换时可见 1 像素偏移
【发布时间】:2018-08-13 10:10:18
【问题描述】:

我们有一个自定义的类似 OSM 的图块源,我们使用 Mapproxy 作为 WMTS 和 WMS 服务,并在 Openlayers 查看器中展示。

我们添加了一个图层切换器控件来在 2 个图层之间滑动,它们显示良好,除了一个小的 1 像素偏移。在尝试使用“precompose”事件弥补偏移量并设置 WMS 层的“event.frameState.pixelRatio”后,我发现偏移量在某些缩放级别是不同的。

例如,在缩放 3 和 6 处,我们必须应用 (0,-1) 偏移,而对于缩放 7、10、11 等,我们必须对 WMS 图层应用 (0,1) 偏移以匹配WMTS 层。

我猜会涉及一些舍入误差,这是 WMS 调用无法避免的?或者这个1像素偏移问题可以解决吗?

在 QGIS 中,当我引入两个图层时,它们看起来完美对齐。

【问题讨论】:

    标签: openlayers wms


    【解决方案1】:

    作为一个实验,您可能希望了解从具有自定义磁贴 url 的基本 XYZ 源构建的图层如何与您的每个源一起运行。我没有您的图层的详细信息,但对于 WMTS,您将使用 tileUrlFunction 坐标 [0] 来索引矩阵 ID,其中 [1] 和 [2] 给出列和行。对于 WMS,url 中的参数可能会与可以从 tileUrlFunction 坐标计算的 BBOX 分开固定。以下是以这种方式实现的 WMTS 和 WMS 源的示例:

    source1: new ol.source.XYZ({
                 attributions: [attribIGN],
                 tileGrid: new ol.tilegrid.TileGrid({ resolutions: resolutions,
                                                      origin: origin, tileSize: tileSize }),
                 tileUrlFunction: function(coordinate) {
                     return "https://wxs.ign.fr/" + keyIGN +
                            "/geoportail/wmts?layer=GEOGRAPHICALGRIDSYSTEMS.MAPS" +
                            "&style=normal&tilematrixset=PM&Service=WMTS&Request=GetTile&Version=1.0.0" +
                            "&Format=image%2Fjpeg&TileMatrix=" + ignMatrixIds[coordinate[0]] +
                            "&TileCol=" + coordinate[1] + "&TileRow=" + (-(coordinate[2]+1));
                 },
             }),
    
    source2: new ol.source.XYZ({
                 attributions: [attribOSM],
                 tileGrid: new ol.tilegrid.TileGrid({ resolutions: resolutions,
                                                      origin: origin, tileSize: tileSize }),
                 tileUrlFunction: function(coordinate) {
                     return "http://129.206.228.72/cached/osm?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image%2Fpng" +
                            "&TRANSPARENT=true&LAYERS=osm_auto%3Aall&WIDTH=256&HEIGHT=256&SRS=EPSG%3A900913&STYLES=&BBOX=" +
                            this.getTileGrid().getTileCoordExtent(coordinate).toString();
                 },
             }),
    

    【讨论】:

    • 在将 IGN France 层定义为简单的 XYZ 时,我得到了明显更好的质量重投影。我怀疑差异可能是由于通常的 WMTS 设置使用 ol.tilegrid.WMTS 而不是 ol.tilegrid.TileGrid。
    • 了解这一点很有用,但我们的代码用于演示如何在 WMTS 和 WMS 实现中使用我们的自定义地图。我会将此作为 OL 社区的错误请求。
    猜你喜欢
    • 2020-04-26
    • 2020-12-22
    • 2020-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    相关资源
    最近更新 更多