如何在openlayers中加载全局多分辨率地形(GMRT)Web地图服务(WMS)?

时间:2019-07-11 13:55:26

标签: openlayers

我正在尝试使用OpenStreetMap(OSM)作为基础层将Global Multi-Resolution Topography (GMRT) WMS加载到openlayers地图中。 GMRT网络服务的URL是:https://www.gmrt.org/services/mapserver/wms_merc

我正在尝试的代码是:

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
    <style>
        .map {
            height: 400px;
            width: 100%;
        }
    </style>

    <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>

    <title>OpenLayers example</title>

</head>

<body>

<h2>My Map</h2>

<div id="map" class="map"></div>

<script type="text/javascript">
    var map = new ol.Map({
        target: 'map',
        layers: [
            new ol.layer.Tile({
                source: new ol.source.OSM()
            }),
            new ol.layer.Image({
                source: new ol.source.ImageWMS({
                    url: 'https://www.gmrt.org/services/mapserver/wms_merc?'
                })
            })
        ],
        view: new ol.View({
            center: ol.proj.fromLonLat([37.41, 8.82]),
            zoom: 4
        })
    });
</script>

</body>
</html>

该代码不会输出GMRT层,而只会输出其中包含OSM的基础层。

通过浏览器建立的连接进行扫描时,我发现对www.gmrt.org的请求成功:

GEThttps://www.gmrt.org/services/mapserver/wms_merc?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&CRS=EPSG%3A3857&STYLES=&WIDTH=1235&HEIGHT=600&BBOX=-1873624.4373262404%2C-1947003.9844800094%2C10209540.993994422%2C3923359.7878215266
[HTTP/1.1 200 OK 343ms]

SERVICE WMS
VERSION 1.3.0
REQUEST GetMap
FORMAT  image/png
TRANSPARENT true
CRS EPSG:3857
STYLES  
WIDTH   1235
HEIGHT  600
BBOX    -1873624.4373262404,-1947003.9844800094,10209540.993994422,3923359.7878215266

我已经检查了这个post,这似乎是一个类似的问题,并且还查看了GetCapabilities,但是返回的XML对我没有多大意义。

任何关于我做错事情的想法吗? 我是openlayers的新手,所以我希望尽可能多的细节。

1 个答案:

答案 0 :(得分:1)

ImageWMS和TileWMS始终需要一个params选项来指定WMS LAYERS参数

source: new ol.source.ImageWMS({
    url: 'https://www.gmrt.org/services/mapserver/wms_merc?',
    params: { 'LAYERS': 'GMRT' }
})