Commit 93d35ac00ebf47b961ec585806fc5b5e19321e9b
1 parent
3c735003
Exists in
master
and in
7 other branches
Otimização da leitura de imagens em cahce
Showing
6 changed files
with
107 additions
and
48 deletions
Show diff stats
classesphp/mapa_googlemaps.php
@@ -329,7 +329,29 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | @@ -329,7 +329,29 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | ||
329 | if($cachedir == "") | 329 | if($cachedir == "") |
330 | {$nome = dirname(dirname($map))."/cache/googlemaps/".$layer."/".$nome;} | 330 | {$nome = dirname(dirname($map))."/cache/googlemaps/".$layer."/".$nome;} |
331 | else | 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 | if(file_exists($nome)) | 355 | if(file_exists($nome)) |
334 | { | 356 | { |
335 | if (!function_exists('imagepng')) | 357 | if (!function_exists('imagepng')) |
@@ -342,14 +364,12 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | @@ -342,14 +364,12 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | ||
342 | @$img = imagecreatefrompng($nome); | 364 | @$img = imagecreatefrompng($nome); |
343 | if(!$img) | 365 | if(!$img) |
344 | { | 366 | { |
345 | - /* Create a blank image */ | ||
346 | $img = imagecreatetruecolor($w, $h); | 367 | $img = imagecreatetruecolor($w, $h); |
347 | imagealphablending($img, false); | 368 | imagealphablending($img, false); |
348 | imagesavealpha($img, true); | 369 | imagesavealpha($img, true); |
349 | $bgc = imagecolorallocatealpha($img, 255, 255, 255,127); | 370 | $bgc = imagecolorallocatealpha($img, 255, 255, 255,127); |
350 | $tc = imagecolorallocate($img, 255, 0, 0); | 371 | $tc = imagecolorallocate($img, 255, 0, 0); |
351 | imagefilledrectangle($img, 0, 0, $w, $h, $bgc); | 372 | imagefilledrectangle($img, 0, 0, $w, $h, $bgc); |
352 | - /* Output an error message */ | ||
353 | imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc); | 373 | imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc); |
354 | } | 374 | } |
355 | else | 375 | else |
@@ -364,6 +384,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | @@ -364,6 +384,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | ||
364 | imagedestroy($img); | 384 | imagedestroy($img); |
365 | exit; | 385 | exit; |
366 | } | 386 | } |
387 | + */ | ||
367 | } | 388 | } |
368 | function nomeRand($n=10) | 389 | function nomeRand($n=10) |
369 | { | 390 | { |
classesphp/mapa_openlayers.php
1 | <?php | 1 | <?php |
2 | - | ||
3 | /* | 2 | /* |
4 | Title: mapa_openlayers.php | 3 | Title: mapa_openlayers.php |
5 | 4 | ||
@@ -60,33 +59,7 @@ i3geo/classesphp/mapa_openlayers.php | @@ -60,33 +59,7 @@ i3geo/classesphp/mapa_openlayers.php | ||
60 | 59 | ||
61 | */ | 60 | */ |
62 | error_reporting(0); | 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 | //map_fileX é necessário caso register_globals = On no PHP.INI | 64 | //map_fileX é necessário caso register_globals = On no PHP.INI |
92 | $map_fileX = $_SESSION["map_file"]; | 65 | $map_fileX = $_SESSION["map_file"]; |
@@ -94,8 +67,7 @@ $postgis_mapa = $_SESSION["postgis_mapa"]; | @@ -94,8 +67,7 @@ $postgis_mapa = $_SESSION["postgis_mapa"]; | ||
94 | $cachedir = $_SESSION["cachedir"]; | 67 | $cachedir = $_SESSION["cachedir"]; |
95 | if(isset($_GET["tipolayer"]) && $_GET["tipolayer"] == "fundo") | 68 | if(isset($_GET["tipolayer"]) && $_GET["tipolayer"] == "fundo") |
96 | {$map_fileX = str_replace(".map","fundo.map",$map_fileX);} | 69 | {$map_fileX = str_replace(".map","fundo.map",$map_fileX);} |
97 | -if(isset($_GET["BBOX"])) | ||
98 | -{ | 70 | +if(isset($_GET["BBOX"])){ |
99 | $_GET["mapext"] = str_replace(","," ",$_GET["BBOX"]); | 71 | $_GET["mapext"] = str_replace(","," ",$_GET["BBOX"]); |
100 | $_GET["map_size"] = $_GET["WIDTH"]." ".$_GET["HEIGHT"]; | 72 | $_GET["map_size"] = $_GET["WIDTH"]." ".$_GET["HEIGHT"]; |
101 | } | 73 | } |
@@ -335,7 +307,27 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | @@ -335,7 +307,27 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | ||
335 | {$nome = $cachedir."/".$layer."/".$nome;} | 307 | {$nome = $cachedir."/".$layer."/".$nome;} |
336 | if(file_exists($nome)) | 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 | $s = PHP_SHLIB_SUFFIX; | 332 | $s = PHP_SHLIB_SUFFIX; |
341 | @dl( 'php_gd2.'.$s ); | 333 | @dl( 'php_gd2.'.$s ); |
@@ -345,7 +337,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | @@ -345,7 +337,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | ||
345 | @$img = imagecreatefrompng($nome); | 337 | @$img = imagecreatefrompng($nome); |
346 | if(!$img) | 338 | if(!$img) |
347 | { | 339 | { |
348 | - /* Create a blank image */ | 340 | + // Create a blank image |
349 | $img = imagecreatetruecolor($w, $h); | 341 | $img = imagecreatetruecolor($w, $h); |
350 | imagealphablending($img, false); | 342 | imagealphablending($img, false); |
351 | imagesavealpha($img, true); | 343 | imagesavealpha($img, true); |
@@ -354,7 +346,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | @@ -354,7 +346,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | ||
354 | $tc = imagecolorallocate($img, 255, 0, 0); | 346 | $tc = imagecolorallocate($img, 255, 0, 0); |
355 | 347 | ||
356 | imagefilledrectangle($img, 0, 0, $w, $h, $bgc); | 348 | imagefilledrectangle($img, 0, 0, $w, $h, $bgc); |
357 | - /* Output an error message */ | 349 | + // Output an error message |
358 | imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc); | 350 | imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc); |
359 | } | 351 | } |
360 | else | 352 | else |
@@ -369,6 +361,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | @@ -369,6 +361,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ | ||
369 | imagedestroy($img); | 361 | imagedestroy($img); |
370 | exit; | 362 | exit; |
371 | } | 363 | } |
364 | + */ | ||
372 | } | 365 | } |
373 | function nomeRand($n=10) | 366 | function nomeRand($n=10) |
374 | { | 367 | { |
@@ -406,6 +399,34 @@ function filtraImg($nomer,$tipoimagem){ | @@ -406,6 +399,34 @@ function filtraImg($nomer,$tipoimagem){ | ||
406 | {imagepng($m->pixelate(),str_replace("\\","/",$nomer));} | 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 | function ilegal(){ | 430 | function ilegal(){ |
410 | $img = imagecreatefrompng("../imagens/ilegal.png"); | 431 | $img = imagecreatefrompng("../imagens/ilegal.png"); |
411 | imagealphablending($img, false); | 432 | imagealphablending($img, false); |
index.html
@@ -6,16 +6,9 @@ | @@ -6,16 +6,9 @@ | ||
6 | <meta name="keywords" content="geoprocessing, GIS, maps, mapserver, dados geograficos, mapa interativo, i3geo, geoprocessamento, mapa, gis, sig, geografia, cartografia, meio ambiente"> | 6 | <meta name="keywords" content="geoprocessing, GIS, maps, mapserver, dados geograficos, mapa interativo, i3geo, geoprocessamento, mapa, gis, sig, geografia, cartografia, meio ambiente"> |
7 | <head> | 7 | <head> |
8 | <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> | 8 | <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> |
9 | - | ||
10 | </head> | 9 | </head> |
11 | <body> | 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 | </body> | 12 | </body> |
20 | <script> | 13 | <script> |
21 | /* | 14 | /* |
interface/openlayers.htm
@@ -65,7 +65,7 @@ | @@ -65,7 +65,7 @@ | ||
65 | <center> | 65 | <center> |
66 | <table id="i3GEOlogoMarca" style='box-shadow:0 1px 13px gray;border-radius:5px;'> | 66 | <table id="i3GEOlogoMarca" style='box-shadow:0 1px 13px gray;border-radius:5px;'> |
67 | <tr> | 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 | </tr> | 69 | </tr> |
70 | <tr> | 70 | <tr> |
71 | <td style="padding:10px;"><center><img alt="" src='../imagens/logo_inicio.png' ></td> | 71 | <td style="padding:10px;"><center><img alt="" src='../imagens/logo_inicio.png' ></td> |
@@ -100,6 +100,7 @@ | @@ -100,6 +100,7 @@ | ||
100 | </div> | 100 | </div> |
101 | </div> | 101 | </div> |
102 | </div> | 102 | </div> |
103 | + | ||
103 | <script src="../classesjs/i3geo.js"></script> | 104 | <script src="../classesjs/i3geo.js"></script> |
104 | <script src="../pacotes/openlayers/OpenLayers211.js.php"></script> | 105 | <script src="../pacotes/openlayers/OpenLayers211.js.php"></script> |
105 | <!-- estilo necessário para a ferramenta de edição --> | 106 | <!-- estilo necessário para a ferramenta de edição --> |
ogc.php
@@ -464,6 +464,28 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ | @@ -464,6 +464,28 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ | ||
464 | {$nome = $cachedir."/".$layer."/".$nome;} | 464 | {$nome = $cachedir."/".$layer."/".$nome;} |
465 | if(file_exists($nome)) | 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 | if (!function_exists('imagepng')) | 489 | if (!function_exists('imagepng')) |
468 | { | 490 | { |
469 | $s = PHP_SHLIB_SUFFIX; | 491 | $s = PHP_SHLIB_SUFFIX; |
@@ -474,7 +496,6 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ | @@ -474,7 +496,6 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ | ||
474 | @$img = imagecreatefrompng($nome); | 496 | @$img = imagecreatefrompng($nome); |
475 | if(!$img) | 497 | if(!$img) |
476 | { | 498 | { |
477 | - /* Create a blank image */ | ||
478 | $img = imagecreatetruecolor($w, $h); | 499 | $img = imagecreatetruecolor($w, $h); |
479 | imagealphablending($img, false); | 500 | imagealphablending($img, false); |
480 | imagesavealpha($img, true); | 501 | imagesavealpha($img, true); |
@@ -483,7 +504,6 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ | @@ -483,7 +504,6 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ | ||
483 | $tc = imagecolorallocate($img, 255, 0, 0); | 504 | $tc = imagecolorallocate($img, 255, 0, 0); |
484 | 505 | ||
485 | imagefilledrectangle($img, 0, 0, $w, $h, $bgc); | 506 | imagefilledrectangle($img, 0, 0, $w, $h, $bgc); |
486 | - /* Output an error message */ | ||
487 | imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc); | 507 | imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc); |
488 | } | 508 | } |
489 | else | 509 | else |
@@ -498,6 +518,7 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ | @@ -498,6 +518,7 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ | ||
498 | imagedestroy($img); | 518 | imagedestroy($img); |
499 | exit; | 519 | exit; |
500 | } | 520 | } |
521 | + */ | ||
501 | } | 522 | } |
502 | 523 | ||
503 | ?> | 524 | ?> |
pacotes/kmlmapserver/classes/layerserver.class.php
@@ -758,9 +758,11 @@ class LayerServer { | @@ -758,9 +758,11 @@ class LayerServer { | ||
758 | function add_style_point(&$new_style, &$style_data){ | 758 | function add_style_point(&$new_style, &$style_data){ |
759 | if($style_data['icon']){ | 759 | if($style_data['icon']){ |
760 | $st =& $new_style->addChild('IconStyle'); | 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 | $st->addChild('scale', $style_data['icon_width'] / 32); | 762 | $st->addChild('scale', $style_data['icon_width'] / 32); |
763 | } | 763 | } |
764 | + else | ||
765 | + {$st->addChild('scale', 1);} | ||
764 | $icon =& $st->addChild('Icon'); | 766 | $icon =& $st->addChild('Icon'); |
765 | $icon->addChild('href', htmlentities($style_data['icon'])); | 767 | $icon->addChild('href', htmlentities($style_data['icon'])); |
766 | } | 768 | } |