Reputation: 119
I'm trying to load the Global Multi-Resolution Topography (GMRT) WMS into an openlayers map using OpenStreetMap (OSM) as base layer. The URL for the GMRT webservice is: https://www.gmrt.org/services/mapserver/wms_merc?
The code I'm trying is:
<!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>
The code does not output the GMRT layer, but only the base layer with OSM in it.
When scanning through the connections established by the browser, I find a successful request to 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
I've checked this post, which appears to be a similar problem, and also looked at the GetCapabilities, but the returned XML doesn't say a lot to me.
Any ideas of what I'm doing wrong? I'm new to openlayers, so I'd appreciate as much detail as possible.
Upvotes: 0
Views: 133
Reputation: 17962
ImageWMS and TileWMS always need a params
option to specify the WMS LAYERS parameter
source: new ol.source.ImageWMS({
url: 'https://www.gmrt.org/services/mapserver/wms_merc?',
params: { 'LAYERS': 'GMRT' }
})
Upvotes: 1