Commit 2034aebf96a35db3cf41ca380e36744bc991e014
1 parent
e31a03a6
Exists in
master
and in
7 other branches
-
Showing
2 changed files
with
106 additions
and
63 deletions
Show diff stats
classesphp/mapa_googlemaps.php
... | ... | @@ -142,6 +142,7 @@ $mapa = ms_newMapObj($map_fileX); |
142 | 142 | $ret = $mapa->extent; |
143 | 143 | |
144 | 144 | $cache = false; |
145 | +$cortePixels = 0; | |
145 | 146 | if(!isset($_GET["telaR"])){ |
146 | 147 | //no caso de projecoes remotas, o mapfile nao e alterado |
147 | 148 | $numlayers = $mapa->numlayers; |
... | ... | @@ -155,7 +156,6 @@ if(!isset($_GET["telaR"])){ |
155 | 156 | // |
156 | 157 | //numero de pixels que serao considerados para corte da imagem no caso de cache ativo e tema de pontos |
157 | 158 | // |
158 | - $cortePixels = 0; | |
159 | 159 | if ($l->getmetadata("cortepixels") != ""){ |
160 | 160 | $cortePixels = $l->getmetadata("cortepixels"); |
161 | 161 | } |
... | ... | @@ -190,6 +190,12 @@ if(!isset($_GET["telaR"])){ |
190 | 190 | if(strtolower($l->getmetadata("cache")) == "sim"){ |
191 | 191 | $cache = true; |
192 | 192 | } |
193 | + // | |
194 | + //numero de pixels que serao considerados para corte da imagem no caso de cache ativo e tema de pontos | |
195 | + // | |
196 | + if ($l->getmetadata("cortepixels") != ""){ | |
197 | + $cortePixels = $l->getmetadata("cortepixels"); | |
198 | + } | |
193 | 199 | if($_GET["REQUEST"] == "GetFeatureInfo" || strtolower($_GET["REQUEST"]) == "getfeature" ){ |
194 | 200 | $l->setmetadata("gml_include_items","all"); |
195 | 201 | $l->set("template","none.htm"); |
... | ... | @@ -210,11 +216,11 @@ else{ |
210 | 216 | $numlayers = $mapa->numlayers; |
211 | 217 | for ($i=0;$i < $numlayers;++$i){ |
212 | 218 | $l = $mapa->getlayer($i); |
213 | - if($l->getProjection() == "" ) | |
214 | - {$l->setProjection("proj=latlong,a=6378137,b=6378137");} | |
219 | + if($l->getProjection() == "" ){ | |
220 | + $l->setProjection("proj=latlong,a=6378137,b=6378137"); | |
221 | + } | |
215 | 222 | } |
216 | 223 | } |
217 | - | |
218 | 224 | // |
219 | 225 | //qd a cahamda e para um WMS, redireciona para ogc.php |
220 | 226 | // |
... | ... | @@ -247,14 +253,16 @@ if($_GET["REQUEST"] == "GetFeatureInfo" || $_GET["REQUEST"] == "getfeature"){ |
247 | 253 | exit; |
248 | 254 | } |
249 | 255 | |
250 | -if($_GET["layer"] == "") | |
251 | -{$cache = true;} | |
252 | - | |
253 | -if(($_GET == false) || ($qy) || (strtolower($_GET["DESLIGACACHE"]) == "sim")) | |
254 | -{$cache = false;} | |
255 | -elseif(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum") | |
256 | -{$cache = false;} | |
256 | +if($_GET["layer"] == ""){ | |
257 | + $cache = true; | |
258 | +} | |
257 | 259 | |
260 | +if(($_GET == false) || ($qy) || (strtolower($_GET["DESLIGACACHE"]) == "sim")){ | |
261 | + $cache = false; | |
262 | +} | |
263 | +elseif(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum"){ | |
264 | + $cache = false; | |
265 | +} | |
258 | 266 | if($cache == true){ |
259 | 267 | carregaCacheImagem(); |
260 | 268 | } |
... | ... | @@ -287,7 +295,6 @@ if($cortePixels > 0){ |
287 | 295 | //$imagemBranco = $mapa->prepareImage(); |
288 | 296 | $escalaInicial = $mapa->scaledenom; |
289 | 297 | $extensaoInicial = $mapa->extent; |
290 | - | |
291 | 298 | $wh = 256+($cortePixels*2); |
292 | 299 | $mapa->setsize($wh,$wh); |
293 | 300 | $ponto = new pointObj(); |
... | ... | @@ -360,10 +367,17 @@ if (!function_exists('imagepng')){ |
360 | 367 | {$_GET["TIPOIMAGEM"] = "";} |
361 | 368 | } |
362 | 369 | if(trim($_GET["TIPOIMAGEM"]) != "" && trim($_GET["TIPOIMAGEM"]) != "nenhum"){ |
363 | - if($img->imagepath == "") | |
364 | - {echo "Erro IMAGEPATH vazio";exit;} | |
370 | + if($img->imagepath == ""){ | |
371 | + echo "Erro IMAGEPATH vazio";exit; | |
372 | + } | |
365 | 373 | $nomer = ($img->imagepath)."filtroimgtemp".nomeRand().".png"; |
366 | 374 | $img->saveImage($nomer); |
375 | + // | |
376 | + //corta a imagem gerada para voltar ao tamanho normal | |
377 | + // | |
378 | + if($cortePixels > 0){ | |
379 | + cortaImagemDisco($nomer,$cortePixels,256); | |
380 | + } | |
367 | 381 | filtraImg($nomer,trim($_GET["TIPOIMAGEM"])); |
368 | 382 | $img = imagecreatefrompng($nomer); |
369 | 383 | imagealphablending($img, false); |
... | ... | @@ -376,31 +390,22 @@ else{ |
376 | 390 | if($cache == true){ |
377 | 391 | $nomer = salvaCacheImagem(); |
378 | 392 | carregaCacheImagem(); |
379 | - /* | |
380 | - if($_SESSION["i3georendermode"] == 2){ | |
381 | - ob_clean(); | |
382 | - header('Cache-Control: public, max-age=22222222'); | |
383 | - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT'); | |
384 | - header("X-Sendfile: $nomer"); | |
385 | - header("Content-type: image/png"); | |
386 | - } | |
387 | - else{ | |
388 | - ob_clean(); | |
389 | - header('Content-Length: '.filesize($nomer)); | |
390 | - header('Content-Type: image/png'); | |
391 | - header('Cache-Control: public, max-age=22222222'); | |
392 | - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT'); | |
393 | - fpassthru(fopen($nomer, 'rb')); | |
394 | - } | |
395 | - */ | |
396 | 393 | } |
397 | 394 | else{ |
398 | - if($_SESSION["i3georendermode"] == 0){ | |
395 | + if($_SESSION["i3georendermode"] == 0 || ($_SESSION["i3georendermode"] == 1 && $cortePixels > 0)){ | |
399 | 396 | $nomer = ($img->imagepath)."temp".nomeRand().".png"; |
400 | 397 | $img->saveImage($nomer); |
401 | - $img = imagecreatefrompng($nomer); | |
402 | - imagealphablending($img, false); | |
403 | - imagesavealpha($img, true); | |
398 | + // | |
399 | + //corta a imagem gerada para voltar ao tamanho normal | |
400 | + // | |
401 | + if($cortePixels > 0){ | |
402 | + $img = cortaImagemDisco($nomer,$cortePixels,256); | |
403 | + } | |
404 | + else{ | |
405 | + $img = imagecreatefrompng($nomer); | |
406 | + imagealphablending($img, false); | |
407 | + imagesavealpha($img, true); | |
408 | + } | |
404 | 409 | ob_clean(); |
405 | 410 | echo header("Content-type: image/png \n\n"); |
406 | 411 | imagepng($img); |
... | ... | @@ -415,6 +420,12 @@ else{ |
415 | 420 | if($_SESSION["i3georendermode"] == 2){ |
416 | 421 | $nomer = ($img->imagepath)."temp".nomeRand().".png"; |
417 | 422 | $img->saveImage($nomer); |
423 | + // | |
424 | + //corta a imagem gerada para voltar ao tamanho normal | |
425 | + // | |
426 | + if($cortePixels > 0){ | |
427 | + $img = cortaImagemDisco($nomer,$cortePixels,256); | |
428 | + } | |
418 | 429 | ob_clean(); |
419 | 430 | header('Cache-Control: public, max-age=22222222'); |
420 | 431 | header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT'); |
... | ... | @@ -441,15 +452,13 @@ function salvaCacheImagem(){ |
441 | 452 | //corta a imagem gerada para voltar ao tamanho normal |
442 | 453 | // |
443 | 454 | if($cortePixels > 0){ |
444 | - $img = imagecreatefrompng($c."/$y.png"); | |
445 | - $imgc = imagecreate(256,256); | |
446 | - imagecopy( $imgc, $img, 0 , 0 , $cortePixels , $cortePixels , 256, 256 ); | |
447 | - imagepng($imgc,$nome); | |
448 | - } | |
455 | + $img = cortaImagemDisco($c."/$y.png",$cortePixels,256); | |
456 | + } | |
457 | + | |
449 | 458 | chmod($cachedir."/googlemaps/$layer/$z/$x",0777); |
450 | 459 | chmod($c."/$y.png",0777); |
451 | 460 | } |
452 | - return $nome; | |
461 | + return $c."/$y.png"; | |
453 | 462 | } |
454 | 463 | function carregaCacheImagem(){ |
455 | 464 | global $img,$cachedir,$x,$y,$z,$map_fileX,$i3georendermode; |
... | ... | @@ -540,4 +549,18 @@ function versaoMS() |
540 | 549 | $versao["principal"] = $v[0]; |
541 | 550 | return $versao; |
542 | 551 | } |
552 | +/** | |
553 | + * Corta uma imagem existente em disco | |
554 | + */ | |
555 | +function cortaImagemDisco($arquivo,$cortePixels,$tamanhoFinal=256){ | |
556 | + $img = imagecreatefrompng($arquivo); | |
557 | + $imgc = imagecreate($tamanhoFinal,$tamanhoFinal); | |
558 | + //@FIXME necessario, sem isso algumas imagens sao geradas de forma errada | |
559 | + imagesavealpha($imgc, true); | |
560 | + $color = imagecolorallocatealpha($imgc,0x00,0x00,0x00,127); | |
561 | + imagefill($imgc, 0, 0, $color); | |
562 | + imagecopy( $imgc, $img, 0 , 0 , $cortePixels , $cortePixels , $tamanhoFinal, $tamanhoFinal ); | |
563 | + imagepng($imgc,$arquivo); | |
564 | + return $imgc; | |
565 | +} | |
543 | 566 | ?> | ... | ... |
classesphp/mapa_openlayers.php
... | ... | @@ -251,8 +251,8 @@ if($_GET["tipolayer"] != "fundo") |
251 | 251 | //antes de gerar a imagem |
252 | 252 | // |
253 | 253 | if($cortePixels > 0){ |
254 | - $mapa->prepareImage(); | |
255 | - echo $mapa->scaledenom;exit; | |
254 | + //$mapa->prepareImage(); | |
255 | + //echo $mapa->scaledenom;exit; | |
256 | 256 | $escalaInicial = $mapa->scaledenom; |
257 | 257 | $extensaoInicial = $mapa->extent; |
258 | 258 | $wh = 256+($cortePixels*2); |
... | ... | @@ -317,16 +317,14 @@ if($_GET["TIPOIMAGEM"] != "" && $_GET["TIPOIMAGEM"] != "nenhum"){ |
317 | 317 | {echo "Erro IMAGEPATH vazio";exit;} |
318 | 318 | $nomer = ($img->imagepath)."filtroimgtemp".nomeRand().".png"; |
319 | 319 | $img->saveImage($nomer); |
320 | - filtraImg($nomer,$_GET["TIPOIMAGEM"]); | |
321 | - $img = imagecreatefrompng($nomer); | |
322 | 320 | // |
323 | 321 | //corta a imagem gerada para voltar ao tamanho normal |
324 | 322 | // |
325 | 323 | if($cortePixels > 0){ |
326 | - $imgc = imagecreate(256,256); | |
327 | - imagecopy( $imgc, $img, 0 , 0 , $cortePixels , $cortePixels , 255, 255 ); | |
328 | - $img = $imgc; | |
324 | + cortaImagemDisco($nomer,$cortePixels,256); | |
329 | 325 | } |
326 | + filtraImg($nomer,$_GET["TIPOIMAGEM"]); | |
327 | + $img = imagecreatefrompng($nomer); | |
330 | 328 | imagealphablending($img, false); |
331 | 329 | imagesavealpha($img, true); |
332 | 330 | ob_clean(); |
... | ... | @@ -358,14 +356,24 @@ else{ |
358 | 356 | } |
359 | 357 | else{ |
360 | 358 | //cache inativo |
361 | - if($img->imagepath == "") | |
362 | - {echo "Erro IMAGEPATH vazio";exit;} | |
363 | - if($_SESSION["i3georendermode"] == 0){ | |
359 | + if($img->imagepath == ""){ | |
360 | + echo "Erro IMAGEPATH vazio";exit; | |
361 | + } | |
362 | + //se for necessario cortar a imagem, $img->saveImage() nao funciona | |
363 | + if($_SESSION["i3georendermode"] == 0 || ($_SESSION["i3georendermode"] == 1 && $cortePixels > 0)){ | |
364 | 364 | $nomer = ($img->imagepath)."temp".nomeRand().".png"; |
365 | 365 | $img->saveImage($nomer); |
366 | - $img = imagecreatefrompng($nomer); | |
367 | - imagealphablending($img, false); | |
368 | - imagesavealpha($img, true); | |
366 | + // | |
367 | + //corta a imagem gerada para voltar ao tamanho normal | |
368 | + // | |
369 | + if($cortePixels > 0){ | |
370 | + $img = cortaImagemDisco($nomer,$cortePixels,256); | |
371 | + } | |
372 | + else{ | |
373 | + $img = imagecreatefrompng($nomer); | |
374 | + imagealphablending($img, false); | |
375 | + imagesavealpha($img, true); | |
376 | + } | |
369 | 377 | ob_clean(); |
370 | 378 | echo header("Content-type: image/png \n\n"); |
371 | 379 | imagepng($img); |
... | ... | @@ -380,6 +388,12 @@ else{ |
380 | 388 | if($_SESSION["i3georendermode"] == 2){ |
381 | 389 | $nomer = ($img->imagepath)."temp".nomeRand().".png"; |
382 | 390 | $img->saveImage($nomer); |
391 | + // | |
392 | + //corta a imagem gerada para voltar ao tamanho normal | |
393 | + // | |
394 | + if($cortePixels > 0){ | |
395 | + $img = cortaImagemDisco($nomer,$cortePixels,256); | |
396 | + } | |
383 | 397 | ob_clean(); |
384 | 398 | header('Cache-Control: public, max-age=22222222'); |
385 | 399 | header('Expires: ' . gmdate('D, d M Y H:i:s', time()+48*60*60) . ' GMT'); |
... | ... | @@ -404,15 +418,7 @@ function salvaCacheImagem($cachedir,$map,$tms){ |
404 | 418 | //corta a imagem gerada para voltar ao tamanho normal |
405 | 419 | // |
406 | 420 | if($cortePixels > 0){ |
407 | - $img = imagecreatefrompng($nome); | |
408 | - $imgc = imagecreate(256,256); | |
409 | - //@FIXME necessario, sem isso algumas imagens sao geradas de forma errada | |
410 | - imagesavealpha($imgc, true); | |
411 | - $color = imagecolorallocatealpha($imgc,0x00,0x00,0x00,127); | |
412 | - imagefill($imgc, 0, 0, $color); | |
413 | - | |
414 | - imagecopy( $imgc, $img, 0 , 0 , $cortePixels , $cortePixels , 256, 256 ); | |
415 | - imagepng($imgc,$nome); | |
421 | + $img = cortaImagemDisco($nome,$cortePixels,256); | |
416 | 422 | } |
417 | 423 | chmod($nome,0777); |
418 | 424 | } |
... | ... | @@ -511,4 +517,18 @@ function ilegal(){ |
511 | 517 | imagepng($img); |
512 | 518 | exit; |
513 | 519 | } |
520 | +/** | |
521 | + * Corta uma imagem existente em disco | |
522 | + */ | |
523 | +function cortaImagemDisco($arquivo,$cortePixels,$tamanhoFinal=256){ | |
524 | + $img = imagecreatefrompng($arquivo); | |
525 | + $imgc = imagecreate($tamanhoFinal,$tamanhoFinal); | |
526 | + //@FIXME necessario, sem isso algumas imagens sao geradas de forma errada | |
527 | + imagesavealpha($imgc, true); | |
528 | + $color = imagecolorallocatealpha($imgc,0x00,0x00,0x00,127); | |
529 | + imagefill($imgc, 0, 0, $color); | |
530 | + imagecopy( $imgc, $img, 0 , 0 , $cortePixels , $cortePixels , $tamanhoFinal, $tamanhoFinal ); | |
531 | + imagepng($imgc,$arquivo); | |
532 | + return $imgc; | |
533 | +} | |
514 | 534 | ?> | ... | ... |