public function __construct() { $err = 0; $errMsg = ""; $wmsurl = $_REQUEST['wmsurl']; $wms = new WMSClient($wmsurl); if ($wms->checkError()) { $err = 1; $errMsg = $wms->returnErrorMsg(); } $layers = json_encode($wms->getLayerList()); $imgFormats = json_encode($wms->getImgFormats()); $srsList = json_encode($wms->getSrsList()); // return JS object literals "{}" for XMLHTTP request header("Content-Type: text/plain; charset={$defCharset}"); echo "{\"err\":{$err}, \"errMsg\":\"{$errMsg}\", \"layers\":{$layers}, \"imgFormats\":{$imgFormats}, \"srsList\":{$srsList}}"; }
<?php require_once "wmsclient.php"; $wmsurl = "http://labs.metacarta.com/wms/vmap0?"; $wmsurl = "http://wms.jpl.nasa.gov/wms.cgi?"; $wms = new WMSClient($wmsurl); //print_r($wms->returnCapabilities()->asXML()); $layers = $wms->getLayerList(); print_r(json_encode($layers)); echo "\n"; $imgFormats = $wms->getImgFormats(); print_r(json_encode($imgFormats)); echo "\n"; $srsList = $wms->getSrsList(); print_r(json_encode($srsList));
protected function getWmsLegend($qLayer, $layName, $legPath) { require_once PM_INCPHP . "/map/wmsclient.php"; $getWmsLegend = (bool) $qLayer->getMetaData("wms_show_legend"); //error_log("getWmsLegend: $getWmsLegend"); if ($getWmsLegend) { $onlineResource = $qLayer->connection; error_log($onlineResource); $wmsLayerName = $qLayer->getMetaData("wms_name"); $wmsLayerList = explode(",", $wmsLayerName); // get URL for legend image $wmsClient = new WMSClient($onlineResource); $legendUrlList = $wmsClient->getLayerLegendParams($wmsLayerList[0]); if ($legendUrlList) { $formatList = explode("/", $legendUrlList['format']); $imgFile = $legPath . $layName . '_i.' . $formatList[1]; // download image via URL $legendImgUrl = $legendUrlList['legendImgUrl']; if (strlen($legendImgUrl) > 0) { $ch = curl_init($legendImgUrl); //error_log("imgUrl: " . $legendUrlList['legendImgUrl']); $fp = fopen($imgFile, "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_BINARYTRANSFER, True); curl_exec($ch); curl_close($ch); fclose($fp); } } } }