Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm able to use OpenLayers' OpenLayers.Layer.Mapserver declaration to generate a raster from GRIB data. I've read in the MapServer docs and on forums that it should be possible to get point information back from the raster using OL's WMSGetFeatureInfo. I've tried a few combinations of others' reported solutions. However, as the control is for a regular WMS and also nearly all of the solutions involve GeoServer, I've pretty much reached a wall. So this is my code:

<script type="text/javascript">

var map, info, wmsmap;


function init() {

    map = new OpenLayers.Map("map", {

        projection: new OpenLayers.Projection("EPSG:3857"),
        units: "m",
        maxResolution: 156543.0339,
        maxExtent: new OpenLayers.Bounds(
            -20037508, -20037508, 20037508, 20037508.34),
        displayProjection: new OpenLayers.Projection("EPSG:4326"),
        controls: [
            new OpenLayers.Control.Navigation(),
            new OpenLayers.Control.KeyboardDefaults(),
            new OpenLayers.Control.PanZoomBar(),
            new OpenLayers.Control.Scale(),
            new OpenLayers.Control.Attribution()
        ]

    });

    var osmLayer = new OpenLayers.Layer.OSM("OpenStreetMap");

// Test MapServer WMS layer

    wmsmap = new OpenLayers.Layer.MapServer( "grib plot", "/cgi-bin/mapserv", 
            {mode: "map",
             map: "wxmap/glmpvis.map", layers: "mosaic", format:'image/png',
         transparent:true, reaspect: "true"},

            {singleTile: true, ratio: 1, isBaseLayer: false, opacity: 1, visibility: true,
             projection: new OpenLayers.Projection("EPSG:3857")});

// add layers to map
   map.addLayers([osmLayer, wmsmap]);

// add controls

   map.addControl(new OpenLayers.Control.LayerSwitcher());
   map.addControl(new OpenLayers.Control.Permalink());

   map.addControl(new OpenLayers.Control.MousePosition(
       {div: document.getElementById('ex_llmousectl'),
        id: "ll_mouse", formatOutput: formatLonlats} ));
   map.addControl(new OpenLayers.Control.MousePosition( 
       {div: document.getElementById('utm_mousectl'),
         id: "utm_mouse", prefix: "UTM ", displayProjection: map.baseLayer.projection, numDigits: 0} ));
   map.setCenter(new OpenLayers.LonLat(-117, 33).transform(
        new OpenLayers.Projection("EPSG:4326"),
        map.getProjectionObject()),6);


   info =  new OpenLayers.Control.WMSGetFeatureInfo({

                     url: "/cgi-bin/mapserv",
                     maxFeatures: 1,
                     title: 'Identify features by clicking',
                     queryVisible: true,
                     layers: [wmsmap],
                     vendorParams: {

                         map: "wxmap/glmpvis.map",

                     },
                     eventListeners: {
                         getfeatureinfo: function(event) {
                             map.addPopup(new OpenLayers.Popup.FramedCloud(
                                     "chicken",
                                     map.getLonLatFromPixel(event.xy),
                                     null,
                                     event.text,
                                     null,
                                     true
                              )); //map.addPopup


                         } // getfeatureinfo
                     } // eventListeners

   });

   map.addControl(info);
   info.activate();

   function formatLonlats(lonLat) {
        var lat = lonLat.lat;
        var long = lonLat.lon;
        var ns = OpenLayers.Util.getFormattedLonLat(lat);
        var ew = OpenLayers.Util.getFormattedLonLat(long,'lon');
        return ns + ', ' + ew + ' (' + (Math.round(lat * 100) / 100) + ', ' + (Math.round(long * 100) / 100) + ')';
    }


} // end of init

</script>

And my mapfile (some url and file locations changed for privacy, but not necessary for this question)

MAP
  NAME "testgrib"
  IMAGETYPE      PNG
  EXTENT         -14000000 3000000 -7000000 7000000
  STATUS         ON
  SIZE           2145 1377

  SHAPEPATH      "../shapefiles"
  SYMBOLSET      "../symbols/symbols35.sym"
  FONTSET        "../fonts/fonts.list"
  DATAPATTERN "^.*$"
  IMAGECOLOR     255 255 255

  PROJECTION
   "init=epsg:3857"
  END
  WEB
    IMAGEPATH "test/img/tmp/ms_tmp/"
    IMAGEURL "http://localhost:8080/wxmap/test/img/tmp/ms_tmp/"
    METADATA
      "wms_title"                  "WMS Test " ## REQUIRED
      "wms_onlineresource"         "http://localhost:8080/cgi-bin/mapserv?" ## Recommended
      "wms_srs"                    "ESPG:3857 EPSG:4326 EPSG:4269 EPSG:3978 EPSG:900913" ## Recommended
      "wms_abstract"               "This text describes my WMS service." ## Recommended
      "wms_enable_request" "*"
      "ows_sld_enable" "true"
    # testing 
      "wms_feature_info_mime_type" "text/html"
    END
  END

  OUTPUTFORMAT
    NAME "png"
    DRIVER GD/PNG
    MIMETYPE "image/png"
    IMAGEMODE RGBA
    EXTENSION "png"
    TRANSPARENT ON
  END


  LAYER # GRIB attempt
    NAME         mosaic
    STATUS       ON
    TYPE         RASTER

    DATA         ../grib/ds.vis.bin

    CLASSITEM "[pixel]"
    METADATA
     "gml_include_items" "all"
     "wms_include_items" "all"
    END

# testing 
    DUMP TRUE
    HEADER  "../templates/test_header.html"
    TEMPLATE "../templates/test_body.html"
    FOOTER "../templates/test_footer.html"

    PROJECTION
     "proj=lcc"
     "lat_1=25" 
     "lat_2=25"
     "lat_0=0" 
     "lon_0=-95" 
     "x_0=0"
     "y_0=0"
     "a=6371200"
     "es=0.0"
     "+no_defs"
    END

    PROCESSING "NODATA=32129"
    PROCESSING "BANDS=01"
    PROCESSING "SCALE=0,11200"
    LABELITEM "[pixel]"

    CLASS
    NAME "< 1/4"
    EXPRESSION ([pixel] < 400 )
    STYLE
        COLOR 100 0 100
    END
    END
    CLASS
    NAME "1/4 - 1/2"
    EXPRESSION ([pixel] >= 400 AND [pixel] < 800 )
    STYLE
        COLOR 200 200 0
    END
    END
    CLASS
    NAME "1/2 - 3/4"
    EXPRESSION ([pixel] >= 800 AND [pixel] < 1200 )
    STYLE
        COLOR 150 0 0
    END
    END
    CLASS
    NAME "3/4 - 1"
    EXPRESSION ([pixel] >= 1200 AND [pixel] < 1600 )
    STYLE
        COLOR 200 0 200
    END
    END
    CLASS
    NAME "1 - 2"
    EXPRESSION ([pixel] >= 1600 AND [pixel] < 3200 )
    STYLE
        COLOR 100 100 0
    END
    END
    CLASS
    NAME "2 - 3"
    EXPRESSION ([pixel] >= 3200 AND [pixel] < 4800 )
    STYLE
        COLOR 255 153 0
    END
    END
    CLASS
    NAME "3 - 5"
    EXPRESSION ([pixel] >= 4800 AND [pixel] < 8000 )
    STYLE
        COLOR 0 0 200
    END
    END
    CLASS
    NAME "5 - 6"
    EXPRESSION ([pixel] >= 8000 AND [pixel] < 9600 )
    STYLE
        COLOR 0 100 0
    END
    END
    CLASS
    NAME "6 - 7"
    EXPRESSION ([pixel]  >= 9600 AND [pixel] < 11200 )
    STYLE
        COLOR 0 200 0
    END
    END
    CLASS
    NAME "> 7"
    EXPRESSION ([pixel] >= 11200 )
    STYLE
        COLOR 250 250 250
    END
    END

  END # End of mosaic layer

END 

And I need template files here for the response: test_header.html

<!-- MapServer Template -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/transitional.dtd">
<html>
  <head>
    <title>MapServer Template Sample</title>
  </head>

test_body.html

<body>
  band1: [value_0]
</body>

test_footer.html

</html>

I'm not positive that the test_body.html is correct. But, the main issue is that when I click on the image, nothing happens. Firebug doesn't indicate any query is sent to MapServer for the layer. Inserted a breakpoint in the WMSGetFeatureInfo code at the getfeatureinfo function but the execution didn't go into the code.

As I realize that perhaps the issue centered around not declaring the layer as OpenLayers.Layer.WMS instead of MapServer, I also attempted to create the layer using OpenLayers.Layer.WMS. But, that created issues of its own. Kind of a toss up then which question to ask. Might ask the other one later. So, if anyone has any thoughts on how to use this with the Mapserver layer or perhaps a different control, I'd really appreciate the help. Thanks!

share|improve this question

2 Answers 2

up vote 3 down vote accepted

I got maps like yours working and the only difference that I could spot is that I use OpenLayers.Layer.WMS instead of OpenLayers.Layer.MapServer.

Since GetFeatureInfo is a WMS protocol operation OL correctly should not apply it to Mapserver layers (even though Mapserver is fully capable of speaking WMS). Try to create the layer as follows:

var wmsmap = new OpenLayers.Layer.WMS( "grib plot",
 "/cgi-bin/mapserv.exe?map=wxmap/glmpvis.map",
     {layers: 'mosaic',
      srs: 'YOUR SRS HERE',
      format: 'image/png',
      isBaseLayer: false,
      visibility: true
     }
);
share|improve this answer
    
Thanks and perhaps that's the real issue here. I mentioned that I was going to ask a different question initially, but thought I'd ask this instead. But, I've tried what you suggested. I get an error indicating that the imgext and mapext aren't set which is what is sent using OL's MapServer layer declaration. So, maybe the real issue is that our MapServer is not properly configured for the WMS side and therefore only the OL MapServer declaration works. Because you have this working, I'm going to accept your answer and ask the other in a new question. Look for it soon. –  teknocreator Mar 4 '12 at 16:18
    
BTW, I should've asked if you have a working example of OL WMS and MapServer? I've seen other forum posts where the OL WMS works for GeoServer, but only found references that it should work for MapServer too. Not actual examples. And the examples on the OL pages only use OL's MapServer Layer declaration. Even if it's only geoserver, I still think your answer is probably correct due to the other problem I noted in my next question. Thanks! –  teknocreator Mar 4 '12 at 17:28

I think your problem is due you not set a proxy in OpenLayers.

The request to get feature info is made using AJAX (OpenLayers.Request.GET). If your server is not configured to accept cross domain request then you need to use an script (the proxy) to make the request.

Using a proxy script the flow is as follows:

  • You load your web page from your server.
  • If you make an AJAX request it is sent to your server proxy script.
  • The script makes the "real" request to the desired server and returns the data.

Also ensure your layer is configured to be queryable if you are using a WMS server.

share|improve this answer
    
Thanks for you comment. But, in attempting to solve this, I also used unicoletti's suggestion by switching to OL's WMS Layer definition. I get a response back from the server with an error that I commented on to unicoletti, which is leading me more and more to believe that it's our WMS setup that's wrong. This is also our server rather an a cross domain issue and I'm able to perform other AJAX (OL GET) calls to the server without issues. Plus the GetCapabilities indicates that GET and POST are enabled for the layer. And the layer is queryable too. Still, thanks for your suggestions! –  teknocreator Mar 4 '12 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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