| 1 | = WMS Wrapper example = |
| 2 | |
| 3 | - source: https://lists.ms4w.com/pipermail/ms4w-users/2019-May/000343.html |
| 4 | - note: likely solution is included in next !MapServer release ([[https://github.com/mapserver/mapserver/pull/5778/files#diff-127c91f36292dd4e75e861fb07c29f1f|diff]]) |
| 5 | |
| 6 | == SWIG !MapScript [ This is now working and is resolved :) ] == |
| 7 | {{{ |
| 8 | #!php |
| 9 | <?php |
| 10 | |
| 11 | include("../includes/phpmapscriptng-swig/mapscript.php"); |
| 12 | $oMap= new mapObj($mymapfile); |
| 13 | |
| 14 | ## Ready stdout for data capture |
| 15 | msIO_installStdoutToBuffer(); |
| 16 | |
| 17 | ## Create OWS Request object |
| 18 | $request = new OWSRequest(); |
| 19 | |
| 20 | ## Get Request |
| 21 | foreach ($_GET as $k=>$v) { |
| 22 | $request->setParameter($k, $v); |
| 23 | } |
| 24 | |
| 25 | ## Dispatch request |
| 26 | $oMap->OWSDispatch($request); |
| 27 | |
| 28 | unset($oMap); |
| 29 | |
| 30 | $contenttype = strtolower(msIO_stripStdoutBufferContentType()); |
| 31 | |
| 32 | ## Capabilities Request |
| 33 | if ($contenttype == "application/vnd.ogc.wms_xml; charset=utf-8"){ |
| 34 | header('Content-type: application/xml; charset=utf-8'); |
| 35 | echo msIO_getStdoutBufferString(); |
| 36 | } |
| 37 | |
| 38 | ## GetMap jpeg |
| 39 | else if ($contenttype == 'image/jpeg'){ |
| 40 | header('Content-type: image/jpeg'); |
| 41 | echo msIO_getStdoutBufferBytes(); |
| 42 | } |
| 43 | |
| 44 | |
| 45 | ## Reset handler and cleaup added |
| 46 | msIO_resetHandlers(); |
| 47 | msCleanup(); |
| 48 | |
| 49 | ?> |
| 50 | }}} |
| 51 | |
| 52 | == Old !MapScript == |
| 53 | |
| 54 | {{{ |
| 55 | #!php |
| 56 | <?php |
| 57 | |
| 58 | $oMap= ms_newMapObj($mymapfile); |
| 59 | |
| 60 | ms_ioinstallstdouttobuffer(); |
| 61 | |
| 62 | $request = ms_newowsrequestobj(); |
| 63 | |
| 64 | //Get Request |
| 65 | foreach ($_GET as $k=>$v) { |
| 66 | $request->setParameter($k, $v); |
| 67 | } |
| 68 | |
| 69 | $oMap->owsdispatch($request); |
| 70 | $oMap->free(); |
| 71 | unset($oMap); |
| 72 | |
| 73 | $contenttype = strtolower(ms_iostripstdoutbuffercontenttype()); |
| 74 | |
| 75 | //Capabilities Request |
| 76 | if ($contenttype == "application/vnd.ogc.wms_xml; charset=utf-8"){ |
| 77 | header('Content-type: application/xml; charset=utf-8'); |
| 78 | echo ms_iogetstdoutbufferstring(); |
| 79 | } |
| 80 | |
| 81 | //getMap jpeg |
| 82 | else if ($contenttype == 'image/jpeg'){ |
| 83 | header('Content-type: image/jpeg'); |
| 84 | echo ms_iogetStdoutBufferBytes(); |
| 85 | } |
| 86 | |
| 87 | ?> |
| 88 | }}} |