0

I have a MapServer layer, Roads in this instance, and I've set its STATUS to ON. I want to render this as a WMS service using OpenLayers. So I've set all the Metadata Section in the LAYER section in the MAP file. Then in OpenLayers I have the following snippet:

 var params = {
              LAYERS: 'Roads',
              FORMAT: 'image/png',
              VERSION: '1.1.1',
       }

       var source = new ol.source.ImageWMS({
            url: 'http://localhost/cgi-bin/mapserv?map=/home/user/mapdata/fifth.map&layer=Roads',
          params: params
       });

       var layer = new ol.layer.Image({
            source: source     
       });

       var center = ol.proj.transform([21.768006, 39.556202], 'EPSG:4326', 'EPSG:3857');

       var view = new ol.View({
              center: center,
              zoom: 15
       });


       var map = new ol.Map({
            target: 'map',
            view: view,
            renderer: 'dom'
       });

       map.addLayer(layer);

However, the layer is never rendered, although in the url I pass the layer=Roads parameter. If I set the STATUS to default in the map file everything works well but in this occasion, not. Any idea?

8
  • Maybe related: renderer: 'dom' has been removed e.g github.com/openlayers/openlayers/releases/tag/v3.19.0
    – ThomasG77
    Commented Jan 31, 2017 at 15:32
  • hmm... I commented it out. Still the same... :\
    – Stefanos
    Commented Jan 31, 2017 at 15:35
  • Do you see any call to MapServer in Network tab of Chrome/FF debugger?
    – ThomasG77
    Commented Jan 31, 2017 at 15:37
  • I think so... in Network tab in the name section I see four five files being called. My html file, ol.js, ol.css, data/image:png;base... and the call to MapServer like 'mapserv?map=/home/user.....' (huge WMS link) In there there's parameter LAYERS=Roads. I guess it's the value of the params variable?
    – Stefanos
    Commented Jan 31, 2017 at 15:44
  • On the WMS call in the same Network tab, right click and then choose "Open in a new tab" to debug your MapServer call.
    – ThomasG77
    Commented Jan 31, 2017 at 15:48

2 Answers 2

1

The parameters should be: var params = { 'LAYERS': 'Roads', 'FORMAT': 'image/png', 'VERSION': '1.1.1', }

5
  • Thanks. I changed it but still nothing. The layer won't be rendered
    – Stefanos
    Commented Jan 31, 2017 at 15:36
  • Are you sure your wms server support the projection EPSG:3857 ?
    – cheesewind
    Commented Jan 31, 2017 at 15:45
  • hem...no. I've set the "wms_srs" to "EPSG:2100" (in the METADATA section of the MAP level). Should I add 3857 too? Can we add two "wms_srs" parameters. And if yes where should it be added? In the LAYER level metadata or the MAP level metadata ?
    – Stefanos
    Commented Jan 31, 2017 at 15:50
  • Well, two suggestions: 1. try EPSG:2100 in openlayers3 to see if layer displayed or not. 2. add EPSG:3857 to both of the above metadata sections
    – cheesewind
    Commented Jan 31, 2017 at 16:05
  • Read the official doc e.g By default layers inherit the SRS of their parent layer (the map’s PROJECTION in the MapServer case). For this reason it is not necessary (but still strongly recommended) to provide PROJECTION and wms_srs for every layer. If a layer PROJECTION is not provided then the top-level map projecion will be assumed. See section mapserver.org/ogc/wms_server.html#setup-a-mapfile-for-your-wms to see an example with multiple SRS
    – ThomasG77
    Commented Jan 31, 2017 at 16:06
0

Put all the projection you need in the web section of your mapfile

WEB
    METADATA
        'wms_enable_request'  '*'
        # Allow WMS service to serve multiple projections
        # Only EPSG, AUTO2, CRS codes are supported as part of WMS 1.3.0
        'wms_srs' 'EPSG:4326 EPSG:3857 EPSG:54009'
    END
END

Source from Mapserver doc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.