Пример #1
0
 public function setSldFolderUrl($folder)
 {
     if (!empty($folder)) {
         $this->sldFolderUrl = R3OgcMapUtils::addPrefixToRelativeUrl($folder);
     }
 }
Пример #2
0
 protected function downloadImages()
 {
     if (empty($this->wms)) {
         throw new Exception('No WMS to query');
     }
     $n = 0;
     foreach ($this->wms as $wmsKey => $wmsData) {
         $n++;
         $separator = '';
         if (!strpos($wmsData['url'], '?')) {
             $separator = '?';
         } else {
             $lastChar = substr($wmsData['url'], 0, -1);
             if ($lastChar != '?') {
                 if ($lastChar != '&' && substr($wmsData['url'], 0, -4) != '&') {
                     $separator = '&';
                 }
             }
         }
         $parameters = array();
         foreach ($wmsData['parameters'] as $parameterKey => $parameterValue) {
             $parameters[strtoupper($parameterKey)] = $parameterValue;
         }
         $wmsData['parameters'] = $parameters;
         $wmsData['parameters']['BBOX'] = implode(',', $this->extent);
         $wmsData['parameters']['SERVICE'] = 'WMS';
         $wmsData['parameters']['REQUEST'] = 'GetMap';
         $wmsData['parameters']['VERSION'] = '1.1.1';
         $wmsData['parameters']['WIDTH'] = $this->size[0];
         $wmsData['parameters']['HEIGHT'] = $this->size[1];
         #$wmsData['parameters']['FORMAT'] = 'image/png';
         // Da precedenza ai parametri nell'url del WMS piuttosto che a quelli in $wmsData['parameters']
         $urlParts = parse_url($wmsData['url']);
         if (isset($urlParts['query'])) {
             parse_str($urlParts['query'], $queryParams);
             foreach ($queryParams as $key => $val) {
                 $key = strtoupper($key);
                 if (isset($wmsData['parameters'][$key])) {
                     unset($wmsData['parameters'][$key]);
                 }
             }
         }
         $url = $wmsData['url'] . $separator . http_build_query($wmsData['parameters']);
         //HACK: http_build_query trasforma da true a 1 e MS6 vuole true e non 1
         $url = str_replace("TRANSPARENT=1", "TRANSPARENT=true", $url);
         $this->wms[$wmsKey]['requesturl'] = $url;
         //SG: PHP BUG #52339 https://bugs.php.net/bug.php?id=52339&edit=1
         /*if (class_exists('R3AppInit')) {
               $elapsedTime = sprintf("elapsed time: %.3f s", microtime(true) - R3AppInit::$startTime);
               ezcLog::getInstance()->log(__METHOD__.", $elapsedTime, fetching $url", ezcLog::DEBUG);
           }*/
         $url = R3OgcMapUtils::addPrefixToRelativeUrl($url);
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
         $image = curl_exec($ch);
         if (!$image) {
             ezcLog::getInstance()->log("Error downloading image from [{$url}], curl error: [" . curl_error($ch) . "]", ezcLog::ERROR);
             throw new Exception("Error downloading image");
         }
         curl_close($ch);
         array_push($this->images, $image);
     }
 }
Пример #3
0
 protected function getLegendImage($url, $tmpFileId)
 {
     $dest = $this->options['TMP_PATH'] . $tmpFileId . '.png';
     $url = R3OgcMapUtils::addPrefixToRelativeUrl($url);
     $ch = curl_init($url);
     if (($fp = fopen($dest, "wb")) === FALSE) {
         throw new Exception("Could not open {$dest}");
     }
     $options = array(CURLOPT_FILE => $fp, CURLOPT_HEADER => 0, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_TIMEOUT => 60);
     curl_setopt_array($ch, $options);
     if (($rv = curl_exec($ch)) === FALSE) {
         throw new Exception("Could not get data from {$url}");
     }
     curl_close($ch);
     fclose($fp);
     return $dest;
 }