From 93d35ac00ebf47b961ec585806fc5b5e19321e9b Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Tue, 7 Feb 2012 13:53:09 +0000 Subject: [PATCH] Otimização da leitura de imagens em cahce --- classesphp/mapa_googlemaps.php | 27 ++++++++++++++++++++++++--- classesphp/mapa_openlayers.php | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- index.html | 9 +-------- interface/openlayers.htm | 3 ++- ogc.php | 25 +++++++++++++++++++++++-- pacotes/kmlmapserver/classes/layerserver.class.php | 4 +++- 6 files changed, 107 insertions(+), 48 deletions(-) diff --git a/classesphp/mapa_googlemaps.php b/classesphp/mapa_googlemaps.php index fb371b3..31f07ff 100644 --- a/classesphp/mapa_googlemaps.php +++ b/classesphp/mapa_googlemaps.php @@ -329,7 +329,29 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ if($cachedir == "") {$nome = dirname(dirname($map))."/cache/googlemaps/".$layer."/".$nome;} else - {$nome = $cachedir."/googlemaps/".$layer."/".$nome;} + {$nome = $cachedir."/googlemaps/".$layer."/".$nome;} + if(file_exists($nome)) + { + ob_start(); + // assuming you have image data in $imagedata + $img = file_get_contents($nome); + $length = strlen($img); + $ft = filemtime($nome); + if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && (strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $ft)) { + // Client's cache IS current, so we just respond '304 Not Modified'. + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ft).' GMT', true, 304); + } else { + // Image not cached or cache outdated, we respond '200 OK' and output the image. + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ft).' GMT', true, 200); + } + header('Accept-Ranges: bytes'); + header('Content-Length: '.$length); + header('Content-Type: image/png'); + print($img); + ob_end_flush(); + exit; + } + /* if(file_exists($nome)) { if (!function_exists('imagepng')) @@ -342,14 +364,12 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ @$img = imagecreatefrompng($nome); if(!$img) { - /* Create a blank image */ $img = imagecreatetruecolor($w, $h); imagealphablending($img, false); imagesavealpha($img, true); $bgc = imagecolorallocatealpha($img, 255, 255, 255,127); $tc = imagecolorallocate($img, 255, 0, 0); imagefilledrectangle($img, 0, 0, $w, $h, $bgc); - /* Output an error message */ imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc); } else @@ -364,6 +384,7 @@ function carregaCacheImagem($cachedir,$bbox,$layer,$map,$w,$h){ imagedestroy($img); exit; } + */ } function nomeRand($n=10) { diff --git a/classesphp/mapa_openlayers.php b/classesphp/mapa_openlayers.php index 1cbf728..0585f40 100644 --- a/classesphp/mapa_openlayers.php +++ b/classesphp/mapa_openlayers.php @@ -1,5 +1,4 @@ pixelate(),str_replace("\\","/",$nomer));} } } +function inicializa(){ + clearstatcache(); + $_COOKIE = array(); + if (!function_exists('ms_GetVersion')){ + $s = PHP_SHLIB_SUFFIX; + @dl( 'php_mapscript.'.$s ); + $ler_extensoes[] = 'php_mapscript'; + } + //verificação de segurança + $_SESSION = array(); + session_name("i3GeoPHP"); + if(@$_GET["g_sid"]) + {session_id($_GET["g_sid"]);} + else + {ilegal();} + session_start(); + //var_dump($_SESSION);exit; + if(@$_SESSION["fingerprint"]) + { + $f = explode(",",$_SESSION["fingerprint"]); + if (md5('I3GEOSEC' . $_SERVER['HTTP_USER_AGENT'] . session_id()) != $f[0] && !in_array($_GET["telaR"],$f) ) + {ilegal();} + } + else + {exit;} + if(!isset($_SESSION["map_file"])) + {exit;} +} function ilegal(){ $img = imagecreatefrompng("../imagens/ilegal.png"); imagealphablending($img, false); diff --git a/index.html b/index.html index 3e65daf..fe0818c 100644 --- a/index.html +++ b/index.html @@ -6,16 +6,9 @@ - -
-

- - - - -
i3Geo
+ diff --git a/ogc.php b/ogc.php index 51b51ec..8fe0b8a 100644 --- a/ogc.php +++ b/ogc.php @@ -464,6 +464,28 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ {$nome = $cachedir."/".$layer."/".$nome;} if(file_exists($nome)) { + ob_start(); + // assuming you have image data in $imagedata + $img = file_get_contents($nome); + $length = strlen($img); + $ft = filemtime($nome); + if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"]) && (strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]) == $ft)) { + // Client's cache IS current, so we just respond '304 Not Modified'. + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ft).' GMT', true, 304); + } else { + // Image not cached or cache outdated, we respond '200 OK' and output the image. + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ft).' GMT', true, 200); + } + header('Accept-Ranges: bytes'); + header('Content-Length: '.$length); + header('Content-Type: image/png'); + print($img); + ob_end_flush(); + exit; + } + /* + if(file_exists($nome)) + { if (!function_exists('imagepng')) { $s = PHP_SHLIB_SUFFIX; @@ -474,7 +496,6 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ @$img = imagecreatefrompng($nome); if(!$img) { - /* Create a blank image */ $img = imagecreatetruecolor($w, $h); imagealphablending($img, false); imagesavealpha($img, true); @@ -483,7 +504,6 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ $tc = imagecolorallocate($img, 255, 0, 0); imagefilledrectangle($img, 0, 0, $w, $h, $bgc); - /* Output an error message */ imagestring($img, 3, 5, 5, 'Erro ao ler ' . $nome, $tc); } else @@ -498,6 +518,7 @@ function carregaCacheImagem($bbox,$layer,$w,$h,$cachedir=""){ imagedestroy($img); exit; } + */ } ?> diff --git a/pacotes/kmlmapserver/classes/layerserver.class.php b/pacotes/kmlmapserver/classes/layerserver.class.php index b84849c..5ad391d 100644 --- a/pacotes/kmlmapserver/classes/layerserver.class.php +++ b/pacotes/kmlmapserver/classes/layerserver.class.php @@ -758,9 +758,11 @@ class LayerServer { function add_style_point(&$new_style, &$style_data){ if($style_data['icon']){ $st =& $new_style->addChild('IconStyle'); - if($style_data['width'] && $style_data['icon_width'] != 32){ + if($style_data['width'] && $style_data['icon_width'] != 32){ $st->addChild('scale', $style_data['icon_width'] / 32); } + else + {$st->addChild('scale', 1);} $icon =& $st->addChild('Icon'); $icon->addChild('href', htmlentities($style_data['icon'])); } -- libgit2 0.21.2