如何使用WMTS错误的地图覆盖来修复EPSG:4326 [英] How to fix EPSG:4326 with WMTS incorrect map overlay

查看:457
本文介绍了如何使用WMTS错误的地图覆盖来修复EPSG:4326的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管设置了投影,地图还是偏斜的.我从openlayers 5文档中尝试了该示例,该示例仍然有效,我不知道自己在做什么错.

Despite the projection setting, the map is skewed. I tried the example from the openlayers 5 documentation and it works, I don't know what I'm doing wrong.

initializeMap() {
    const projection = getProjection("EPSG:4326");
    const projectionExtent = projection.getExtent();
    let size = getWidth(projectionExtent) / 256;
    let resolutions = new Array(14);
    const matrixIds = new Array(14);

    for (let z = 0; z < 14; ++z) {
      resolutions[z] = size / Math.pow(2, z);
      matrixIds[z] = z;
    }

    this.map = new Map({
      layers: [
        new TileLayer({
          source: new OSM()
        }),
        new TileLayer({
          crossOrigin: true,
          source: new WMTS({
            url:
            "http://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/ORTO",
            matrixSet: ["EPSG:4326"],
            projection: projection,
            tileGrid: new WMTSTileGrid({
              origin: getTopLeft(projectionExtent),
              resolutions: resolutions,
              matrixIds: matrixIds
            })
          })
        })
      ],
      target: "map",
      view: new View({
        center: fromLonLat([19.4569911, 51.7687323]),
        zoom: 4
      })
    });
  }

这是有问题的屏幕.

推荐答案

我已经检查了该服务的GetCapabilities,并且tilegrid并非基于全局投影范围(相反,它使用[13.8、48.8、24.4、55 ],并且图块大小为512).虽然您可以更新代码以反映出,让OpenLayers解析GetCapabilities来创建源选项更容易:

I've checked the GetCapabilities for that service and the tilegrid isn't based on the global projection extent (instead it uses [13.8, 48.8, 24.4, 55] and the tile size is 512). While you could update your code to reflect that it is easier to let OpenLayers parse the GetCapabilities to create the source options:

var parser = new ol.format.WMTSCapabilities();
var url = 'https://mapy.geoportal.gov.pl/wss/service/WMTS/guest/wmts/ORTO?SERVICE=WMTS&REQUEST=GetCapabilities';

fetch(url).then(function(response) {
  return response.text();
}).then(function(text) {
  var result = parser.read(text);
  var options = ol.source.WMTS.optionsFromCapabilities(result, {
    layer: 'ORTOFOTOMAPA',
    matrixSet: 'EPSG:4326',
    crossOrigin: true,
  });
  //console.log(options);

  this.map = new ol.Map({
    layers: [
      new ol.layer.Tile({
        source: new ol.source.OSM()
      }),
      new ol.layer.Tile({
        source: new ol.source.WMTS(options),
        opacity: 0.5
      })
    ],
    target: "map",
    view: new ol.View({
      center: ol.proj.fromLonLat([19.4569911, 51.7687323]),
      zoom: 4
    })
  });

});

html, body, .map {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
}

<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet" />
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<div id="map" class="map"></div>

这篇关于如何使用WMTS错误的地图覆盖来修复EPSG:4326的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆