| 1 | = Using setOpacity() method for SWIG !MapScript = |
| 2 | |
| 3 | {{{ |
| 4 | #!php |
| 5 | <?php |
| 6 | |
| 7 | // define variables |
| 8 | define( "MAPFILE", "C:/ms4w/apps/phpmapscriptng-swig/output.map" ); |
| 9 | |
| 10 | // required SWIG include (contains constants for PHP7) |
| 11 | include("C:/ms4w/apps/phpmapscriptng-swig/include/mapscript.php"); |
| 12 | |
| 13 | // open map |
| 14 | $oMap = new mapObj(MAPFILE); |
| 15 | |
| 16 | //force all errors to display |
| 17 | // comment out the next 2 lines, useful on servers not displaying errors |
| 18 | ini_set('display_errors','On'); |
| 19 | error_reporting(E_ALL); |
| 20 | |
| 21 | // set image size |
| 22 | $oMap->setsize(400, 300); |
| 23 | |
| 24 | // set image format |
| 25 | $oMap->selectoutputformat("png"); |
| 26 | |
| 27 | |
| 28 | // get layer |
| 29 | $oPolyLayer = $oMap->getLayerByName('prov_bound'); |
| 30 | |
| 31 | //*********************************************************************************************** |
| 32 | // set opacity on the layer |
| 33 | //*********************************************************************************************** |
| 34 | // call setOpacity() (which actually creates a new COMPOSITE object) |
| 35 | $oPolyLayer->setOpacity(40); |
| 36 | |
| 37 | // draw map |
| 38 | $oImage = $oMap->draw(); |
| 39 | |
| 40 | // save image file |
| 41 | $file = $oImage->save("C:/ms4w/apps/phpmapscriptng-swig/ttt.png",$oMap); |
| 42 | |
| 43 | //*********************************************************************************************** |
| 44 | // save mapfile to new file, to see your new COMPOSITE object inside the layer |
| 45 | //*********************************************************************************************** |
| 46 | $oMap->save("C:/ms4w/apps/phpmapscriptng-swig/output2.map"); |
| 47 | |
| 48 | // set header |
| 49 | header("Content-type: image/gif"); |
| 50 | |
| 51 | // read image to output buffer |
| 52 | readfile("C:/ms4w/apps/phpmapscriptng-swig/ttt.png"); |
| 53 | |
| 54 | ?> |
| 55 | }}} |