wiki:SWIGMapScriptNewLayer

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

<?php

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

// required SWIG include (contains constants for PHP7)
include("C:/ms4w/apps/phpmapscriptng-swig/include/mapscript.php");

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

//force all errors to display
//  comment out the next 2 lines, useful on servers not displaying errors
ini_set('display_errors','On');
error_reporting(E_ALL);

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

// set image format
$oMap->selectoutputformat("png");

// 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", "https://demo.gatewaygeomatics.com/cgi-bin/wms_gateway?");
$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");
$oWMSLayer->SetProjection("init=EPSG:3978");

// 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);
$oClass->insertStyle($oStyle);
$oPolyLayer->SetProjection("init=EPSG:3978");
// set opacity (actually creates a new COMPOSITE object)
$oPolyLayer->setOpacity(40);

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

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

// save mapfile to new file
$oMap->save("C:/ms4w/apps/phpmapscriptng-swig/output.map");

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

// read image to output buffer
readfile("C:/ms4w/apps/phpmapscriptng-swig/ttt.png");

?>
Last modified 3 months ago Last modified on May 16, 2019, 8:32:03 AM