Commit 93d35ac00ebf47b961ec585806fc5b5e19321e9b

Authored by Edmar Moretti
1 parent 3c735003

Otimização da leitura de imagens em cahce

classesphp/mapa_googlemaps.php
... ... @@ -329,7 +329,29 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){
329 329 if($cachedir == "")
330 330 {$nome = dirname(dirname($map))."/cache/googlemaps/".$layer."/".$nome;}
331 331 else
332   - {$nome = $cachedir."/googlemaps/".$layer."/".$nome;}
  332 + {$nome = $cachedir."/googlemaps/".$layer."/".$nome;}
  333 + if(file_exists($nome))
  334 + {
  335 + ob_start();
  336 + // assuming you have image data in $imagedata
  337 + $img = file_get_contents($nome);
  338 + $length = strlen($img);
  339 + $ft = filemtime($nome);
  340 + if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && (strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $ft)) {
  341 + // Client's cache IS current, so we just respond '304 Not Modified'.
  342 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ft).' GMT', true, 304);
  343 + } else {
  344 + // Image not cached or cache outdated, we respond '200 OK' and output the image.
  345 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ft).' GMT', true, 200);
  346 + }
  347 + header('Accept-Ranges: bytes');
  348 + header('Content-Length: '.$length);
  349 + header('Content-Type: image/png');
  350 + print($img);
  351 + ob_end_flush();
  352 + exit;
  353 + }
  354 + /*
333 355 if(file_exists($nome))
334 356 {
335 357 if (!function_exists('imagepng'))
... ... @@ -342,14 +364,12 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){
342 364 @$img = imagecreatefrompng($nome);
343 365 if(!$img)
344 366 {
345   - /* Create a blank image */
346 367 $img = imagecreatetruecolor($w, $h);
347 368 imagealphablending($img, false);
348 369 imagesavealpha($img, true);
349 370 $bgc = imagecolorallocatealpha($img, 255, 255, 255,127);
350 371 $tc = imagecolorallocate($img, 255, 0, 0);
351 372 imagefilledrectangle($img, 0, 0, $w, $h, $bgc);
352   - /* Output an error message */
353 373 imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc);
354 374 }
355 375 else
... ... @@ -364,6 +384,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){
364 384 imagedestroy($img);
365 385 exit;
366 386 }
  387 + */
367 388 }
368 389 function nomeRand($n=10)
369 390 {
... ...
classesphp/mapa_openlayers.php
1 1 <?php
2   -
3 2 /*
4 3 Title: mapa_openlayers.php
5 4  
... ... @@ -60,33 +59,7 @@ i3geo/classesphp/mapa_openlayers.php
60 59  
61 60 */
62 61 error_reporting(0);
63   -clearstatcache();
64   -$_COOKIE = array();
65   -if (!function_exists('ms_GetVersion'))
66   -{
67   - $s = PHP_SHLIB_SUFFIX;
68   - @dl( 'php_mapscript.'.$s );
69   - $ler_extensoes[] = 'php_mapscript';
70   -}
71   -//verificação de segurança
72   -$_SESSION = array();
73   -session_name("i3GeoPHP");
74   -if(@$_GET["g_sid"])
75   -{session_id($_GET["g_sid"]);}
76   -else
77   -{ilegal();}
78   -session_start();
79   -//var_dump($_SESSION);exit;
80   -if(@$_SESSION["fingerprint"])
81   -{
82   - $f = explode(",",$_SESSION["fingerprint"]);
83   - if (md5('I3GEOSEC' . $_SERVER['HTTP_USER_AGENT'] . session_id()) != $f[0] && !in_array($_GET["telaR"],$f) )
84   - {ilegal();}
85   -}
86   -else
87   -{exit;}
88   -if(!isset($_SESSION["map_file"]))
89   -{exit;}
  62 +inicializa();
90 63 //
91 64 //map_fileX é necessário caso register_globals = On no PHP.INI
92 65 $map_fileX = $_SESSION["map_file"];
... ... @@ -94,8 +67,7 @@ $postgis_mapa = $_SESSION[&quot;postgis_mapa&quot;];
94 67 $cachedir = $_SESSION["cachedir"];
95 68 if(isset($_GET["tipolayer"]) && $_GET["tipolayer"] == "fundo")
96 69 {$map_fileX = str_replace(".map","fundo.map",$map_fileX);}
97   -if(isset($_GET["BBOX"]))
98   -{
  70 +if(isset($_GET["BBOX"])){
99 71 $_GET["mapext"] = str_replace(","," ",$_GET["BBOX"]);
100 72 $_GET["map_size"] = $_GET["WIDTH"]." ".$_GET["HEIGHT"];
101 73 }
... ... @@ -335,7 +307,27 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){
335 307 {$nome = $cachedir."/".$layer."/".$nome;}
336 308 if(file_exists($nome))
337 309 {
338   - if (!function_exists('imagepng'))
  310 + ob_start();
  311 + // assuming you have image data in $imagedata
  312 + $img = file_get_contents($nome);
  313 + $length = strlen($img);
  314 + $ft = filemtime($nome);
  315 + if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && (strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $ft)) {
  316 + // Client's cache IS current, so we just respond '304 Not Modified'.
  317 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ft).' GMT', true, 304);
  318 + } else {
  319 + // Image not cached or cache outdated, we respond '200 OK' and output the image.
  320 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ft).' GMT', true, 200);
  321 + }
  322 + header('Accept-Ranges: bytes');
  323 + header('Content-Length: '.$length);
  324 + header('Content-Type: image/png');
  325 + print($img);
  326 + ob_end_flush();
  327 + exit;
  328 + }
  329 + /*
  330 + if (!function_exists('imagepng'))
339 331 {
340 332 $s = PHP_SHLIB_SUFFIX;
341 333 @dl( 'php_gd2.'.$s );
... ... @@ -345,7 +337,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){
345 337 @$img = imagecreatefrompng($nome);
346 338 if(!$img)
347 339 {
348   - /* Create a blank image */
  340 + // Create a blank image
349 341 $img = imagecreatetruecolor($w, $h);
350 342 imagealphablending($img, false);
351 343 imagesavealpha($img, true);
... ... @@ -354,7 +346,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){
354 346 $tc = imagecolorallocate($img, 255, 0, 0);
355 347  
356 348 imagefilledrectangle($img, 0, 0, $w, $h, $bgc);
357   - /* Output an error message */
  349 + // Output an error message
358 350 imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc);
359 351 }
360 352 else
... ... @@ -369,6 +361,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){
369 361 imagedestroy($img);
370 362 exit;
371 363 }
  364 + */
372 365 }
373 366 function nomeRand($n=10)
374 367 {
... ... @@ -406,6 +399,34 @@ function filtraImg($nomer,$tipoimagem){
406 399 {imagepng($m->pixelate(),str_replace("\\","/",$nomer));}
407 400 }
408 401 }
  402 +function inicializa(){
  403 + clearstatcache();
  404 + $_COOKIE = array();
  405 + if (!function_exists('ms_GetVersion')){
  406 + $s = PHP_SHLIB_SUFFIX;
  407 + @dl( 'php_mapscript.'.$s );
  408 + $ler_extensoes[] = 'php_mapscript';
  409 + }
  410 + //verificação de segurança
  411 + $_SESSION = array();
  412 + session_name("i3GeoPHP");
  413 + if(@$_GET["g_sid"])
  414 + {session_id($_GET["g_sid"]);}
  415 + else
  416 + {ilegal();}
  417 + session_start();
  418 + //var_dump($_SESSION);exit;
  419 + if(@$_SESSION["fingerprint"])
  420 + {
  421 + $f = explode(",",$_SESSION["fingerprint"]);
  422 + if (md5('I3GEOSEC' . $_SERVER['HTTP_USER_AGENT'] . session_id()) != $f[0] && !in_array($_GET["telaR"],$f) )
  423 + {ilegal();}
  424 + }
  425 + else
  426 + {exit;}
  427 + if(!isset($_SESSION["map_file"]))
  428 + {exit;}
  429 +}
409 430 function ilegal(){
410 431 $img = imagecreatefrompng("../imagens/ilegal.png");
411 432 imagealphablending($img, false);
... ...
index.html
... ... @@ -6,16 +6,9 @@
6 6 <meta name="keywords" content="geoprocessing, GIS, maps, mapserver, dados geograficos, mapa interativo, i3geo, geoprocessamento, mapa, gis, sig, geografia, cartografia, meio ambiente">
7 7 <head>
8 8 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
9   -
10 9 </head>
11 10 <body>
12   -<center>
13   -<br><br>
14   -<table>
15   -<tr>
16   - <td style="padding:10px;"><center><img alt="i3Geo" src='imagens/logo_inicio.png'></td>
17   -</tr>
18   -</table>
  11 +
19 12 </body>
20 13 <script>
21 14 /*
... ...
interface/openlayers.htm
... ... @@ -65,7 +65,7 @@
65 65 <center>
66 66 <table id="i3GEOlogoMarca" style='box-shadow:0 1px 13px gray;border-radius:5px;'>
67 67 <tr>
68   - <td><center><h1 style="font-size:10px;font-family: Verdana, Arial, Helvetica, sans-serif;"><div id=versaoi3geo ></div><h2 style="font-size:10px;font-family: Verdana, Arial, Helvetica, sans-serif;">i3Geo - Software livre para criação de mapas interativos e geoprocessamento<h3 style="font-size:10px;font-family: Verdana, Arial, Helvetica, sans-serif;">Baseado no Mapserver, é licenciado sob GPL e integra o Portal do Software Público Brasileiro</h3></h2></h1></td>
  68 + <td><center><h1 style="font-weight:normal;font-size:10px;font-family: Verdana, Arial, Helvetica, sans-serif;"><div id=versaoi3geo ></div><h2 style="font-weight:normal;font-size:10px;font-family: Verdana, Arial, Helvetica, sans-serif;">i3Geo - Software livre para criação de mapas interativos e geoprocessamento<h3 style="font-weight:normal;font-size:10px;font-family: Verdana, Arial, Helvetica, sans-serif;">Baseado no Mapserver, é licenciado sob GPL e integra o Portal do Software Público Brasileiro</h3></h2></h1></td>
69 69 </tr>
70 70 <tr>
71 71 <td style="padding:10px;"><center><img alt="" src='../imagens/logo_inicio.png' ></td>
... ... @@ -100,6 +100,7 @@
100 100 </div>
101 101 </div>
102 102 </div>
  103 +
103 104 <script src="../classesjs/i3geo.js"></script>
104 105 <script src="../pacotes/openlayers/OpenLayers211.js.php"></script>
105 106 <!-- estilo necessário para a ferramenta de edição -->
... ...
ogc.php
... ... @@ -464,6 +464,28 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=&quot;&quot;){
464 464 {$nome = $cachedir."/".$layer."/".$nome;}
465 465 if(file_exists($nome))
466 466 {
  467 + ob_start();
  468 + // assuming you have image data in $imagedata
  469 + $img = file_get_contents($nome);
  470 + $length = strlen($img);
  471 + $ft = filemtime($nome);
  472 + if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && (strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $ft)) {
  473 + // Client's cache IS current, so we just respond '304 Not Modified'.
  474 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ft).' GMT', true, 304);
  475 + } else {
  476 + // Image not cached or cache outdated, we respond '200 OK' and output the image.
  477 + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ft).' GMT', true, 200);
  478 + }
  479 + header('Accept-Ranges: bytes');
  480 + header('Content-Length: '.$length);
  481 + header('Content-Type: image/png');
  482 + print($img);
  483 + ob_end_flush();
  484 + exit;
  485 + }
  486 + /*
  487 + if(file_exists($nome))
  488 + {
467 489 if (!function_exists('imagepng'))
468 490 {
469 491 $s = PHP_SHLIB_SUFFIX;
... ... @@ -474,7 +496,6 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=&quot;&quot;){
474 496 @$img = imagecreatefrompng($nome);
475 497 if(!$img)
476 498 {
477   - /* Create a blank image */
478 499 $img = imagecreatetruecolor($w, $h);
479 500 imagealphablending($img, false);
480 501 imagesavealpha($img, true);
... ... @@ -483,7 +504,6 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=&quot;&quot;){
483 504 $tc = imagecolorallocate($img, 255, 0, 0);
484 505  
485 506 imagefilledrectangle($img, 0, 0, $w, $h, $bgc);
486   - /* Output an error message */
487 507 imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc);
488 508 }
489 509 else
... ... @@ -498,6 +518,7 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=&quot;&quot;){
498 518 imagedestroy($img);
499 519 exit;
500 520 }
  521 + */
501 522 }
502 523  
503 524 ?>
... ...
pacotes/kmlmapserver/classes/layerserver.class.php
... ... @@ -758,9 +758,11 @@ class LayerServer {
758 758 function add_style_point(&$new_style, &$style_data){
759 759 if($style_data['icon']){
760 760 $st =& $new_style->addChild('IconStyle');
761   - if($style_data['width'] && $style_data['icon_width'] != 32){
  761 + if($style_data['width'] && $style_data['icon_width'] != 32){
762 762 $st->addChild('scale', $style_data['icon_width'] / 32);
763 763 }
  764 + else
  765 + {$st->addChild('scale', 1);}
764 766 $icon =& $st->addChild('Icon');
765 767 $icon->addChild('href', htmlentities($style_data['icon']));
766 768 }
... ...