简体   繁体   English

将OpenLayers从4.6.5升级到5.3.0后,TileWMS没有显示

[英]TileWMS' not showing after upgrading OpenLayers from 4.6.5 to 5.3.0

I had an OpenLayers 4.6.5 application, which showed a map, and on top of that had the option to turn on and off some overlays. 我有一个OpenLayers 4.6.5应用程序,其中显示了地图,并且在其上面还可以选择打开和关闭一些叠加层。

The overlays are of the type TileWMS, and seemed to work perfectly. 叠加层类型为TileWMS,并且看起来效果很好。

At first i got called OpenLayers remotely like this: 最初,我像这样远程调用了OpenLayers:

<script src="https://openlayers.org/en/v4.6.5/build/ol.js" type="text/javascript"></script>

But i need to store do it locally instead, and at the same time upgrade to 5.3.0. 但是我需要将其存储在本地,同时升级到5.3.0。 So i downloaded the v5.3.0-dist.zip, added the files and replaces the above with: 因此,我下载了v5.3.0-dist.zip,添加了文件并将其替换为:

<script src="./lib/ol/ol.js"></script>

Everything seems to work as before, except for the TileWMS, which simply isn't showing. 除了TileWMS之外,其他所有内容似乎都可以正常工作,而后者根本没有显示。

As far as i can tell there is nothing, in the upgrade notes , indicating that something should have changed. 据我所知, 升级说明中没有任何内容,表明某些内容已经更改。

I have tried excluding unnecessary parts of my JavaScript, so let me know if i left out too much: 我已尝试排除JavaScript不必要的部分,所以请告知我是否遗漏了太多内容:

var token = "123456thisisnotmytoken";

var myProjection = new ol.proj.Projection({
    code: projCode,
    units: "m",
    extent: [120000, 5661139.2, 1378291.2, 6500000]
});

var projection = GetProjection(myProjection);
var projectionExtent = projection.getExtent();

const map = new Map({
    target: "map",
    layers: [
        new Group({
            "title": "Base maps",
            layers: [
                new ol.layer.Tile({...
                }),
                new ol.layer.Tile({...
                })
            ]
        }),
        new Group({
            "title": "Overlays",
            layers: [
                new ol.layer.Tile({
                    title: "Matrikel",
                    type: "overlay",
                    visible: true,
                    opacity: 1.0,
                    zIndex: 1000,
                    source: new ol.source.TileWMS({
                        url: "https://services.kortforsyningen.dk/mat?token=" + token,
                        params: {
                            "LAYERS": "MatrikelSkel,Centroide",
                            "VERSION": "1.1.1",
                            "TRANSPARENT": "true",
                            "FORMAT": "image/png",
                            "STYLES": ""
                        },
                    })
                }),
                new ol.layer.Tile({
                    title: "Hillshade",
                    type: "overlay",
                    visible: false,
                    opacity: 1.0,
                    zIndex: 900,
                    source: new ol.source.TileWMS({
                        url: "https://services.kortforsyningen.dk/dhm?token=" + token,
                        params: {
                            "LAYERS": "dhm_terraen_skyggekort_transparent_overdrevet",
                            "VERSION": "1.1.1",
                            "TRANSPARENT": "true",
                            "FORMAT": "image/png",
                            "STYLES": ""
                        },
                    })
                })
            ]
        }),
    ],
    view: view
});

map.addControl(new ol.control.LayerSwitcher());

I get that the second TileWMS is hidden as default, but i have tried turning it on and off in the LayerSwitcher, which worked before the upgrade. 我知道第二个TileWMS默认是隐藏的,但是我尝试在LayerSwitcher中将其打开和关闭,该操作在升级之前就起作用了。

Any suggestions pn how i fix this? 任何建议pn我如何解决这个问题?

The problem was the projection in my View! 问题出在我看来是投影!

I changed it from 我从

GetProjection("EPSG:25832") GetProjection(“ EPSG:25832”)

to

myProjection myProjection

So now it looks like this: 所以现在看起来像这样:

var view = new ol.View({
  center: [606985, 6231744], // EPSG:25832
  zoom: 2,
  resolutions: [1638.4, 819.2, 409.6, 204.8, 102.4, 51.2, 25.6, 12.8, 6.4, 3.2, 1.6, 0.8, 0.4, 0.2],
  projection: myProjection,
  minZoom: 2,
})

myProjection looks like this: myProjection看起来像这样:

var projCode = "EPSG:25832";
var myProjection = new ol.proj.Projection({
  code: projCode,
  units: "m",
  extent: [120000, 5661139.2, 1378291.2, 6500000]
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM