Version 3 (modified by Jeff McKenna, 3 weeks ago) (diff)

add point example

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 polygon layerObj
$oPolyLayer = new layerObj($oMap);
$oPolyLayer->__set("name", "prov_bound");
$oPolyLayer->__set("type", MS_LAYER_POLYGON);
$oPolyLayer->__set("status", MS_ON);
$oPolyLayer->__set("data", "province.shp");
// create new class for poly layer
$oClass = new classObj($oPolyLayer); 
$oClass->__set("name", "Province");
// create new style
$oStyle = new styleObj(); 
// create new colors
$oColor = new colorObj(120,120,120); 
$oOutlineColor = new colorObj(0,0,0); 
$oStyle->__set("color", $oColor);
$oStyle->__set("outlinecolor", $oOutlineColor);
// set opacity (actually creates a new COMPOSITE object)

// 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 point layerObj
$oPointLayer = new layerObj($oMap);
$oPointLayer->__set("name", "gg-location");
$oPointLayer->__set("type", MS_LAYER_POINT);
$oPointLayer->__set("status", MS_ON);
$oPointLayer->__set("units", "DD");
$oPoint = new pointObj(-64.2576966,44.3596731);
// create new lineObj (lineObj is composed of one or more pointObj instances)
$oline = new lineObj();
// create shapeObj for point
$oShape = new shapeObj();
// create new class for poly layer
$oClass = new classObj($oPointLayer); 
$oClass->__set("name", "GatewayGeo");
// create new style
$oStyle = new styleObj();
// set symbol
$oStyle->setSymbolByName($oMap, "star");
$oStyle->__set("size", 10);
// create new colors
$oColor = new colorObj(255,255,0); 
$oStyle->__set("color", $oColor);

// 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/png");

//send image to stdout, without saving file locally
echo $oImage ->getBytes();