Commit 7c6c0e65132d59c06136da5067a19616a351deb6

Authored by Edmar Moretti
1 parent 19504ddf

Correção na opção de identificação quando o tema é do tipo WMS. A definição da U…

…RL de consulta (getfeatureinfo) passou a utilizar a função interna do próprio Mapserver. A string de retorno agora é tratada com o mb_convert_string para resolver problemas de acentuação
Showing 1 changed file with 433 additions and 424 deletions   Show diff stats
classesphp/classe_atributos.php
... ... @@ -707,6 +707,7 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado
707 707 {$temas = $this->mapa->getalllayernames();}
708 708 foreach ($temas as $tem)
709 709 {
  710 +
710 711 $vermultilayer = new vermultilayer();
711 712 $vermultilayer->verifica($this->arquivo,$tem);
712 713 if ($vermultilayer->resultado == 1) // o tema e multi layer
... ... @@ -815,522 +816,530 @@ $listaDeTemas - (opcional) Lista com os códigos dos temas que serão identificado
815 816 else
816 817 {return("");}
817 818 }
818   -/*
819   -function: retornaI2
  819 + /*
  820 + function: retornaI2
820 821  
821   -Depreciado na versão 4.2
  822 + Depreciado na versão 4.2
822 823  
823   -Processa o resultado da identificação de um elemento compondo um array de strings formatadas.
  824 + Processa o resultado da identificação de um elemento compondo um array de strings formatadas.
824 825  
825   -parameters:
826   -$listatemas - Lista de temas
  826 + parameters:
  827 + $listatemas - Lista de temas
827 828  
828   -$resultados - Resultados de cada tema.
  829 + $resultados - Resultados de cada tema.
829 830  
830   -$map - Objeto Map.
831   -*/
832   -function retornaI2($listatemas,$resultados,$map)
833   -{
834   - $final = array();
835   - foreach ($listatemas as $tema)
  831 + $map - Objeto Map.
  832 + */
  833 + function retornaI2($listatemas,$resultados,$map)
836 834 {
837   - $layer = $map->getlayerbyname($tema);
838   - $nometmp = $tema;
839   - if (strtoupper($layer->getMetaData("TEMA")) != "NAO")
840   - {$nometmp = $layer->getMetaData("TEMA");}
841   - else if ($layer->getMetaData("ALTTEMA") != "")
842   - {$nometmp = $layer->getMetaData("ALTTEMA");}
843   - $nometmp = mb_convert_encoding($nometmp,"UTF-8","ISO-8859-1");
844   - $final[] = array("nome"=>$nometmp,"resultado"=>$resultados[$tema]);
  835 + $final = array();
  836 + foreach ($listatemas as $tema)
  837 + {
  838 + $layer = $map->getlayerbyname($tema);
  839 + $nometmp = $tema;
  840 + if (strtoupper($layer->getMetaData("TEMA")) != "NAO")
  841 + {$nometmp = $layer->getMetaData("TEMA");}
  842 + else if ($layer->getMetaData("ALTTEMA") != "")
  843 + {$nometmp = $layer->getMetaData("ALTTEMA");}
  844 + $nometmp = mb_convert_encoding($nometmp,"UTF-8","ISO-8859-1");
  845 + $final[] = array("nome"=>$nometmp,"resultado"=>$resultados[$tema]);
  846 + }
  847 + return $final;
845 848 }
846   - return $final;
847   -}
848 849  
849   -/*
850   -function: retornaI
  850 + /*
  851 + function: retornaI
851 852  
852   -Depreciado na versão 4.2
  853 + Depreciado na versão 4.2
853 854  
854   -Processa o resultado da identificação de um elemento compondo um array de strings formatadas.
  855 + Processa o resultado da identificação de um elemento compondo um array de strings formatadas.
855 856  
856   -parameters:
857   -$listatemas - Lista de temas
  857 + parameters:
  858 + $listatemas - Lista de temas
858 859  
859   -$resultados - Resultados de cada tema.
  860 + $resultados - Resultados de cada tema.
860 861  
861   -$map - Objeto Map.
862   -*/
863   -function retornaI($listatemas,$resultados,$map)
864   -{
865   - $final = "";
866   - foreach ($listatemas as $tema)
  862 + $map - Objeto Map.
  863 + */
  864 + function retornaI($listatemas,$resultados,$map)
867 865 {
868   - $layer = $map->getlayerbyname($tema);
869   - //pega o nome correto do tema
870   - $nometmp = $tema;
871   - if (strtoupper($layer->getMetaData("TEMA")) != "NAO")
872   - {$nometmp = $layer->getMetaData("TEMA");}
873   - else if ($layer->getMetaData("ALTTEMA") != "")
874   - {$nometmp = $layer->getMetaData("ALTTEMA");}
875   - $final = $final."!".$nometmp;
876   - $final = trim($final,"!");
877   - $rs = $resultados[$tema];
878   - $final = $final."@";
879   - foreach ($rs as $r)
  866 + $final = "";
  867 + foreach ($listatemas as $tema)
880 868 {
881   - $final = $final . "*";
882   - if ($r != " ")
  869 + $layer = $map->getlayerbyname($tema);
  870 + //pega o nome correto do tema
  871 + $nometmp = $tema;
  872 + if (strtoupper($layer->getMetaData("TEMA")) != "NAO")
  873 + {$nometmp = $layer->getMetaData("TEMA");}
  874 + else if ($layer->getMetaData("ALTTEMA") != "")
  875 + {$nometmp = $layer->getMetaData("ALTTEMA");}
  876 + $final = $final."!".$nometmp;
  877 + $final = trim($final,"!");
  878 + $rs = $resultados[$tema];
  879 + $final = $final."@";
  880 + foreach ($rs as $r)
883 881 {
884   - foreach ($r as $f)
885   - {$final = $final . $f;}
  882 + $final = $final . "*";
  883 + if ($r != " ")
  884 + {
  885 + foreach ($r as $f)
  886 + {$final = $final . $f;}
  887 + }
886 888 }
887 889 }
  890 + return $final;
888 891 }
889   - return $final;
890   -}
891   -/*
892   -function: identificaQBP
  892 + /*
  893 + function: identificaQBP
893 894  
894   -Depreciado na versão 4.2
  895 + Depreciado na versão 4.2
895 896  
896   -Identifica um elemento utilizando querybypoint.
  897 + Identifica um elemento utilizando querybypoint.
897 898  
898   -parameters:
  899 + parameters:
899 900  
900   -$tema - Tema que será identificado
  901 + $tema - Tema que será identificado
901 902  
902   -$x - Coordenada X.
  903 + $x - Coordenada X.
903 904  
904   -$y - Coordenada Y.
  905 + $y - Coordenada Y.
905 906  
906   -$map_file - Arquivo map file.
  907 + $map_file - Arquivo map file.
907 908  
908   -$resolucao - Resolução de busca.
  909 + $resolucao - Resolução de busca.
909 910  
910   -$item - Item único que será identificado.
  911 + $item - Item único que será identificado.
911 912  
912   -$tiporetorno - Tipo de retorno dos dados. Se for vazio, o retorno é formatado como string, se for shape, retorna o objeto shape
913   -*/
914   -function identificaQBP($tema,$x,$y,$map_file,$resolucao,$item="",$tiporetorno="")
915   -{
916   - $mapa = ms_newMapObj($map_file);
917   - $layer = $mapa->getLayerByName($tema);
918   - $layer->set("status",MS_DEFAULT);
919   - $layer->set("template","none.htm");
920   - $pt = ms_newPointObj();
921   - $pt->setXY($x,$y);
922   - //
923   - //operação especial para o caso de wms
924   - //
925   - if($layer->connectiontype == MS_WMS)
  913 + $tiporetorno - Tipo de retorno dos dados. Se for vazio, o retorno é formatado como string, se for shape, retorna o objeto shape
  914 + */
  915 + function identificaQBP($tema,$x,$y,$map_file,$resolucao,$item="",$tiporetorno="")
926 916 {
927   - $layer->set("toleranceunits",MS_PIXELS);
928   - $layer->set("tolerance",$resolucao);
929   - $ptimg = xy2imagem($map_file,array($x,$y));
930   - $mapa = desligatemas($mapa);
931   - $mapa = desligamargem($mapa);
932   - $imgo = $mapa->draw();
933   - //$res = $layer->getWMSFeatureInfoURL($ptimg->x, $ptimg->y, 1,"MIME");
934   - $resultado = array();
935   - $res = $layer->connection;
936   - $res .= "&request=getfeatureinfo&service=wms";
937   - $res .= "&version=1.1.0";//.($layer->getmetadata("wms_version"));
938   - $res .= "&QUERY_LAYERS=".($layer->getmetadata("wms_name"));
939   - $res .= "&LAYERS=".($layer->getmetadata("wms_name"));
940   - $bb = $mapa->extent;
941   - $res .= "&BBOX=".($bb->minx).",".($bb->miny).",".($bb->maxx).",".($bb->maxy);
942   - $res .= "&X=".round($ptimg->x);
943   - $res .= "&Y=".round($ptimg->y);
944   - $res .= "&WIDTH=".$mapa->width;
945   - $res .= "&HEIGHT=".$mapa->height;
946   - $formatoinfo = "text/plain";
947   - $formatosinfo = $layer->getmetadata("formatosinfo");
948   - if ($formatosinfo != "")
  917 + $mapa = ms_newMapObj($map_file);
  918 + $layer = $mapa->getLayerByName($tema);
  919 + $layer->set("status",MS_DEFAULT);
  920 + $layer->set("template","none.htm");
  921 + $pt = ms_newPointObj();
  922 + $pt->setXY($x,$y);
  923 + //
  924 + //operação especial para o caso de wms
  925 + //
  926 + if($layer->connectiontype == MS_WMS)
949 927 {
950   - $formatosinfo = explode(",",$formatosinfo);
951   - if ($formatosinfo[0] != ""){$formatoinfo = $formatosinfo[0];}
952   - foreach ($formatosinfo as $f)
  928 + $layer->set("toleranceunits",MS_PIXELS);
  929 + $layer->set("tolerance",$resolucao);
  930 + $ptimg = xy2imagem($map_file,array($x,$y));
  931 + $mapa = desligatemas($mapa);
  932 + $mapa = desligamargem($mapa);
  933 + $imgo = $mapa->draw();
  934 + //$res = $layer->getWMSFeatureInfoURL($ptimg->x, $ptimg->y, 1,"MIME");
  935 + $resultado = array();
  936 + $res = $layer->connection;
  937 + $res .= "&request=getfeatureinfo&service=wms";
  938 + $res .= "&version=1.1.0";//.($layer->getmetadata("wms_version"));
  939 + $res .= "&QUERY_LAYERS=".($layer->getmetadata("wms_name"));
  940 + $res .= "&LAYERS=".($layer->getmetadata("wms_name"));
  941 + $bb = $mapa->extent;
  942 + $res .= "&BBOX=".($bb->minx).",".($bb->miny).",".($bb->maxx).",".($bb->maxy);
  943 + $res .= "&X=".round($ptimg->x);
  944 + $res .= "&Y=".round($ptimg->y);
  945 + $res .= "&WIDTH=".$mapa->width;
  946 + $res .= "&HEIGHT=".$mapa->height;
  947 + $formatoinfo = "text/plain";
  948 + $formatosinfo = $layer->getmetadata("formatosinfo");
  949 + if ($formatosinfo != "")
953 950 {
954   - if(strtoupper($f) == "TEXT/PLAIN")
955   - {$formatoinfo = "text/plain";}
  951 + $formatosinfo = explode(",",$formatosinfo);
  952 + if ($formatosinfo[0] != ""){$formatoinfo = $formatosinfo[0];}
  953 + foreach ($formatosinfo as $f)
  954 + {
  955 + if(strtoupper($f) == "TEXT/PLAIN")
  956 + {$formatoinfo = "text/plain";}
  957 + }
  958 +
956 959 }
957   -
958   - }
959   - $srs = $layer->getmetadata("wms_srs");
960   - $srss = explode(" ",$srs);
961   - $srs = "EPSG:4326";
962   - foreach ($srss as $s)
963   - {
964   - if(strtoupper($s) == "EPSG:4291")
965   - {$srs = "EPSG:4291";}
966   - }
967   - $res .= "&SRS=".$srs;
968   - $resposta = file($res."&FORMAT=".$formatoinfo);
969   - $resposta = str_ireplace('<?xml version="1.0" encoding="UTF-8"?>',"",$resposta);
970   - $resposta = str_ireplace('<?xml version="1.0" encoding="ISO-8859-1"?>',"",$resposta);
971   - $resposta = str_ireplace("<?xml version='1.0' encoding='ISO-8859-1'?>","",$resposta);
972   - $resposta = str_ireplace('<?xml',"",$resposta);
973   - $resposta = str_ireplace("<","zzzzzzzzzz",$resposta);
974   - $resposta = str_ireplace(">","zzzzzzzzzz",$resposta);
975   - if (stristr(implode(" ",$resposta),"msWMSLoadGetMapParams"))
976   - {
977   - $resposta = file($res);
  960 + $srs = $layer->getmetadata("wms_srs");
  961 + $srss = explode(" ",$srs);
  962 + $srs = "EPSG:4326";
  963 + foreach ($srss as $s)
  964 + {
  965 + if(strtoupper($s) == "EPSG:4291")
  966 + {$srs = "EPSG:4291";}
  967 + }
  968 + $res .= "&SRS=".$srs;
  969 + $resposta = file($res."&FORMAT=".$formatoinfo);
978 970 $resposta = str_ireplace('<?xml version="1.0" encoding="UTF-8"?>',"",$resposta);
979 971 $resposta = str_ireplace('<?xml version="1.0" encoding="ISO-8859-1"?>',"",$resposta);
980 972 $resposta = str_ireplace("<?xml version='1.0' encoding='ISO-8859-1'?>","",$resposta);
981 973 $resposta = str_ireplace('<?xml',"",$resposta);
982 974 $resposta = str_ireplace("<","zzzzzzzzzz",$resposta);
983 975 $resposta = str_ireplace(">","zzzzzzzzzz",$resposta);
984   - }
985   - $resultado[] = $resposta;
986   - return $resultado;
987   - }
988   - if(($layer->connectiontype != MS_WMS) && ($layer->type == MS_LAYER_RASTER))
989   - {
990   - $layer->set("toleranceunits",MS_PIXELS);
991   - $layer->set("tolerance",$resolucao);
992   - $ident = @$layer->queryByPoint($pt, 0, 0); //0.01);
993   - }
994   - if (($layer->type == MS_LAYER_POINT) || ($layer->type == MS_LAYER_LINE))
995   - {
996   - $layer->set("toleranceunits",MS_PIXELS);
997   - $layer->set("tolerance",$resolucao);
998   - $ident = @$layer->queryByPoint($pt, 1, 0); //0.01);
999   - }
1000   - if ($layer->type == MS_LAYER_POLYGON)
1001   - {
1002   - $layer->set("toleranceunits",'MS_PIXEL');
1003   - $layer->set("tolerance",1);
1004   - $ident = @$layer->queryByPoint($pt, 1, 0);
1005   - }
1006   - if ($ident == MS_SUCCESS)
1007   - {
1008   - $its = $layer->getmetadata("ITENS"); // itens
1009   - if ($item != "") //utilizado pela funcao tip
1010   - {$its = $item;}
1011   - if ($its != "")
1012   - {
1013   - $descis = $layer->getmetadata("ITENSDESC"); // descri&ccedil;&atilde;o dos itens
1014   - $descisarray = explode(",",$descis); // array com a descri&ccedil;&atilde;o dos itens
1015   - $itsarray = explode(",",$its); // array com os nomes dos itens
1016   - $lks = $layer->getmetadata("ITENSLINK"); // link dos itens
1017   - $itemimg = $layer->getmetadata("ITEMIMG"); //indica um item que será utilizado para colocar um ícone
1018   - $locimg = $layer->getmetadata("IMGLOC"); //indica o local onde estão os ícones
1019   - $lksarray = explode(",",$lks);
1020   - if ($item != "") //utilizado pela funcao tip
  976 + if (stristr(implode(" ",$resposta),"msWMSLoadGetMapParams"))
1021 977 {
1022   - $descis = $item;
1023   - $descisarray = array();
1024   - $descisarray[] = $item;
1025   - $lksarray = array();
  978 + $resposta = file($res);
  979 + $resposta = str_ireplace('<?xml version="1.0" encoding="UTF-8"?>',"",$resposta);
  980 + $resposta = str_ireplace('<?xml version="1.0" encoding="ISO-8859-1"?>',"",$resposta);
  981 + $resposta = str_ireplace("<?xml version='1.0' encoding='ISO-8859-1'?>","",$resposta);
  982 + $resposta = str_ireplace('<?xml',"",$resposta);
  983 + $resposta = str_ireplace("<","zzzzzzzzzz",$resposta);
  984 + $resposta = str_ireplace(">","zzzzzzzzzz",$resposta);
1026 985 }
  986 + $resultado[] = $resposta;
  987 + return $resultado;
1027 988 }
1028   - else
  989 + if(($layer->connectiontype != MS_WMS) && ($layer->type == MS_LAYER_RASTER))
1029 990 {
1030   - if ($item != "") //utilizado pela funcao tip
1031   - {
1032   - $descisarray[] = $item;
1033   - $lksarray = array();
1034   - }
1035   - else
1036   - {
1037   - $descisarray = pegaItens($layer);
1038   - $itsarray = pegaItens($layer);
1039   - $lksarray = array();
1040   - }
  991 + $layer->set("toleranceunits",MS_PIXELS);
  992 + $layer->set("tolerance",$resolucao);
  993 + $ident = @$layer->queryByPoint($pt, 0, 0); //0.01);
1041 994 }
1042   - $res_count = $layer->getNumresults();
1043   - $sopen = $layer->open();
1044   - if($sopen == MS_FAILURE){return "erro";}
1045   - for ($i = 0; $i < $res_count; ++$i)
  995 + if (($layer->type == MS_LAYER_POINT) || ($layer->type == MS_LAYER_LINE))
1046 996 {
1047   - $valori = array();
1048   - $result = $layer->getResult($i);
1049   - $shp_index = $result->shapeindex;
1050   - $shape = $layer->getfeature($shp_index,-1);
1051   - if ($tiporetorno == "shape")
  997 + $layer->set("toleranceunits",MS_PIXELS);
  998 + $layer->set("tolerance",$resolucao);
  999 + $ident = @$layer->queryByPoint($pt, 1, 0); //0.01);
  1000 + }
  1001 + if ($layer->type == MS_LAYER_POLYGON)
  1002 + {
  1003 + $layer->set("toleranceunits",'MS_PIXEL');
  1004 + $layer->set("tolerance",1);
  1005 + $ident = @$layer->queryByPoint($pt, 1, 0);
  1006 + }
  1007 + if ($ident == MS_SUCCESS)
  1008 + {
  1009 + $its = $layer->getmetadata("ITENS"); // itens
  1010 + if ($item != "") //utilizado pela funcao tip
  1011 + {$its = $item;}
  1012 + if ($its != "")
1052 1013 {
1053   - $layer->close();
1054   - return $shape;
  1014 + $descis = $layer->getmetadata("ITENSDESC"); // descri&ccedil;&atilde;o dos itens
  1015 + $descisarray = explode(",",$descis); // array com a descri&ccedil;&atilde;o dos itens
  1016 + $itsarray = explode(",",$its); // array com os nomes dos itens
  1017 + $lks = $layer->getmetadata("ITENSLINK"); // link dos itens
  1018 + $itemimg = $layer->getmetadata("ITEMIMG"); //indica um item que será utilizado para colocar um ícone
  1019 + $locimg = $layer->getmetadata("IMGLOC"); //indica o local onde estão os ícones
  1020 + $lksarray = explode(",",$lks);
  1021 + if ($item != "") //utilizado pela funcao tip
  1022 + {
  1023 + $descis = $item;
  1024 + $descisarray = array();
  1025 + $descisarray[] = $item;
  1026 + $lksarray = array();
  1027 + }
1055 1028 }
1056   - if ($tiporetorno == "unico")
  1029 + else
1057 1030 {
1058   - $layer->close();
1059   - return $shape->values[$itsarray[0]];;
  1031 + if ($item != "") //utilizado pela funcao tip
  1032 + {
  1033 + $descisarray[] = $item;
  1034 + $lksarray = array();
  1035 + }
  1036 + else
  1037 + {
  1038 + $descisarray = pegaItens($layer);
  1039 + $itsarray = pegaItens($layer);
  1040 + $lksarray = array();
  1041 + }
1060 1042 }
1061   - $conta = 0;
1062   - foreach ($itsarray as $it)
  1043 + $res_count = $layer->getNumresults();
  1044 + $sopen = $layer->open();
  1045 + if($sopen == MS_FAILURE){return "erro";}
  1046 + for ($i = 0; $i < $res_count; ++$i)
1063 1047 {
1064   - $val = $shape->values[$it];
1065   - if ($val == ""){$val = "-";}
1066   - if(!@$lksarray[$conta]){$lksarray[$conta] = "";}
1067   - if ($lksarray[$conta] == "") //descricao,valor,link
  1048 + $valori = array();
  1049 + $result = $layer->getResult($i);
  1050 + $shp_index = $result->shapeindex;
  1051 + $shape = $layer->getfeature($shp_index,-1);
  1052 + if ($tiporetorno == "shape")
1068 1053 {
1069   - if(!@$descisarray[$conta]){$descisarray[$conta] = "";}
1070   - $valori[] = $descisarray[$conta].":#".($val)."#"." ";
  1054 + $layer->close();
  1055 + return $shape;
1071 1056 }
1072   - else
  1057 + if ($tiporetorno == "unico")
1073 1058 {
1074   - $nli = $descisarray[$conta].":#".$val."#".$lksarray[$conta];
1075   - $itemstab = pegaItens($layer);
1076   - foreach ($itemstab as $itab)
1077   - {
1078   - $busca = '['.$itab.']';
1079   - $nli = str_replace($busca,$shape->values[$itab],$nli);
1080   - }
1081   - $valori[] = $nli;
  1059 + $layer->close();
  1060 + return $shape->values[$itsarray[0]];;
1082 1061 }
1083   - if ((@$shape->values[$itemimg]) && ($itemimg != "")) //incluir icone
  1062 + $conta = 0;
  1063 + foreach ($itsarray as $it)
1084 1064 {
1085   - $valori[] = "<img src=..//".$locimg."//".$shape->values[$itemimg].".png //># # ";
  1065 + $val = $shape->values[$it];
  1066 + if ($val == ""){$val = "-";}
  1067 + if(!@$lksarray[$conta]){$lksarray[$conta] = "";}
  1068 + if ($lksarray[$conta] == "") //descricao,valor,link
  1069 + {
  1070 + if(!@$descisarray[$conta]){$descisarray[$conta] = "";}
  1071 + $valori[] = $descisarray[$conta].":#".($val)."#"." ";
  1072 + }
  1073 + else
  1074 + {
  1075 + $nli = $descisarray[$conta].":#".$val."#".$lksarray[$conta];
  1076 + $itemstab = pegaItens($layer);
  1077 + foreach ($itemstab as $itab)
  1078 + {
  1079 + $busca = '['.$itab.']';
  1080 + $nli = str_replace($busca,$shape->values[$itab],$nli);
  1081 + }
  1082 + $valori[] = $nli;
  1083 + }
  1084 + if ((@$shape->values[$itemimg]) && ($itemimg != "")) //incluir icone
  1085 + {
  1086 + $valori[] = "<img src=..//".$locimg."//".$shape->values[$itemimg].".png //># # ";
  1087 + }
  1088 + $conta = $conta + 1;
1086 1089 }
1087   - $conta = $conta + 1;
  1090 + $valori = implode("@##",$valori);
  1091 + $valori = explode("@",$valori);
  1092 + $resultado[] = $valori;
1088 1093 }
1089   - $valori = implode("@##",$valori);
1090   - $valori = explode("@",$valori);
1091   - $resultado[] = $valori;
  1094 + $layer->close();
1092 1095 }
1093   - $layer->close();
  1096 + else
  1097 + {$resultado[] = " ";}
  1098 + return $resultado;
1094 1099 }
1095   - else
1096   - {$resultado[] = " ";}
1097   - return $resultado;
1098   -}
1099   -/*
1100   -function: identificaQBP2
  1100 + /*
  1101 + function: identificaQBP2
1101 1102  
1102   -Identifica um elemento utilizando querybypoint.
  1103 + Identifica um elemento utilizando querybypoint.
1103 1104  
1104   -parameters:
  1105 + parameters:
1105 1106  
1106   -$tema - Tema que será identificado
  1107 + $tema - Tema que será identificado
1107 1108  
1108   -$x - Coordenada X.
  1109 + $x - Coordenada X.
1109 1110  
1110   -$y - Coordenada Y.
  1111 + $y - Coordenada Y.
1111 1112  
1112   -$map_file - Arquivo map file.
  1113 + $map_file - Arquivo map file.
1113 1114  
1114   -$resolucao - Resolução de busca.
  1115 + $resolucao - Resolução de busca.
1115 1116  
1116   -$item - Item único que será identificado.
  1117 + $item - Item único que será identificado.
1117 1118  
1118   -$tiporetorno - Tipo de retorno dos dados. Se for vazio, o retorno é formatado como string, se for shape, retorna o objeto shape
  1119 + $tiporetorno - Tipo de retorno dos dados. Se for vazio, o retorno é formatado como string, se for shape, retorna o objeto shape
1119 1120  
1120   -$etip {booblean} - indica se a solicitação é para obtenção dos dados do tipo etiqueta
1121   -*/
1122   -function identificaQBP2($tema,$x,$y,$map_file,$resolucao,$item="",$tiporetorno="",$etip=false,$ext="")
1123   -{
1124   - $mapa = ms_newMapObj($map_file);
1125   - if($ext != ""){
1126   - $extmapa = $mapa->extent;
1127   - $e = explode(" ",$ext);
1128   - $extmapa->setextent((min($e[0],$e[2])),(min($e[1],$e[3])),(max($e[0],$e[2])),(max($e[1],$e[3])));
1129   - }
1130   - $layer = $mapa->getLayerByName($tema);
1131   - $layer->set("status",MS_DEFAULT);
1132   - $layer->set("template","none.htm");
1133   - $pt = ms_newPointObj();
1134   - $pt->setXY($x, $y);
1135   - //
1136   - //operação especial para o caso de wms
1137   - //
1138   - if($layer->connectiontype == MS_WMS)
  1121 + $etip {booblean} - indica se a solicitação é para obtenção dos dados do tipo etiqueta
  1122 + */
  1123 + function identificaQBP2($tema,$x,$y,$map_file,$resolucao,$item="",$tiporetorno="",$etip=false,$ext="")
1139 1124 {
1140   - $layer->set("toleranceunits",MS_PIXELS);
1141   - $layer->set("tolerance",$resolucao);
1142   - $ptimg = xy2imagem($map_file,array($x,$y));
1143   - $mapa = desligatemas($mapa);
1144   - $mapa = desligamargem($mapa);
1145   - $imgo = $mapa->draw();
1146   - //$res = $layer->getWMSFeatureInfoURL($ptimg->x, $ptimg->y, 1,"MIME");
1147   - $resultado = array();
1148   - $res = $layer->connection;
1149   - $res .= "&request=getfeatureinfo&service=wms";
1150   - $res .= "&version=1.1.0";//.($layer->getmetadata("wms_version"));
1151   - $res .= "&QUERY_LAYERS=".($layer->getmetadata("wms_name"));
1152   - $res .= "&LAYERS=".($layer->getmetadata("wms_name"));
1153   - $bb = $mapa->extent;
1154   - $res .= "&BBOX=".($bb->minx).",".($bb->miny).",".($bb->maxx).",".($bb->maxy);
1155   - $res .= "&X=".round($ptimg->x);
1156   - $res .= "&Y=".round($ptimg->y);
1157   - $res .= "&WIDTH=".$mapa->width;
1158   - $res .= "&HEIGHT=".$mapa->height;
1159   - $formatoinfo = "text/plain";
1160   - $formatosinfo = $layer->getmetadata("formatosinfo");
1161   - if ($formatosinfo != "")
  1125 + $mapa = ms_newMapObj($map_file);
  1126 + if($ext != ""){
  1127 + $extmapa = $mapa->extent;
  1128 + $e = explode(" ",$ext);
  1129 + $extmapa->setextent((min($e[0],$e[2])),(min($e[1],$e[3])),(max($e[0],$e[2])),(max($e[1],$e[3])));
  1130 + }
  1131 + $layer = $mapa->getLayerByName($tema);
  1132 + $layer->set("status",MS_DEFAULT);
  1133 + $layer->set("template","none.htm");
  1134 + $pt = ms_newPointObj();
  1135 + $pt->setXY($x, $y);
  1136 + //
  1137 + //operação especial para o caso de wms
  1138 + //
  1139 + if($layer->connectiontype == MS_WMS)
1162 1140 {
1163   - $formatosinfo = explode(",",$formatosinfo);
1164   - if ($formatosinfo[0] != ""){$formatoinfo = $formatosinfo[0];}
1165   - foreach ($formatosinfo as $f)
  1141 + $layer->set("toleranceunits",MS_PIXELS);
  1142 + $layer->set("tolerance",$resolucao);
  1143 + $ptimg = xy2imagem($map_file,array($x,$y));
  1144 + $mapa = desligatemas($mapa);
  1145 + $mapa = desligamargem($mapa);
  1146 + $imgo = $mapa->draw();
  1147 + /*
  1148 + $resultado = array();
  1149 + $res = $layer->connection;
  1150 + $res .= "&request=getfeatureinfo&service=wms";
  1151 + $res .= "&version=1.1.0";//.($layer->getmetadata("wms_version"));
  1152 + $res .= "&QUERY_LAYERS=".($layer->getmetadata("wms_name"));
  1153 + $res .= "&LAYERS=".($layer->getmetadata("wms_name"));
  1154 + $bb = $mapa->extent;
  1155 + $res .= "&BBOX=".($bb->minx).",".($bb->miny).",".($bb->maxx).",".($bb->maxy);
  1156 + $res .= "&X=".round($ptimg->x);
  1157 + $res .= "&Y=".round($ptimg->y);
  1158 + $res .= "&WIDTH=".$mapa->width;
  1159 + $res .= "&HEIGHT=".$mapa->height;
  1160 + $formatoinfo = "text/plain";
  1161 + $formatosinfo = $layer->getmetadata("formatosinfo");
  1162 + if ($formatosinfo != "")
1166 1163 {
1167   - if(strtoupper($f) == "TEXT/PLAIN")
1168   - {$formatoinfo = "text/plain";}
  1164 + $formatosinfo = explode(",",$formatosinfo);
  1165 + if ($formatosinfo[0] != ""){$formatoinfo = $formatosinfo[0];}
  1166 + foreach ($formatosinfo as $f)
  1167 + {
  1168 + if(strtoupper($f) == "TEXT/PLAIN")
  1169 + {$formatoinfo = "text/plain";}
  1170 + }
  1171 +
1169 1172 }
1170   -
1171   - }
1172   - $srs = $layer->getmetadata("wms_srs");
1173   - $srss = explode(" ",$srs);
1174   - $srs = "EPSG:4326";
1175   - foreach ($srss as $s)
1176   - {
1177   - if(strtoupper($s) == "EPSG:4291")
1178   - {$srs = "EPSG:4291";}
1179   - }
1180   - $res .= "&SRS=".$srs;
1181   -
1182   - $resposta = file($res."&FORMAT=".$formatoinfo);
1183   - $resposta = str_ireplace('<?xml version="1.0" encoding="UTF-8"?>',"",$resposta);
1184   - $resposta = str_ireplace('<?xml version="1.0" encoding="ISO-8859-1"?>',"",$resposta);
1185   - $resposta = str_ireplace("<?xml version='1.0' encoding='ISO-8859-1'?>","",$resposta);
1186   - $resposta = str_ireplace('<?xml',"",$resposta);
1187   - $resposta = str_ireplace("<","zzzzzzzzzz",$resposta);
1188   - $resposta = str_ireplace(">","zzzzzzzzzz",$resposta);
1189   - if (stristr(implode(" ",$resposta),"msWMSLoadGetMapParams"))
1190   - {
  1173 + $srs = $layer->getmetadata("wms_srs");
  1174 + $srss = explode(" ",$srs);
  1175 + $srs = "EPSG:4326";
  1176 + foreach ($srss as $s)
  1177 + {
  1178 + if(strtoupper($s) == "EPSG:4291")
  1179 + {$srs = "EPSG:4291";}
  1180 + }
  1181 + $res .= "&SRS=".$srs;
  1182 + $resposta = file($res."&FORMAT=".$formatoinfo);
  1183 + */
  1184 + $res = $layer->getWMSFeatureInfoURL($ptimg->x, $ptimg->y, 1,"MIME");
1191 1185 $resposta = file($res);
  1186 + /*
1192 1187 $resposta = str_ireplace('<?xml version="1.0" encoding="UTF-8"?>',"",$resposta);
1193 1188 $resposta = str_ireplace('<?xml version="1.0" encoding="ISO-8859-1"?>',"",$resposta);
1194 1189 $resposta = str_ireplace("<?xml version='1.0' encoding='ISO-8859-1'?>","",$resposta);
1195 1190 $resposta = str_ireplace('<?xml',"",$resposta);
1196 1191 $resposta = str_ireplace("<","zzzzzzzzzz",$resposta);
1197 1192 $resposta = str_ireplace(">","zzzzzzzzzz",$resposta);
  1193 + if (stristr(implode(" ",$resposta),"msWMSLoadGetMapParams"))
  1194 + {
  1195 + $resposta = file($res);
  1196 + $resposta = str_ireplace('<?xml version="1.0" encoding="UTF-8"?>',"",$resposta);
  1197 + $resposta = str_ireplace('<?xml version="1.0" encoding="ISO-8859-1"?>',"",$resposta);
  1198 + $resposta = str_ireplace("<?xml version='1.0' encoding='ISO-8859-1'?>","",$resposta);
  1199 + $resposta = str_ireplace('<?xml',"",$resposta);
  1200 + $resposta = str_ireplace("<","zzzzzzzzzz",$resposta);
  1201 + $resposta = str_ireplace(">","zzzzzzzzzz",$resposta);
  1202 + }
  1203 + */
  1204 + $n = array();
  1205 + foreach($resposta as $r)
  1206 + {
  1207 + $t = explode("=",$r);
  1208 + $v = str_replace("\\n","",$t[1]);
  1209 + $v = str_replace("\\r","",$v);
  1210 + if(trim($v) != "")
  1211 + {
  1212 + $va = trim($v);
  1213 + $va = mb_convert_encoding($va,"UTF-8","ISO-8859-1");
  1214 + $n[] = array("alias"=>trim($t[0]),"valor"=>$va,"link"=>"","img"=>"");
  1215 + }
  1216 + }
  1217 + return array($n);
1198 1218 }
1199   - $n = array();
1200   - foreach($resposta as $r)
  1219 + if(($layer->connectiontype != MS_WMS) && ($layer->type == MS_LAYER_RASTER))
1201 1220 {
1202   - $t = explode("=",$r);
1203   - $v = str_replace("\\n","",$t[1]);
1204   - $v = str_replace("\\r","",$v);
1205   - if(trim($v) != "")
1206   - $n[] = array("alias"=>trim($t[0]),"valor"=>trim($v),"link"=>"","img"=>"");
  1221 + $layer->set("toleranceunits",MS_PIXELS);
  1222 + $layer->set("tolerance",$resolucao);
  1223 + $ident = @$layer->queryByPoint($pt, 0, 0); //0.01);
  1224 + }
  1225 + //error_reporting(E_ALL);
  1226 + if (($layer->type == MS_LAYER_POINT) || ($layer->type == MS_LAYER_LINE) || ($layer->type == MS_LAYER_CHART))
  1227 + {
  1228 + $layer->set("toleranceunits",MS_PIXELS);
  1229 + $layer->set("tolerance",$resolucao);
  1230 + $ident = @$layer->queryByPoint($pt, 1, -1); //0.01);
  1231 + }
  1232 + if ($layer->type == MS_LAYER_POLYGON)
  1233 + {
  1234 + $layer->set("toleranceunits",MS_PIXELS);
  1235 + $layer->set("tolerance",$resolucao);
  1236 + $ident = @$layer->queryByPoint($pt, 1, -1);
1207 1237 }
1208   - return array($n);
1209   - }
1210   - if(($layer->connectiontype != MS_WMS) && ($layer->type == MS_LAYER_RASTER))
1211   - {
1212   - $layer->set("toleranceunits",MS_PIXELS);
1213   - $layer->set("tolerance",$resolucao);
1214   - $ident = @$layer->queryByPoint($pt, 0, 0); //0.01);
1215   - }
1216   - //error_reporting(E_ALL);
1217   - if (($layer->type == MS_LAYER_POINT) || ($layer->type == MS_LAYER_LINE) || ($layer->type == MS_LAYER_CHART))
1218   - {
1219   - $layer->set("toleranceunits",MS_PIXELS);
1220   - $layer->set("tolerance",$resolucao);
1221   - $ident = @$layer->queryByPoint($pt, 1, -1); //0.01);
1222   - }
1223   - if ($layer->type == MS_LAYER_POLYGON)
1224   - {
1225   - $layer->set("toleranceunits",MS_PIXELS);
1226   - $layer->set("tolerance",$resolucao);
1227   - $ident = @$layer->queryByPoint($pt, 1, -1);
1228   - }
1229 1238  
1230   - if ($ident == MS_SUCCESS)
1231   - {
1232   - $itens = $layer->getmetadata("ITENS"); // itens
1233   - $itensdesc = $layer->getmetadata("ITENSDESC"); // descri&ccedil;&atilde;o dos itens
1234   - $lks = $layer->getmetadata("ITENSLINK"); // link dos itens
1235   - $itemimg = $layer->getmetadata("ITEMIMG"); //indica um item que será utilizado para colocar um ícone
1236   - $locimg = $layer->getmetadata("IMGLOC"); //indica o local onde estão os ícones
1237   - $tips = $layer->getmetadata("TIP");
1238   - $itensLayer = pegaItens($layer);
1239   -
1240   - $nitens = count($itensLayer);
1241   -
1242   - if($itens == "")
1243   - {$itens = $itensLayer;}
1244   - else
1245   - {$itens = explode(",",$itens);}
1246   -
1247   - if($itensdesc == "")
1248   - {$itensdesc = $itensLayer;}//array_fill(0, $nitens-1,'');}
1249   - else
1250   - {$itensdesc = explode(",",$itensdesc);}
1251   -
1252   - if($lks == "")
1253   - {$lks = array_fill(0, $nitens-1,'');}
1254   - else
1255   - {$lks = explode(",",$lks);}
1256   -
1257   - if($itemimg == "")
1258   - {$itemimg = array_fill(0, $nitens-1,'');}
1259   - else
1260   - {$itemimg = explode(",",$itemimg);}
1261   -
1262   - if($locimg == "")
1263   - {$locimg = array_fill(0, $nitens-1,'');}
1264   - else
1265   - {$locimg = explode(",",$locimg);}
1266   - //o retorno deve ser do tipo TIP
1267   - if($etip == true)
  1239 + if ($ident == MS_SUCCESS)
1268 1240 {
1269   - $temp = array_combine($itens,$itensdesc);
1270   - $templ = array_combine($itens,$lks);
1271   - $tempimg = array_combine($itens,$itemimg);
1272   - $temploc = array_combine($itens,$locimg);
1273   - $itensdesc = array();
1274   - $itens = array();
1275   - $lks = array();
1276   - $itemimg = array();
1277   - $locimg = array();
1278   - $tips = explode(",",$tips);
1279   - foreach($tips as $t)
  1241 + $itens = $layer->getmetadata("ITENS"); // itens
  1242 + $itensdesc = $layer->getmetadata("ITENSDESC"); // descri&ccedil;&atilde;o dos itens
  1243 + $lks = $layer->getmetadata("ITENSLINK"); // link dos itens
  1244 + $itemimg = $layer->getmetadata("ITEMIMG"); //indica um item que será utilizado para colocar um ícone
  1245 + $locimg = $layer->getmetadata("IMGLOC"); //indica o local onde estão os ícones
  1246 + $tips = $layer->getmetadata("TIP");
  1247 + $itensLayer = pegaItens($layer);
  1248 +
  1249 + $nitens = count($itensLayer);
  1250 +
  1251 + if($itens == "")
  1252 + {$itens = $itensLayer;}
  1253 + else
  1254 + {$itens = explode(",",$itens);}
  1255 +
  1256 + if($itensdesc == "")
  1257 + {$itensdesc = $itensLayer;}//array_fill(0, $nitens-1,'');}
  1258 + else
  1259 + {$itensdesc = explode(",",$itensdesc);}
  1260 +
  1261 + if($lks == "")
  1262 + {$lks = array_fill(0, $nitens-1,'');}
  1263 + else
  1264 + {$lks = explode(",",$lks);}
  1265 +
  1266 + if($itemimg == "")
  1267 + {$itemimg = array_fill(0, $nitens-1,'');}
  1268 + else
  1269 + {$itemimg = explode(",",$itemimg);}
  1270 +
  1271 + if($locimg == "")
  1272 + {$locimg = array_fill(0, $nitens-1,'');}
  1273 + else
  1274 + {$locimg = explode(",",$locimg);}
  1275 + //o retorno deve ser do tipo TIP
  1276 + if($etip == true)
1280 1277 {
1281   - $itens[] = $t;
1282   - if($temp[$t] != ""){$itensdesc[] = $temp[$t];}else{$itensdesc[] = $t;}
1283   - if($templ[$t] != ""){$lks[] = $templ[$t];}else{$lks[] = "";}
1284   - if($tempimg[$t] != ""){$itemimg[] = $tempimg[$t];}else{$itemimg[] = "";}
1285   - if($temploc[$t] != ""){$locimg[] = $temploc[$t];}else{$locimg[] = "";}
  1278 + $temp = array_combine($itens,$itensdesc);
  1279 + $templ = array_combine($itens,$lks);
  1280 + $tempimg = array_combine($itens,$itemimg);
  1281 + $temploc = array_combine($itens,$locimg);
  1282 + $itensdesc = array();
  1283 + $itens = array();
  1284 + $lks = array();
  1285 + $itemimg = array();
  1286 + $locimg = array();
  1287 + $tips = explode(",",$tips);
  1288 + foreach($tips as $t)
  1289 + {
  1290 + $itens[] = $t;
  1291 + if($temp[$t] != ""){$itensdesc[] = $temp[$t];}else{$itensdesc[] = $t;}
  1292 + if($templ[$t] != ""){$lks[] = $templ[$t];}else{$lks[] = "";}
  1293 + if($tempimg[$t] != ""){$itemimg[] = $tempimg[$t];}else{$itemimg[] = "";}
  1294 + if($temploc[$t] != ""){$locimg[] = $temploc[$t];}else{$locimg[] = "";}
  1295 + }
1286 1296 }
1287   - }
1288   - $res_count = $layer->getNumresults();
1289   - $sopen = $layer->open();
1290   - if($sopen == MS_FAILURE){return "erro";}
1291   - for ($i = 0; $i < $res_count; ++$i)
1292   - {
1293   - $valori = array();
1294   - $result = $layer->getResult($i);
1295   - $shp_index = $result->shapeindex;
1296   - $shape = $layer->getfeature($shp_index,-1);
1297   - $conta = 0;
1298   - foreach ($itens as $it)
  1297 + $res_count = $layer->getNumresults();
  1298 + $sopen = $layer->open();
  1299 + if($sopen == MS_FAILURE){return "erro";}
  1300 + for ($i = 0; $i < $res_count; ++$i)
1299 1301 {
1300   - $val = $shape->values[$it];
1301   - $link = $lks[$conta];
1302   - foreach($itens as $t)
  1302 + $valori = array();
  1303 + $result = $layer->getResult($i);
  1304 + $shp_index = $result->shapeindex;
  1305 + $shape = $layer->getfeature($shp_index,-1);
  1306 + $conta = 0;
  1307 + foreach ($itens as $it)
1303 1308 {
1304   - $valtemp = $shape->values[$t];
1305   - $busca = '['.$t.']';
1306   - $link = str_replace($busca,$valtemp,$link);
  1309 + $val = $shape->values[$it];
  1310 + $link = $lks[$conta];
  1311 + foreach($itens as $t)
  1312 + {
  1313 + $valtemp = $shape->values[$t];
  1314 + $busca = '['.$t.']';
  1315 + $link = str_replace($busca,$valtemp,$link);
  1316 + }
  1317 + $img = "";
  1318 + if($locimg[$conta] != "" && $itemimg[$conta] != "")
  1319 + {$img = "<img src='".$locimg[$conta]."//".$shape->values[$itemimg[$conta]]."' //>";}
  1320 + else
  1321 + if($itemimg[$conta] != "")
  1322 + {$img = "<img src='".$shape->values[$itemimg[$conta]]."' //>";}
  1323 +
  1324 + $arraytemp = array(
  1325 + "alias"=>mb_convert_encoding($itensdesc[$conta],"UTF-8","ISO-8859-1"),
  1326 + "valor"=>mb_convert_encoding($val,"UTF-8","ISO-8859-1"),
  1327 + "link"=>$link,
  1328 + "img"=>$img
  1329 + );
  1330 + if($etip==false)
  1331 + {$valori[] = $arraytemp;}
  1332 + else
  1333 + {$valori[$it] = $arraytemp;}
  1334 + $conta = $conta + 1;
1307 1335 }
1308   - $img = "";
1309   - if($locimg[$conta] != "" && $itemimg[$conta] != "")
1310   - {$img = "<img src='".$locimg[$conta]."//".$shape->values[$itemimg[$conta]]."' //>";}
1311   - else
1312   - if($itemimg[$conta] != "")
1313   - {$img = "<img src='".$shape->values[$itemimg[$conta]]."' //>";}
1314   -
1315   - $arraytemp = array(
1316   - "alias"=>mb_convert_encoding($itensdesc[$conta],"UTF-8","ISO-8859-1"),
1317   - "valor"=>mb_convert_encoding($val,"UTF-8","ISO-8859-1"),
1318   - "link"=>$link,
1319   - "img"=>$img
1320   - );
1321   - if($etip==false)
1322   - {$valori[] = $arraytemp;}
1323   - else
1324   - {$valori[$it] = $arraytemp;}
1325   - $conta = $conta + 1;
  1336 + $resultado[] = $valori;
1326 1337 }
1327   - $resultado[] = $valori;
  1338 + $layer->close();
1328 1339 }
1329   - $layer->close();
  1340 + else
  1341 + {$resultado[] = " ";}
  1342 + return $resultado;
1330 1343 }
1331   - else
1332   - {$resultado[] = " ";}
1333   - return $resultado;
1334   -}
1335 1344 }
1336 1345 ?>
1337 1346 \ No newline at end of file
... ...