6

I have set up MapServer WMS on the localhost by the following map file:

MAP
  NAME "Prvi_WMS"
  SIZE 600 300              # 600 by 300 pixel image output
  PROJECTION
       "init=epsg:4326"
  END  
    #EXTENT -180 -90 180 90
    WEB
    IMAGEPATH "/ms4w/tmp/ms_tmp/"
    IMAGEURL "/ms_tmp/"
    METADATA
      "wms_title" "My Global Map WMS Server"
      "wms_onlineresource" "http://localhost/cgi-bin/mapserv.exe?mode=map&map=c:/ms4w/Apache/htdocs/MapFile06_wms.map&"
      "wms_enable_request" "*"
      "wms_srs" "EPSG:4326"
    END
  END

  LAYER

    NAME countries
    TYPE POLYGON
    STATUS DEFAULT
    DATA "/ms4w/data/countries_simpl.shp"
    MINSCALE 1000
    MAXSCALE 1000000000     
    PROJECTION
       "init=epsg:4326"
    END  
    EXTENT -180 -90 180 90

    CLASSITEM 'NAME'
    CLASS
      NAME 'Bulgaria'
      EXPRESSION 'Bulgaria'
      OUTLINECOLOR 100 100 100
      COLOR 255 255 150
    END

    CLASS
      NAME 'All Countries'
      EXPRESSION ("[NAME]" ne 'Bulgaria')
      STYLE
        OUTLINECOLOR 100 100 100
      END
    END
    METADATA
      "wms_title" "World Boundaries"
      "wms_onlineresource" "http://localhost/cgi-bin/mapserv.exe?" 
      "wms_srs" "EPSG:4326"
      "wms_enable_request" "*"
    END
  END
END

then, I checked GetCapabilities and GetMap requests and the results seem fine. However, I have problems getting the map inside the OpenLayers. Here is how I define my WMS layer:

<html>
<head>
    <title>Karta</title>
    <link rel="stylesheet" href="openlayers/theme/default/style.css" type="text/css">
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script  type="text/javascript">
    function inicializacija(){
        var options = {
            projection: new OpenLayers.Projection("EPSG:900913"),
            units: "m",
            numZoomLevels: 18,
            maxResolution: 156543.0339,
            maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34)
            };
         var map = new OpenLayers.Map("map-id", options);
         var osm = new OpenLayers.Layer.OSM("Open Street Map");
         var wms = new OpenLayers.Layer.MapServer( "World Map", "http://localhost/cgi-bin/mapserv.exe", {layers: 'countries',map: '/ms4w/Apache/htdocs/MapFile06_wms.map', srs: 'EPSG:4326'} );

        map.addLayers([osm,wms]);
        map.addControl(new OpenLayers.Control.LayerSwitcher());
        map.addControl(new OpenLayers.Control.MousePosition());


        map.zoomToExtent(new OpenLayers.Bounds(1490000, 5600000,1850000, 5900000));
    }
</script>
    <style>
        #map-id {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body onload= 'inicializacija()'>
    <h1>Primer prekrivanja slojev in izbire podlag</h1>
    <div id="map-id"></div>
</body>
</html>

The WMS layer shown in OpenLayers is completely white. What am I missing?

1
  • You need to remove mode=map& otherwise you won't get a WMS response
    – nmtoken
    Commented Feb 20, 2019 at 21:17

1 Answer 1

7

You say you have checked the GetCapabilities and GetMap requests/responses which indicates you are running MapServer as a WMS. Thus you need to be using a WMS layer in OpenLayers - I'm not sure of the status of the MapServer layer. so you need something like:

    map = new OpenLayers.Map( 'map' );
    layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
            "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
    map.addLayer(layer);

UPDATE

You'll need to provide a wms_srs element for each projection you need in your map file to enable reprojection (see http://mapserver.org/ogc/wms_server.html#setting-up-a-wms-server-using-mapserver)

7
  • When I tried using OpenLayers.Layer.WMS for serving MapServer WMS I get empty tiles.
    – Matej
    Commented Jan 3, 2012 at 9:45
  • I think we'll need to see all the openlayers code then
    – Ian Turton
    Commented Jan 3, 2012 at 9:51
  • When I tried using OpenLayers.Layer.WMS for serving MapServer WMS I get EMPTY tiles as oposed to WHITE tiles with the MapServer layer So this leads me to the thought that MapServer SRS could be the problem.. When I checked GetMap request, I noticed that BBOX variable behaved strangely: the returned image did not show the correct BBOX... Is there possibly a catch with the coordinate system?
    – Matej
    Commented Jan 3, 2012 at 9:55
  • 1
    almost certainly projections are the problem - that was why I asked to see all the code. Are you perhaps using Google Maps as a base layer?
    – Ian Turton
    Commented Jan 3, 2012 at 10:16
  • 2
    Your projection is defined by the baselayer so when you use Google or OSM the projection will be 900913 which will give you a bounding box in meters. Try making a simple example with just your wms layer in it to check the WMS is working first
    – Ian Turton
    Commented Jan 3, 2012 at 10:26

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.