Creating a WMS layer, a Polygon layer with Opacity, using SWIG MapScript


// define variables
define( "MAPFILE", "C:/ms4w/apps/phpmapscriptng-swig/" );

// required SWIG include (contains constants for PHP7)

// open map
$oMap = new mapObj(MAPFILE);

//force all errors to display
//  comment out the next 2 lines, useful on servers not displaying errors

// set image size
$oMap->setsize(400, 300);

// set image format

// create new WMS layer
$oWMSLayer = new layerObj($oMap);
$oWMSLayer->__set("name", "cities");
$oWMSLayer->__set("type", MS_LAYER_RASTER);
$oWMSLayer->__set("status", MS_ON);
$oWMSLayer->setConnectionType(MS_WMS, NULL);
$oWMSLayer->__set("connection", "");
$oWMSLayer->setMetaData("wms_name", "popplace");
$oWMSLayer->setMetaData("wms_srs", "EPSG:3978");
$oWMSLayer->setMetaData("wms_server_version", "1.1.1");
$oWMSLayer->setMetaData("wms_format", "image/png");

// create new polygon layer
$oPolyLayer = new layerObj($oMap);
$oPolyLayer->__set("name", "prov_bound");
$oPolyLayer->__set("type", MS_LAYER_POLYGON);
$oPolyLayer->__set("status", MS_ON);
$oPolyLayer->__set("data", "province");
// create new class for poly layer
$oClass = new classObj($oPolyLayer); 
$oClass->__set("name", "Province");
// create new style
$oStyle = new styleObj(); 
// create new color
$oColor = new colorObj(120,120,120); 
$oStyle->__set("color", $oColor);
// set opacity (actually creates a new COMPOSITE object)

// draw map
$oImage = $oMap->draw();

// save image file
$file = $oImage->save("C:/ms4w/apps/phpmapscriptng-swig/ttt.png",$oMap);

// save mapfile to new file

// set header
header("Content-type: image/gif");

// read image to output buffer

Last modified 6 weeks ago Last modified on May 16, 2019, 8:32:03 AM