Commit 2ee6fd7df90a2acf74586331045c3c81f5b97736

Authored by Edmar Moretti
1 parent 1c1a6520

Coreção na legenda quando é gerado KMZ. Uso do Mapserver ao invés de KMZ quando …

…a requisição OGC for KML
aplicmap/ogcwsv6.map
@@ -43,7 +43,7 @@ MAP @@ -43,7 +43,7 @@ MAP
43 NAME 'kml' 43 NAME 'kml'
44 DRIVER 'OGR/KML' 44 DRIVER 'OGR/KML'
45 MIMETYPE "application/vnd.google-earth.kml+xml" 45 MIMETYPE "application/vnd.google-earth.kml+xml"
46 - #FORMATOPTION "STORAGE=memory" 46 + FORMATOPTION "STORAGE=memory"
47 IMAGEMODE FEATURE 47 IMAGEMODE FEATURE
48 END 48 END
49 OUTPUTFORMAT 49 OUTPUTFORMAT
aplicmap/ogcwsv7.map
1 MAP 1 MAP
2 EXTENT -76.512593 -36.948432 -29.585185 7.046013 2 EXTENT -76.512593 -36.948432 -29.585185 7.046013
3 FONTSET "../symbols/fontes.txt" 3 FONTSET "../symbols/fontes.txt"
4 - SYMBOLSET "../symbols/simbolosv6.sym" 4 + SYMBOLSET "../symbols/simbolosv7.sym"
5 IMAGECOLOR 255 255 255 5 IMAGECOLOR 255 255 255
6 IMAGETYPE png 6 IMAGETYPE png
7 MAXSIZE 10000 7 MAXSIZE 10000
@@ -42,8 +42,8 @@ MAP @@ -42,8 +42,8 @@ MAP
42 OUTPUTFORMAT 42 OUTPUTFORMAT
43 NAME 'kml' 43 NAME 'kml'
44 DRIVER 'OGR/KML' 44 DRIVER 'OGR/KML'
45 - MIMETYPE "application/vnd.google-earth.kml+xml"  
46 - #FORMATOPTION "STORAGE=memory" 45 + #MIMETYPE "application/vnd.google-earth.kml+xml"
  46 + FORMATOPTION "STORAGE=memory"
47 IMAGEMODE FEATURE 47 IMAGEMODE FEATURE
48 END 48 END
49 OUTPUTFORMAT 49 OUTPUTFORMAT
classesjs/datadownload.js
@@ -319,6 +319,7 @@ function mostraDownload(retorno) @@ -319,6 +319,7 @@ function mostraDownload(retorno)
319 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=shape-zip' target=blank >Download shapefile com WFS (arquivo compactado incluindo .prj)</a><br><br>"; 319 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=shape-zip' target=blank >Download shapefile com WFS (arquivo compactado incluindo .prj)</a><br><br>";
320 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=csv' target=blank >Download CSV com WFS (arquivo compactado)</a><br><br>"; 320 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=csv' target=blank >Download CSV com WFS (arquivo compactado)</a><br><br>";
321 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=kmz' target=blank >Download KMZ</a><br><br>"; 321 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=kmz' target=blank >Download KMZ</a><br><br>";
  322 + ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=kml' target=blank >Download KML</a><br><br>";
322 323
323 for (var arq=0;arq<n;arq++) 324 for (var arq=0;arq<n;arq++)
324 { 325 {
datadownload.htm
@@ -97,6 +97,10 @@ A:hover { @@ -97,6 +97,10 @@ A:hover {
97 color: #4142ff; 97 color: #4142ff;
98 } 98 }
99 99
  100 +#panellistaarquivos_h{
  101 + line-height: 1.5;
  102 +}
  103 +
100 </style> 104 </style>
101 </head> 105 </head>
102 <body class=" yui-skin-sam " style="background-color: white;"> 106 <body class=" yui-skin-sam " style="background-color: white;">
js/datadownload.js
@@ -319,6 +319,7 @@ function mostraDownload(retorno) @@ -319,6 +319,7 @@ function mostraDownload(retorno)
319 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=shape-zip' target=blank >Download shapefile com WFS (arquivo compactado incluindo .prj)</a><br><br>"; 319 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=shape-zip' target=blank >Download shapefile com WFS (arquivo compactado incluindo .prj)</a><br><br>";
320 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=csv' target=blank >Download CSV com WFS (arquivo compactado)</a><br><br>"; 320 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=csv' target=blank >Download CSV com WFS (arquivo compactado)</a><br><br>";
321 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=kmz' target=blank >Download KMZ</a><br><br>"; 321 ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=kmz' target=blank >Download KMZ</a><br><br>";
  322 + ins += "<a href='"+g_locaplic+"/ogc.php?tema="+retorno.tema+"&SERVICE=WFS&VERSION=1.1.0&request=getfeature&OUTPUTFORMAT=kml' target=blank >Download KML</a><br><br>";
322 323
323 for (var arq=0;arq<n;arq++) 324 for (var arq=0;arq<n;arq++)
324 { 325 {
@@ -97,6 +97,9 @@ A:hover { @@ -97,6 +97,9 @@ A:hover {
97 color: #4142ff; 97 color: #4142ff;
98 } 98 }
99 99
  100 +#panellistaarquivos_h{
  101 + line-height: 1.5;
  102 +}
100 </style> 103 </style>
101 </head> 104 </head>
102 <body class=" yui-skin-sam " style="background-color: white;"> 105 <body class=" yui-skin-sam " style="background-color: white;">
@@ -211,6 +214,8 @@ A:hover { @@ -211,6 +214,8 @@ A:hover {
211 ins += 214 ins +=
212 "<p><a target=blank href='"+servico+"OUTPUTFORMAT=kmz&bbox=-76.5125927,-39.3925675209,-29.5851853,9.49014852081&service=wfs&version=1.1.0&request=getfeature&layers="+tema+"&typeName="+tema+"' />download KMZ</a>"; 215 "<p><a target=blank href='"+servico+"OUTPUTFORMAT=kmz&bbox=-76.5125927,-39.3925675209,-29.5851853,9.49014852081&service=wfs&version=1.1.0&request=getfeature&layers="+tema+"&typeName="+tema+"' />download KMZ</a>";
213 ins += 216 ins +=
  217 + "<p><a target=blank href='"+servico+"OUTPUTFORMAT=kml&bbox=-76.5125927,-39.3925675209,-29.5851853,9.49014852081&service=wfs&version=1.1.0&request=getfeature&layers="+tema+"&typeName="+tema+"' />download KML</a>";
  218 + ins +=
214 "<p><a target=blank href='"+servico+"OUTPUTFORMAT=geojson&bbox=-76.5125927,-39.3925675209,-29.5851853,9.49014852081&service=wfs&version=1.1.0&request=getfeature&layers="+tema+"&typeName="+tema+"' />GeoJson</a>"; 219 "<p><a target=blank href='"+servico+"OUTPUTFORMAT=geojson&bbox=-76.5125927,-39.3925675209,-29.5851853,9.49014852081&service=wfs&version=1.1.0&request=getfeature&layers="+tema+"&typeName="+tema+"' />GeoJson</a>";
215 ins += 220 ins +=
216 "<p><a target=blank href='ferramentas/recline/default.php?tema="+tema+"' />Explore a tabela de atributos</a>"; 221 "<p><a target=blank href='ferramentas/recline/default.php?tema="+tema+"' />Explore a tabela de atributos</a>";
@@ -181,9 +181,10 @@ if(!empty($OUTPUTFORMAT)){ @@ -181,9 +181,10 @@ if(!empty($OUTPUTFORMAT)){
181 carregaCacheArquivo(); 181 carregaCacheArquivo();
182 } 182 }
183 // 183 //
184 -//para o caso da requisicao kml 184 +//para o caso da requisicao kmz
  185 +//kmz nao funciona diretamente com mapserver
185 // 186 //
186 -if(strtolower($OUTPUTFORMAT) == "kml" || strtolower($OUTPUTFORMAT) == "kmz"){ 187 +if(strtolower($OUTPUTFORMAT) == "xkml" || strtolower($OUTPUTFORMAT) == "kmz"){
187 $urln = "pacotes/kmlmapserver/kmlservice.php?request=kmz&map=".$tema."&typename=".$tema; 188 $urln = "pacotes/kmlmapserver/kmlservice.php?request=kmz&map=".$tema."&typename=".$tema;
188 header("Location:".$urln); 189 header("Location:".$urln);
189 exit; 190 exit;
@@ -290,8 +291,7 @@ $arrayget[&quot;Z&quot;] = &quot;&quot;; @@ -290,8 +291,7 @@ $arrayget[&quot;Z&quot;] = &quot;&quot;;
290 $arrayget["X"] = ""; 291 $arrayget["X"] = "";
291 $arrayget["Y"] = ""; 292 $arrayget["Y"] = "";
292 $arrayget["tms"] = ""; 293 $arrayget["tms"] = "";
293 -$nomeMapfileTmp = $dir_tmp."/ogc_".md5(implode("",$arrayget))."_".$agora.".map";  
294 - 294 +$nomeMapfileTmp = $dir_tmp."/ogc_".md5(implode("",$arrayget))."_".$agora.".map";
295 //essa variavel e usada para definir se a imagem final gerada devera ser cortada ou nao 295 //essa variavel e usada para definir se a imagem final gerada devera ser cortada ou nao
296 $cortePixels = 0; 296 $cortePixels = 0;
297 if(file_exists($nomeMapfileTmp) && $tipo == ""){ 297 if(file_exists($nomeMapfileTmp) && $tipo == ""){
@@ -558,7 +558,7 @@ else{ @@ -558,7 +558,7 @@ else{
558 } 558 }
559 } 559 }
560 $req->setParameter("LAYERS", implode(",",$lys)); 560 $req->setParameter("LAYERS", implode(",",$lys));
561 - $req->setParameter("STYLES", ""); 561 + $req->setParameter("STYLES", "");
562 } 562 }
563 } 563 }
564 } 564 }
@@ -677,9 +677,10 @@ else{ @@ -677,9 +677,10 @@ else{
677 //caso seja download ou json ou csv 677 //caso seja download ou json ou csv
678 // 678 //
679 processaOutputformatMapfile(); 679 processaOutputformatMapfile();
680 -  
681 $oMap->save($nomeMapfileTmp); 680 $oMap->save($nomeMapfileTmp);
  681 +
682 validaAcessoTemas($nomeMapfileTmp,true); 682 validaAcessoTemas($nomeMapfileTmp,true);
  683 +
683 $oMap = ms_newMapobj($nomeMapfileTmp); 684 $oMap = ms_newMapobj($nomeMapfileTmp);
684 } 685 }
685 686
@@ -945,6 +946,35 @@ if(strtolower($OUTPUTFORMAT) == &quot;geojson&quot; || strtolower($OUTPUTFORMAT) == &quot;json&quot; @@ -945,6 +946,35 @@ if(strtolower($OUTPUTFORMAT) == &quot;geojson&quot; || strtolower($OUTPUTFORMAT) == &quot;json&quot;
945 946
946 exit; 947 exit;
947 } 948 }
  949 +if(strtolower($OUTPUTFORMAT) == "kml"){
  950 + $oMap->owsdispatch($req);
  951 + $contenttype = ms_iostripstdoutbuffercontenttype();
  952 + ms_iostripstdoutbuffercontentheaders();
  953 + //grava em disco
  954 + $arq = $dir_tmp."/".$tema.".kml";
  955 + $contents = ms_iogetstdoutbufferstring();
  956 + file_put_contents($arq,$contents);
  957 + //envia para download
  958 + header('Content-Disposition: attachment; filename='.$tema.'.kml');
  959 + ms_iogetStdoutBufferBytes();
  960 + ms_ioresethandlers();
  961 + exit;
  962 +}
  963 +//kmz nao funciona quando fornecido diretamente pelo mapserver
  964 +if(strtolower($OUTPUTFORMAT) == "kmz"){
  965 + $oMap->owsdispatch($req);
  966 + $contenttype = ms_iostripstdoutbuffercontenttype();
  967 + ms_iostripstdoutbuffercontentheaders();
  968 + //grava em disco
  969 + $arq = $dir_tmp."/".$tema.".kmz";
  970 + $contents = ms_iogetstdoutbufferstring();
  971 + file_put_contents($arq,$contents);
  972 + //envia para download
  973 + header('Content-Disposition: attachment; filename='.$tema.'.kmz');
  974 + ms_iogetStdoutBufferBytes();
  975 + ms_ioresethandlers();
  976 + exit;
  977 +}
948 if(strtolower($OUTPUTFORMAT) == "shape-zip"){ 978 if(strtolower($OUTPUTFORMAT) == "shape-zip"){
949 $oMap->owsdispatch($req); 979 $oMap->owsdispatch($req);
950 $contenttype = ms_iostripstdoutbuffercontenttype(); 980 $contenttype = ms_iostripstdoutbuffercontenttype();
@@ -1245,6 +1275,14 @@ function getfeatureinfoJson(){ @@ -1245,6 +1275,14 @@ function getfeatureinfoJson(){
1245 } 1275 }
1246 function processaOutputformatMapfile(){ 1276 function processaOutputformatMapfile(){
1247 global $OUTPUTFORMAT, $oMap, $tema, $ows_geomtype; 1277 global $OUTPUTFORMAT, $oMap, $tema, $ows_geomtype;
  1278 + if(strtolower($OUTPUTFORMAT) == "kml"){
  1279 + $l = $oMap->getlayer(0);
  1280 + $n = $l->name;
  1281 + $oMap->selectOutputFormat("kml");
  1282 + $oMap->outputformat->setOption("STORAGE", "filesystem");
  1283 + $oMap->outputformat->setOption("FILENAME", $tema.".kml");
  1284 + $l->setmetadata("wfs_getfeature_formatlist","kml");
  1285 + }
1248 if(strtolower($OUTPUTFORMAT) == "shape-zip"){ 1286 if(strtolower($OUTPUTFORMAT) == "shape-zip"){
1249 $l = $oMap->getlayer(0); 1287 $l = $oMap->getlayer(0);
1250 $n = $l->name; 1288 $n = $l->name;
@@ -1290,6 +1328,24 @@ function carregaCacheArquivo(){ @@ -1290,6 +1328,24 @@ function carregaCacheArquivo(){
1290 readfile($arq); 1328 readfile($arq);
1291 exit; 1329 exit;
1292 } 1330 }
  1331 + }
  1332 + if(strtolower($OUTPUTFORMAT) == "kml"){
  1333 + $arq = $dir_tmp."/".$tema.".kml";
  1334 + if(file_exists($arq)){
  1335 + header('Content-Disposition: attachment; filename='.$tema.'.kml');
  1336 + header("Content-type: application/vnd.google-earth.kml+xml");
  1337 + readfile($arq);
  1338 + exit;
  1339 + }
  1340 + }
  1341 + if(strtolower($OUTPUTFORMAT) == "kmz"){
  1342 + $arq = $dir_tmp."/".$tema.".kmz";
  1343 + if(file_exists($arq)){
  1344 + header('Content-Disposition: attachment; filename='.$tema.'.kmz');
  1345 + header("Content-type: application/vnd.google-earth.kmz");
  1346 + readfile($arq);
  1347 + exit;
  1348 + }
1293 } 1349 }
1294 if(strtolower($OUTPUTFORMAT) == "geojson" || strtolower($OUTPUTFORMAT) == "json"){ 1350 if(strtolower($OUTPUTFORMAT) == "geojson" || strtolower($OUTPUTFORMAT) == "json"){
1295 $arq = $dir_tmp."/".$tema.".json"; 1351 $arq = $dir_tmp."/".$tema.".json";
pacotes/kmlmapserver/classes/layerserver.class.php
@@ -157,6 +157,29 @@ class LayerServer { @@ -157,6 +157,29 @@ class LayerServer {
157 } else { 157 } else {
158 $this->_networklink = false; 158 $this->_networklink = false;
159 } 159 }
  160 + //ajusta a legenda
  161 + $numlayers = $this->map_object->numlayers;
  162 + for ($i=0;$i < $numlayers;++$i){
  163 + $layer = $this->map_object->getlayer($i);
  164 + if (($layer->data != "") && (strtoupper($layer->getmetadata("escondido")) != "SIM") && (strtoupper($layer->getmetadata("tema")) != "NAO")){
  165 + if ($layer->numclasses > 0){
  166 + $classe = $layer->getclass(0);
  167 + if (($classe->name == "") || ($classe->name == " ")){
  168 + $classe->set("name",$layer->getmetadata("tema"));
  169 + }
  170 + //corrige o titulo da legenda
  171 + if($layer->type != 3 && $layer->type != 4){
  172 + $nclass = $layer->numclasses;
  173 + for($j=0;$j<$nclass;$j++){
  174 + $classe = $layer->getclass($j);
  175 + if($classe->title === ""){
  176 + $classe->title = $classe->name;
  177 + }
  178 + }
  179 + }
  180 + }
  181 + }
  182 + }
160 $imageObj = $this->map_object->drawlegend(); 183 $imageObj = $this->map_object->drawlegend();
161 $url = $imageObj->saveWebImage(); 184 $url = $imageObj->saveWebImage();
162 $protocolo = explode("/",$_SERVER['SERVER_PROTOCOL']); 185 $protocolo = explode("/",$_SERVER['SERVER_PROTOCOL']);