Commit d3fc25a95f785e96682fe5a0fae5496c076de45d

Authored by Edmar Moretti
1 parent 010464f0
Exists in master

Correção no uso de JSON na requisição WMS getfeatureinfo

aplicmap/ogcws.map
... ... @@ -105,6 +105,8 @@ MAP
105 105 "ows_namespace_uri" "http://www.omsug.ca/osgis2004"
106 106 "ows_address" "http://www.mma.gov.br"
107 107 "ows_postcode" ""
  108 + "wms_info" "1.1.1"
  109 + "wms_feature_info_mime_type" "application/json"
108 110 "ows_enable_request" "*"
109 111 END
110 112 QUERYFORMAT text/html
... ...
aplicmap/ogcwsv5.map
... ... @@ -107,6 +107,7 @@ MAP
107 107 "ows_address" "http://www.mma.gov.br"
108 108 "ows_postcode" ""
109 109 "ows_enable_request" "*"
  110 + "wms_feature_info_mime_type" "application/json"
110 111 END
111 112 QUERYFORMAT text/html
112 113 LEGENDFORMAT text/html
... ...
aplicmap/ogcwsv6.map
... ... @@ -138,6 +138,7 @@ MAP
138 138 "ows_postcode" ""
139 139 "ows_enable_request" "*"
140 140 "ows_sld_enabled" "true"
  141 + "wms_feature_info_mime_type" "application/json"
141 142 END
142 143 QUERYFORMAT text/html
143 144 LEGENDFORMAT text/html
... ...
guia_de_migracao.txt
... ... @@ -3,6 +3,10 @@ GUIA DE UPDATES e UPGRADES
3 3 -------------------------------------------------------------------------------------------------
4 4 Para a versão 6.0
5 5  
  6 +- para permitir o retorno da requisição WMS getfeatureinfo em JSON, foi incluído no mapfile base utilizado para
  7 +gerar os serviços OGC a linha "wms_feature_info_mime_type" "application/json" em WEB->METADATA
  8 +Caso você utilize um mapfile específico da sua instalação, veja o arquivo original existente em i3geo/aplicmap
  9 +para fazer as adaptações.
6 10  
7 11 - style.overflow passou a ser definido automaticamente como "hidden" para previnir problemas com as janelas de informação.
8 12 Essa definição ocorre apenas quando o elemento body do HTML contiver o id definido como "i3geo" e quando seu estilo
... ...
ogc.php
... ... @@ -106,17 +106,6 @@ if(strtolower($OUTPUTFORMAT) == "kml" || strtolower($OUTPUTFORMAT) == "kmz"){
106 106 $urln = "pacotes/kmlmapserver/kmlservice.php?request=kmz&map=".$tema."&typename=".$tema;
107 107 header("Location:".$urln);
108 108 exit;
109   - /*
110   - $l = $oMap->getlayer(0);
111   - $n = $l->name."-kml";
112   - $oMap->selectOutputFormat("kml");
113   - $oMap->outputformat->setOption("STORAGE", "memory");
114   - $oMap->outputformat->setOption("FILENAME", $n.".kml");
115   - $l->setmetadata("wfs_getfeature_formatlist","kml");
116   - $oMap->save($nomeMapfileTmp);
117   - header('Content-Disposition: attachment; filename='.$n.'.kml');
118   - header("Content-type: application/vnd.google-earth.kml+xml");
119   - */
120 109 }
121 110  
122 111 //define um nome para o mapfile caso a origem seja o sistema de metadados estatisticos
... ... @@ -876,40 +865,53 @@ ms_ioinstallstdouttobuffer();
876 865 if(strtolower($req->getValueByName("REQUEST")) == "getmap" && $req->getValueByName("format") == ""){
877 866 $req->setParameter("format","image/png");
878 867 }
879   -
  868 +if(strtolower($req->getValueByName("REQUEST")) == "getfeatureinfo" && $_GET["info_format"] == "text/xml"){
  869 + $req->setParameter("info_format","application/vnd.ogc.gml");
  870 +}
  871 +//json conforme cesium
880 872 if(strtolower($req->getValueByName("REQUEST")) == "getfeatureinfo" && $_GET["info_format"] == "application/json"){
881   - $req->setParameter("info_format","text/plain");
  873 + $req->setParameter("info_format","application/vnd.ogc.gml");
882 874 $oMap->owsdispatch($req);
883 875 ms_iostripstdoutbuffercontentheaders();
884 876 ob_clean();
885 877 $r = ms_iogetstdoutbufferstring();
886   - $t = explode("=",$r);
  878 + //$r = converteenc($r);
  879 + $nome = $oMap->getlayer(0)->name;
  880 + $xml = simplexml_load_string($r);
  881 +
  882 + $json = json_encode($xml);
  883 + $r = json_decode($json,TRUE);
  884 + $propriedades = $r[$nome."_layer"];
  885 + $propriedades = $propriedades[$nome."_feature"];
  886 + $propriedades = converteenc(json_encode($propriedades));
  887 + $propriedades = json_decode($propriedades);
887 888 $n = array();
888   - if(count($t) > 1){
889   - $v = str_replace("\\n","",$t[1]);
890   - $v = str_replace("\\r","",$v);
891   - if(trim($v) != ""){
892   - $va = trim($v);
893   - $coluna = trim(explode(":",$t[0])[2]);
894   - $valor = str_replace("'","",$va);
895   - $n[] = array (
896   - "type" => "FeatureCollection",
897   - "features" => array(
898   - array(
899   - "type"=>"Feature",
900   - "id" => "",
901   - "geometry" => array(),
902   - "properties" => array(
903   - $coluna => $valor
904   - ),
905   - "geometry_name" => ""
906   - )
  889 + $n[] = array (
  890 + "type" => "FeatureCollection",
  891 + "features" => array(
  892 + array(
  893 + "type"=>"Feature",
  894 + "id" => "",
  895 + "geometry" => array(),
  896 + "properties" => array(
  897 + $propriedades
  898 + ),
  899 + "geometry_name" => ""
907 900 )
908   - );
909   - }
910   - }
  901 + )
  902 + );
911 903 header("Content-type: application/json");
912   - echo json_encode($n[0]);
  904 + $json = json_encode($n[0]);
  905 + //verifica a substituicao de alias
  906 + $itens = $oMap->getlayer(0)->getmetadata("ITENS"); // itens
  907 + $itensdesc = $oMap->getlayer(0)->getmetadata("ITENSDESC"); // descrição dos itens
  908 + $itens = explode(",",$itens);
  909 + $itensdesc = explode(",",converteenc($itensdesc));
  910 + $n = count($itens);
  911 + for($i = 0; $i < $n; $i++){
  912 + $json = str_ireplace($itens[$i],$itensdesc[$i],$json);
  913 + }
  914 + echo $json;
913 915 exit;
914 916 }
915 917  
... ... @@ -1143,4 +1145,10 @@ function renderNocacheTms(){
1143 1145 header("Content-type: image/png");
1144 1146 }
1145 1147 }
  1148 +function converteenc($texto){
  1149 + if (!mb_detect_encoding($texto,"UTF-8",true)){
  1150 + $texto = mb_convert_encoding($texto,"UTF-8","ISO-8859-1");
  1151 + }
  1152 + return $texto;
  1153 +}
1146 1154 ?>
... ...