3

I have several raster layers defined in mapfile:

   LAYER
     NAME "01"
     TYPE raster
     STATUS off
     OPACITY 30
     DATA "01.png"
  END

LAYER NAME "02" TYPE raster STATUS off OPACITY 30 DATA "02.png" END

LAYER NAME "03" TYPE raster STATUS off OPACITY 30 DATA "03.png" END

They are in .png format in raster folder on my server (data/www/project4/raster).

I need to insert button which will update my map with raster. First button is 01, and when I click on that button, raster should be rendered on my map. Also, I'm interested is there an option where I can click on some button just to open menu with three buttons which will lead rendering those rasters.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
againstflow
  • 5,034
  • 18
  • 56
  • 87

1 Answers1

4

One easy way is to first, change all your Layer entries to STATUS ON.

Then expose the whole thing as a WMS service. IMHO, the documentation makes it seem harder than what it is. You just need to add metadata entries for each LAYER entry like:

LAYER
  NAME "01_name"
  TYPE raster
  STATUS ON
  OPACITY 30
  DATA "01.png"
  METADATA
    'wms_title'        '01_name'
    'wms_srs'          'EPSG:900913 EPSG:4326'
    'wms_extent'       '-124.449431 32.496501 -114.113529 42.073017'
  END
END

LAYER NAME "02_name" TYPE raster STATUS ON OPACITY 30 DATA "02.png" METADATA 'wms_title' '02_name' 'wms_srs' 'EPSG:900913 EPSG:4326' 'wms_extent' '-124.449431 32.496501 -114.113529 42.073017' END END

...

You get the picture. You also need to add metadata entry for the entire MAP like:

MAP
  ... #all your other map stuff
  WEB
# Set IMAGEPATH to the path where MapServer should
# write its output.
IMAGEPATH '/mnt/singledsk/tmp'

# Set IMAGEURL to the url that points to IMAGEPATH
# as defined in your web server configuration
IMAGEURL '/mnt/singledsk/tmp'

# WMS server settings
METADATA
 'ows_enable_request'  '*'
 'ows_title'           'amigo_imagery'
 'ows_onlineresource'  'http://myserver.net/cgibin/mapservmap=/srv/mapserver/amigo_imagery.map'
 'ows_srs'             'EPSG:4326'
END

END END

Then, assuming you are using OpenLayers, create individual layers for every layer you have specified in your WMS

var wms_layer1 = new OpenLayers.Layer.WMS( "NASA Global Mosaic",
              "http://myserver.net/cgibin/mapservmap=/srv/mapserver/amigo_imagery.map", 
              {layers: "01_name"});

var wms_layer2 = new OpenLayers.Layer.WMS( "NASA Global Mosaic", "http://myserver.net/cgibin/mapservmap=/srv/mapserver/amigo_imagery.map", {layers: "02_name"});

and add them to the map. You will then be able to use openlayers to turn on or off as you see fit.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Ragi Yaser Burhum
  • 15,339
  • 2
  • 59
  • 76