Commit 0deb109733df1ce09df75b928a5cde64b7bd4622

Authored by Edmar Moretti
1 parent 89d59223
Exists in master

Alteração em ogc.php para permitir o desenho de mais de uma camada com getmap. I…

…nclusão de parametro para definir o template da legenda em HTML. Ajustes na apresentação dos títulos das classes em legendas inseridas no mapa
Showing 1 changed file with 200 additions and 159 deletions   Show diff stats
ogc.php
... ... @@ -36,9 +36,12 @@ se for igual a "temaswfs", mostra a lista de links WFS
36 36  
37 37 ajuda - (opcional) mostra uma ajuda ao usuário
38 38  
39   -tema - (opcional) nome do tema que será mostrado no serviço. Se for definido, o web service conterá apenas esse tema. O tema é o nome do mapfile existente em i3geo/temas, mas pode ser especificado um mapfile existente em outra pasta. Nesse caso, deve-se especificar o caminho completo para o arquivo. Se não for definido, serão considerados todos os temas
  39 +tema ou temas - (opcional) nome do tema que será mostrado no serviço. Se for definido, o web service conterá apenas esse tema. O tema é o nome do mapfile existente em i3geo/temas, mas pode ser especificado um mapfile existente em outra pasta. Nesse caso, deve-se especificar o caminho completo para o arquivo. Se não for definido, serão considerados todos os temas
40 40  
41 41 legenda - (opcional) mostra a legenda no corpo do mapa sim|nao
  42 +
  43 +templateLegenda - (opcional) nome de um template HTML para uso em legendas do tipo text/html. Dever ser o caminho relativo a pasta
  44 +onde o i3Geo esta instalado e deve usar a extensao .htm. Sobre templates, veja a documentacao do Mapserver. exemplo &templateLegenda=aplicmap/legenda8.htm
42 45  
43 46 perfil - (opcional) perfil utilizado para restringir os temas que serão mostrados
44 47  
... ... @@ -255,7 +258,7 @@ if(strtolower($OUTPUTFORMAT) == "shape-zip" && $ogrOutput == false){
255 258 ob_end_clean();
256 259 header('Content-type: application/zip');
257 260 header('Content-Disposition: attachment; filename='.basename($zip));
258   - echo file_get_contents($zip);
  261 + readfile($zip);
259 262 }
260 263 exit;
261 264 }
... ... @@ -432,9 +435,9 @@ else{
432 435 }
433 436 $e = $oMap->extent;
434 437 $extensaoMap = ($e->minx)." ".($e->miny)." ".($e->maxx)." ".($e->maxy);
435   - //gera o mapa
  438 + //gera o mapa
436 439 if ($tema != ""){
437   - $listatema = explode(" ",$tema);
  440 + $listatema = explode(" ",str_replace(","," ",$tema));
438 441 //para o caso do tema ser um arquivo mapfile existente em uma pasta qualquer
439 442 //$temai3geo = true indica que o layer será buscado na pasta i3geo/temas
440 443 $temai3geo = true;
... ... @@ -452,8 +455,7 @@ else{
452 455 if($temai3geo == true && file_exists($locaplic."/temas/".$tx.".gvp")){
453 456 $extensao = ".gvp";
454 457 }
455   - if($extensao == ".map"){
456   -
  458 + if($extensao == ".map"){
457 459 //cria o mapfile com base no sistema de metadados estatisticos
458 460 //verifica se o id_medida_variavel existe no mapfile e nao foi passado como um parametro
459 461 if(!isset($_GET["id_medida_variavel"]) && $temai3geo == true){
... ... @@ -477,7 +479,7 @@ else{
477 479 if($temai3geo == true){
478 480 $nmap = ms_newMapobj($locaplic."/temas/".$tx.".map");
479 481 $nmap->setmetadata("ows_enable_request","*");
480   - }
  482 + }
481 483 if($temai3geo == false || empty($layers)){
482 484 $ts = $nmap->getalllayernames();
483 485 $nmap->setmetadata("ows_enable_request","*");
... ... @@ -489,128 +491,146 @@ else{
489 491 $l = $nmap->getlayerbyname($t);
490 492 if($l == ""){
491 493 $l = $nmap->getlayer(0);
492   - }
493   - $permite = $l->getmetadata("permiteogc");
494   - if(strtolower($permite) != "nao"){
495   - //necessário pq o mapfile pode ter todos os layers como default
496   - if($temai3geo == false){
497   - $l->set("status",MS_OFF);
498   - }
499   - else{
500   - $l->set("status",MS_DEFAULT);
501   - }
502   - $l->setmetadata("ows_title",pegaNome($l));
503   - $l->setmetadata("ows_srs",$listaepsg);
504   - $l->set("group","");
505   - //timeout
506   - $tout = $l->getmetadata("wms_connectiontimeout");
507   - if($tout == ""){
508   - $l->setmetadata("wms_connectiontimeout",0);
509   - }
510   - //essa linha é necessária pq as vezes no mapfile não tem nenhum layer com o nome igual ao nome do mapfile
511   - if(count($ts)==1 && $temai3geo == true){
512   - $l->set("name",$tx);
513   - }
514   - $l->setmetadata("gml_include_items","all");
515   - $l->set("template","none.htm");
516   - $l->set("dump",MS_TRUE);
517   - $l->setmetadata("WMS_INCLUDE_ITEMS","all");
518   - $l->setmetadata("WFS_INCLUDE_ITEMS","all");
  494 + }
  495 + //verifica se ja existe layer com mesmo nome
  496 + if($oMap->getlayerbyname($l->name) == ""){
  497 + $permite = $l->getmetadata("permiteogc");
  498 + if(strtolower($permite) != "nao"){
  499 + //necessário pq o mapfile pode ter todos os layers como default
  500 + if($temai3geo == false){
  501 + $l->set("status",MS_OFF);
  502 + }
  503 + else{
  504 + $l->set("status",MS_DEFAULT);
  505 + }
  506 + $l->setmetadata("ows_title",pegaNome($l));
  507 + $l->setmetadata("ows_srs",$listaepsg);
  508 + $l->set("group","");
  509 + //timeout
  510 + $tout = $l->getmetadata("wms_connectiontimeout");
  511 + if($tout == ""){
  512 + $l->setmetadata("wms_connectiontimeout",0);
  513 + }
  514 + //essa linha é necessária pq as vezes no mapfile não tem nenhum layer com o nome igual ao nome do mapfile
  515 + if(count($ts)==1 && $temai3geo == true){
  516 + $l->set("name",$tx);
  517 + }
  518 + $l->setmetadata("gml_include_items","all");
  519 + $l->set("template","none.htm");
  520 + $l->set("dump",MS_TRUE);
  521 + $l->setmetadata("WMS_INCLUDE_ITEMS","all");
  522 + $l->setmetadata("WFS_INCLUDE_ITEMS","all");
519 523  
520   - if(file_exists($locaplic."/temas/miniaturas/".$t.".map.mini.png")){
521   - $mini = $proto.$server.dirname($_SERVER['PHP_SELF'])."/temas/miniaturas/".$t.".map.mini.png";
522   - $l->setmetadata("wms_attribution_logourl_format","image/png");
523   - $l->setmetadata("wms_attribution_logourl_height","50");
524   - $l->setmetadata("wms_attribution_logourl_width","50");
525   - $l->setmetadata("wms_attribution_logourl_href",$mini);
526   - }
527   - if($l->type == MS_LAYER_RASTER && $l->numclasses > 0){
528   - $c = $l->getclass(0);
529   - if($c->name == ""){
530   - $c->name = " ";
  524 + if(file_exists($locaplic."/temas/miniaturas/".$t.".map.mini.png")){
  525 + $mini = $proto.$server.dirname($_SERVER['PHP_SELF'])."/temas/miniaturas/".$t.".map.mini.png";
  526 + $l->setmetadata("wms_attribution_logourl_format","image/png");
  527 + $l->setmetadata("wms_attribution_logourl_height","50");
  528 + $l->setmetadata("wms_attribution_logourl_width","50");
  529 + $l->setmetadata("wms_attribution_logourl_href",$mini);
531 530 }
532   - }
533   - //inclui extensao geografica
534   - $extensao = $l->getmetadata("EXTENSAO");
535   - if($extensao == ""){
536   - $extensao = $extensaoMap;
537   - }
538   - $l->setmetadata("wms_extent",$extensao);
539   - if (!empty($postgis_mapa)){
540   - if ($l->connectiontype == MS_POSTGIS){
  531 + if($l->type == MS_LAYER_RASTER && $l->numclasses > 0){
  532 + $c = $l->getclass(0);
  533 + if($c->name == ""){
  534 + $c->name = " ";
  535 + }
  536 + }
  537 + //inclui extensao geografica
  538 + $extensao = $l->getmetadata("EXTENSAO");
  539 + if($extensao == ""){
  540 + $extensao = $extensaoMap;
  541 + }
  542 + $l->setmetadata("wms_extent",$extensao);
  543 + if (!empty($postgis_mapa)){
  544 + if ($l->connectiontype == MS_POSTGIS){
541 545  
542   - $lcon = $l->connection;
543   - if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))){
544   - //
545   - //o metadata CONEXAOORIGINAL guarda o valor original para posterior substituição
546   - //
547   - if(($lcon == " ") || ($lcon == "")){
548   - $l->set("connection",$postgis_mapa);
549   - $l->setmetadata("CONEXAOORIGINAL",$lcon);
550   - }
551   - else{
552   - $l->set("connection",$postgis_mapa[$lcon]);
553   - $l->setmetadata("CONEXAOORIGINAL",$lcon);
  546 + $lcon = $l->connection;
  547 + if (($lcon == " ") || ($lcon == "") || (in_array($lcon,array_keys($postgis_mapa)))){
  548 + //
  549 + //o metadata CONEXAOORIGINAL guarda o valor original para posterior substituição
  550 + //
  551 + if(($lcon == " ") || ($lcon == "")){
  552 + $l->set("connection",$postgis_mapa);
  553 + $l->setmetadata("CONEXAOORIGINAL",$lcon);
  554 + }
  555 + else{
  556 + $l->set("connection",$postgis_mapa[$lcon]);
  557 + $l->setmetadata("CONEXAOORIGINAL",$lcon);
  558 + }
554 559 }
555 560 }
556   - }
557   - }
  561 + }
558 562  
559   - autoClasses($l,$oMap);
  563 + autoClasses($l,$oMap);
560 564  
561   - if($versao > 5){
562   - $pr = $l->getProcessing();
563   - if(!in_array("LABEL_NO_CLIP=True",$pr)){
564   - $l->setprocessing("LABEL_NO_CLIP=True");
  565 + if($versao > 5){
  566 + $pr = $l->getProcessing();
  567 + if(!in_array("LABEL_NO_CLIP=True",$pr)){
  568 + $l->setprocessing("LABEL_NO_CLIP=True");
  569 + }
  570 + if(!in_array("POLYLINE_NO_CLIP=True",$pr)){
  571 + $l->setprocessing("POLYLINE_NO_CLIP=True");
  572 + }
565 573 }
566   - if(!in_array("POLYLINE_NO_CLIP=True",$pr)){
567   - $l->setprocessing("POLYLINE_NO_CLIP=True");
  574 +
  575 + //
  576 + //verifica se existem parametros de substituicao passados via url
  577 + //
  578 + $parametro = $_GET["map_layer_".$l->name."_filter"];
  579 + //echo $parametro;exit;
  580 + if(!empty($parametro)){
  581 + $l->setfilter($parametro);
  582 + $cache = false;
568 583 }
  584 + //muda o title se for vazio
  585 + $nclass = $l->numclasses;
  586 + for($i=0;$i<$nclass;$i++){
  587 + $classe = $l->getclass($i);
  588 + if($classe->title == ""){
  589 + $classe->title = $classe->name;
  590 + }
  591 + }
  592 + if($nclass == 1){
  593 + $classe = $l->getclass(0);
  594 + if($classe->name == ""){
  595 + $classe->title = $l->getmetadata("tema");
  596 + $classe->set("name",$l->getmetadata("tema"));
  597 + }
  598 + }
  599 + ms_newLayerObj($oMap, $l);
569 600 }
570   -
571   - //
572   - //verifica se existem parametros de substituicao passados via url
573   - //
574   - $parametro = $_GET["map_layer_".$l->name."_filter"];
575   - //echo $parametro;exit;
576   - if(!empty($parametro)){
577   - $l->setfilter($parametro);
578   - $cache = false;
579   - }
580   - ms_newLayerObj($oMap, $l);
581   - }
582   - else{
583   - //a camada nao pode ser usada como servico WMS, entao e enviada uma mensagem
584   - $l->set("data","");
585   - $l->set("type",MS_POINT);
586   - $l->setmetadata("cache","nao");
587   - //apaga as classes
588   - $nclass = $l->numclasses;
589   - for($i=0;$i<$nclass;$i++){
590   - $classe = $l->getclass($i);
591   - $classe->set("status",MS_DELETE);
  601 + else{
  602 + //a camada nao pode ser usada como servico WMS, entao e enviada uma mensagem
  603 + $l->set("data","");
  604 + $l->set("type",MS_POINT);
  605 + $l->setmetadata("cache","nao");
  606 + //apaga as classes
  607 + $nclass = $l->numclasses;
  608 + for($i=0;$i<$nclass;$i++){
  609 + $classe = $l->getclass($i);
  610 + $classe->set("status",MS_DELETE);
  611 + }
  612 + $l->updatefromstring('
  613 + LAYER
  614 + SIZEUNITS PIXELS
  615 + TRANSFORM FALSE
  616 + CLASS
  617 + LABEL
  618 + SIZE 10
  619 + TYPE truetype
  620 + FONT arial
  621 + COLOR 255 0 0
  622 + POSITION cc
  623 + FORCE true
  624 + END
  625 + END
  626 + FEATURE POINTS 100 100 END
  627 + TEXT "OGC denied" END
  628 + FEATURE POINTS 100 120 END
  629 + TEXT "' . $l->name . '" END
  630 + END
  631 + ');
  632 + ms_newLayerObj($oMap, $l);
592 633 }
593   - $l->updatefromstring('
594   - LAYER
595   - SIZEUNITS PIXELS
596   - TRANSFORM FALSE
597   - CLASS
598   - LABEL
599   - SIZE 10
600   - TYPE truetype
601   - FONT arial
602   - COLOR 255 0 0
603   - POSITION cc
604   - FORCE true
605   - END
606   - END
607   - FEATURE POINTS 100 100 END
608   - TEXT "OGC denied" END
609   - FEATURE POINTS 100 120 END
610   - TEXT "' . $l->name . '" END
611   - END
612   - ');
613   - ms_newLayerObj($oMap, $l);
614 634 }
615 635 }
616 636 }
... ... @@ -767,7 +787,6 @@ else{
767 787 }
768 788 }
769 789 }
770   -
771 790 //
772 791 //a imagem do mapa recebera a legenda
773 792 //
... ... @@ -787,11 +806,9 @@ else{
787 806 $nomeMapfileTmp = str_replace(".map","",$nomeMapfileTmp).".map";
788 807 restauraConObj($oMap,$postgis_mapa);
789 808 $oMap->save($nomeMapfileTmp);
790   -
791 809 validaAcessoTemas($oMap,true);
792 810 substituiConObj($oMap,$postgis_mapa);
793   -}
794   -
  811 +}
795 812 if(ob_get_contents ()){
796 813 ob_end_clean();
797 814 }
... ... @@ -955,50 +972,74 @@ if(isset($_GET[&quot;Z&quot;]) &amp;&amp; isset($_GET[&quot;X&quot;])){
955 972 renderNocacheTms();
956 973 }
957 974 if(strtolower($req->getValueByName("REQUEST")) == "getlegendgraphic"){
958   - $l = $oMap->getlayer(0);
959   - if($req->getValueByName("LAYER") == ""){
960   - $req->setParameter("LAYER",$l->name);
961   - }
962   - //muda o title se for vazio
963   - $nclass = $l->numclasses;
964   - for($i=0;$i<$nclass;$i++){
965   - $classe = $l->getclass($i);
966   - if($classe->title === ""){
967   - $classe->title = $classe->name;
968   - }
969   - }
970   - if($req->getValueByName("FORMAT") == ""){
971   - $req->setParameter("FORMAT","image/png");
972   - }
973 975 $legenda = $oMap->legend;
974 976 $legenda->set("status",MS_ON);
975   - $l->set("minscaledenom",0);
976   - $l->set("maxscaledenom",0);
977   - if($req->getValueByName("FORMAT") == "text/html"){
978   - //$req->setParameter("FORMAT","image/png");
979   - $l = $oMap->getlayerbyname($req->getValueByName("LAYER"));
  977 + $numlayers = $oMap->numlayers;
  978 + for ($i=0;$i < $numlayers;$i++){
  979 + $l = $oMap->getlayer($i);
980 980 $l->set("status",MS_DEFAULT);
981   - //remove offset de simbolos pontuais
982   - $nclass = $l->numclasses;
983   - for($cc = 0; $cc < $nclass; $cc++){
984   - $classe = $l->getclass($cc);
985   - if($classe->numstyles > 0){
986   - $estilo = $classe->getstyle(0);
987   - if($estilo->symbolname != "" && file_exists($estilo->symbolname)){
988   - $estilo->set("offsetx",0);
989   - $estilo->set("offsety",0);
990   - }
  981 + if($req->getValueByName("LAYER") == ""){
  982 + $req->setParameter("LAYER",$l->name);
  983 + }
  984 +
  985 + //muda o title se for vazio
  986 + /*
  987 + $nclass = $l->numclasses;
  988 + for($i=0;$i<$nclass;$i++){
  989 + $classe = $l->getclass($i);
  990 + if($classe->title == ""){
  991 + $classe->title = $classe->name;
  992 + }
  993 + }
  994 + if($nclass == 1){
  995 + $classe = $l->getclass(0);
  996 + if($classe->name == ""){
  997 + $classe->title = $l->getmetadata("tema");
  998 + $classe->set("name",$l->getmetadata("tema"));
991 999 }
  1000 + }
  1001 + */
  1002 + if($req->getValueByName("FORMAT") == ""){
  1003 + $req->setParameter("FORMAT","image/png");
992 1004 }
993   - $legenda->set("template",$locaplic."/aplicmap/legendaOgc.html");
994   - $tmparray["my_tag"] = "value_of_my_tag";
995   - if($leg = @$oMap->processlegendtemplate($tmparray)){
996   - if (function_exists("mb_convert_encoding")){
997   - $leg = mb_convert_encoding($leg,"UTF-8","ISO-8859-1");
  1005 + $l->set("minscaledenom",0);
  1006 + $l->set("maxscaledenom",0);
  1007 + if($req->getValueByName("FORMAT") == "text/html"){
  1008 + //remove offset de simbolos pontuais
  1009 + $nclass = $l->numclasses;
  1010 + for($cc = 0; $cc < $nclass; $cc++){
  1011 + $classe = $l->getclass($cc);
  1012 + if($classe->numstyles > 0){
  1013 + $estilo = $classe->getstyle(0);
  1014 + if($estilo->symbolname != "" && file_exists($estilo->symbolname)){
  1015 + $estilo->set("offsetx",0);
  1016 + $estilo->set("offsety",0);
  1017 + }
  1018 + }
998 1019 }
  1020 + }
  1021 + }
  1022 + if($req->getValueByName("FORMAT") == "text/html"){
  1023 + //define qual template utilizar
  1024 + if(empty($_GET["templateLegenda"])){
  1025 + $legenda->set("template",$locaplic."/aplicmap/legendaOgc.html");
  1026 + } else {
  1027 + $_GET["templateLegenda"] = str_replace(".htm","",$_GET["templateLegenda"]);
  1028 + $_GET["templateLegenda"] = str_replace(".","",$_GET["templateLegenda"]);
  1029 + if(file_exists($locaplic."/".$_GET["templateLegenda"].".htm")){
  1030 + $legenda->set("template",$locaplic."/".$_GET["templateLegenda"].".htm");
  1031 + } else {
  1032 + $legenda->set("template",$locaplic."/aplicmap/legendaOgc.html");
  1033 + }
  1034 + }
  1035 + $tmparray["my_tag"] = "value_of_my_tag";
  1036 + if($leg = @$oMap->processlegendtemplate($tmparray)){
  1037 + if (function_exists("mb_convert_encoding")){
  1038 + $leg = mb_convert_encoding($leg,"UTF-8","ISO-8859-1");
  1039 + }
999 1040 echo $leg;
1000   - exit;
1001   - }
  1041 + exit;
  1042 + }
1002 1043 }
1003 1044 }
1004 1045  
... ...