Commit 503e5ace066afbcd8e5dc688fd1b8ea143037896

Authored by Edmar Moretti
1 parent 94cbb65a

--no commit message

Showing 1 changed file with 55 additions and 5 deletions   Show diff stats
ogc.php
... ... @@ -182,7 +182,14 @@ if(!isset($tema)){
182 182 $tipo = "intervalo";
183 183 }
184 184 //nome do mapfile que ficara em cache
185   -$agora = intval(time() / 1000);
  185 +$agora = intval(time() / 1000);
  186 +//acrescenta ao nome a indicacao do tipo de TMS
  187 +if(isset($_GET["tms"])){
  188 + $agora .= "tms";
  189 +}
  190 +if(isset($_GET["Z"]) && isset($_GET["X"])){
  191 + $agora .= "google";
  192 +}
186 193 $nomeMapfileTmp = $dir_tmp."/ogc_".md5($tema)."_".$agora.".map";
187 194 $nomeMapfileTmp = str_replace(",","",$nomeMapfileTmp);
188 195 $nomeMapfileTmp = str_replace(" ","",$nomeMapfileTmp);
... ... @@ -481,7 +488,7 @@ else{
481 488 }
482 489 }
483 490 //
484   -//verifica se a requisicao e do tipo TMS. Se for, tenta gerar ou usar o cache
  491 +//verifica se a requisicao e do tipo TMS.
485 492 //
486 493 //
487 494 //calcula a extensao geografica com base no x,y,z em requisições TMS
... ... @@ -512,7 +519,10 @@ if(isset($_GET["tms"])){
512 519 if($img->imagepath == ""){
513 520 exit;
514 521 }
515   - salvaCacheImagem($cachedir,$nomeMapfileTmp,$_GET["tms"]);
  522 + if($cache == true){
  523 + salvaCacheImagem($cachedir,$nomeMapfileTmp,$_GET["tms"]);
  524 + }
  525 + renderNocacheTms();
516 526 }
517 527 //
518 528 //verifica se a chamada do servico e do tipo TILE no padrao do Google
... ... @@ -552,8 +562,12 @@ if(isset($_GET["Z"]) && isset($_GET["X"])){
552 562 $img = $oMap->draw();
553 563 if($img->imagepath == ""){
554 564 exit;
555   - }
556   - salvaCacheImagem($cachedir,$nomeMapfileTmp,$_GET["tms"]);
  565 + }
  566 + /**
  567 + * @TODO ativar cache
  568 + */
  569 + //salvaCacheImagem($cachedir,$nomeMapfileTmp,$_GET["tms"]);
  570 + renderNocacheTms();
557 571 }
558 572 if(strtolower($req->getValueByName("REQUEST")) == "getlegendgraphic"){
559 573 $l = $oMap->getlayer(0);
... ... @@ -736,4 +750,40 @@ function texto2iso($texto){
736 750 }
737 751 return $texto;
738 752 }
  753 +function nomeRand($n=10)
  754 +{
  755 + $nomes = "";
  756 + $a = 'azertyuiopqsdfghjklmwxcvbnABCDEFGHIJKLMNOPQRSTUVWXYZ';
  757 + $max = 51;
  758 + for($i=0; $i < $n; ++$i)
  759 + {$nomes .= $a{mt_rand(0, $max)};}
  760 + return $nomes;
  761 +}
  762 +function renderNocacheTms(){
  763 + global $img,$i3georendermode,$dir_tmp;
  764 + if($i3georendermode == 0 || !isset($i3georendermode)){
  765 + $nomer = $dir_tmp."/temp".nomeRand().".png";
  766 + $img->saveImage($nomer);
  767 + header('Content-Length: '.filesize($nomer));
  768 + header('Content-Type: image/png');
  769 + header('Cache-Control: max-age=3600, must-revalidate');
  770 + header('Expires: ' . gmdate('D, d M Y H:i:s', time()+24*60*60) . ' GMT');
  771 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($nomer)).' GMT', true, 200);
  772 + fpassthru(fopen($nomer, 'rb'));
  773 + }
  774 + if($i3georendermode == 1){
  775 + ob_clean();
  776 + header('Content-Type: image/png');
  777 + $img->saveImage();
  778 + }
  779 + if($i3georendermode == 2){
  780 + $nomer = $dir_tmp."/temp".nomeRand().".png";
  781 + $img->saveImage($nomer);
  782 + ob_clean();
  783 + header('Cache-Control: public, max-age=22222222');
  784 + header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT');
  785 + header("X-Sendfile: $nomer");
  786 + header("Content-type: image/png");
  787 + }
  788 +}
739 789 ?>
... ...