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 trying to load a raster into my browser using Openlayers. I can examine my WMS raster layer using OpenJump, but I'm not able to get it to load into my browser. My mapfile is as follows:

MAP      
    ###########
    NAME         "ny_pop"
    SHAPEPATH     "/v0.3/mapserver/"                                                                              
    UNITS         meters
    EXTENT        -8269337 4955373 -8190365 5005745 
    SIZE          1000 1000
    STATUS        ON
    DEBUG         ON
    IMAGETYPE     "png"

    ###########    
    PROJECTION
        "init=epsg:900913"
    END

    ###########
OUTPUTFORMAT
  NAME "png"
  DRIVER AGG/PNG
  MIMETYPE "image/png"
  IMAGEMODE RGB
  EXTENSION "png"
  FORMATOPTION "GAMMA=0.75"
END

    ###########    
    WEB             
        METADATA
            "wms_title"           "WMS Pop Tif"
            "wms_onlineresource"  "http://mysite.com/mapserv.cgi?map=raster_1.map&"            
            "wms_enable_request"  "GetMap GetFeatureInfo GetCapabilities"
        END
    END

    ###########
    LAYER
        NAME      "ny_pop"
        DATA      /home/mysite/webapps/htdocs/v0.3/mapserver/ny_pop.tif
        STATUS    ON
        TYPE      RASTER   
        METADATA
            "wms_title"  "WMS NY Raster"
            "wms_srs"    "EPSG:900913"
        END
    END

    ########### 
END

Everything (map, raster and mapfile) are using EPSG:900913, and I have an existing map (centered around New York) which I am adding the layer rasterLayer to. My javascript is as follows:

function generateRaster(){

    console.log('get map bounds');
    bounds = map.getExtent();

    rasterLayer = new OpenLayers.Layer.WMS( 
           "ny_pop",
           "http://mysite.com/mapserv.cgi?", 
           {map: 'raster_1.map'},
           {'maxExtent': bounds}
       );
    console.log(rasterLayer);
    map.addLayer(rasterLayer);

}

I'm trying to limit the raster to the bounds of the map using the {'maxExtent': bounds} command, but I also tried with just the map name and URL and it did not work either. I'm still trying to get my head around the .map format, so there could be some mistakes there also. However, as I could view the raster in OpenJump I assumed it was ok.

EDIT: I updated my javascript to the following:

rasterLayer = new OpenLayers.Layer.WMS( 
   "NY Population layer..... ",
   "http://urbmet.webfactional.com/mapserv.cgi?", 
   {map: 'raster_1.map', layers: 'ny_pop'}
);

but still nothing shows up on the map. I've added a screencapture of my firebug output - this is the contents of console.log(rasterLayer).

enter image description here

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You need to set the layers parameter in the WMS constructor in OpenLayers:

rasterLayer = new OpenLayers.Layer.WMS( 
       "This Can Be Any Name",
       "http://mysite.com/mapserv.cgi?", 
       {map: 'raster_1.map', layers: 'ny_pop'},
       {'maxExtent': bounds}
   );

http://trac.osgeo.org/openlayers/wiki/Layer/WMS

You also may have to add in the EPSG:900913 definition to your proj\nad\epsg definitions in your MapServer installation.

I'm assuming your TIF file is georeferenced, and falls within the extents you set in your MAP file: -8269337 4955373 -8190365 5005745

I usually set the SIZE parameter to match the default OpenLayers tiles:

SIZE 256 256

I also set the STATUS to OFF for both Map and Layer - calling the WMS will then only bring back the layers you specify.

You can also set up an error log to see if any errors are recorded by MapServer:

CONFIG "MS_ERRORFILE" "tmp/ms.log"

Finally what are you getting back - empty images, or error messages?

share|improve this answer
    
Thanks @geographika. I added the layers:'ny_pop' and checked that EPSG:900913 is in proj\nad\epsg (it is), but still no luck. Could there be anything else that I am doing wrong? It seems that the osgeo examples do not typically have a map:'...' component. –  djq Jan 25 '12 at 17:31
    
I just updated my question a little. I added the error logging, and updated the tile size to 256, but no errors are produced when I run the javascript. How can I tell if my tif is georeferenced? I exported it from ArcGIS and copied it to my server so I assumed it was. Nothing is happening in the browser, no error messages or empty images. –  djq Jan 25 '12 at 17:56
    
You can take off the {'maxExtent': bounds} parameter - OpenLayers will call the WMS when it is visible in the map bounds. –  geographika Jan 25 '12 at 18:08
    
Is it possible that it is sending the WMS request using epsg:4362? As I looked through the firebug output I saw the line yx Object { EPSG:4326=true} –  djq Jan 25 '12 at 18:10
    
@celenius - install Fiddler or look at the net tab in Firebug to see the exact requests sent from the browser –  geographika Jan 25 '12 at 18:43

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.