Commit c36a6a2396b7c38b5caddf32d4537ed764d40863

Authored by Edmar Moretti
1 parent fa64b543

Aprimoramento das funções de download (documentação e rotinas de download de imagens)

classesjs/datadownload.js
@@ -308,21 +308,23 @@ function mostraDownload(retorno) @@ -308,21 +308,23 @@ function mostraDownload(retorno)
308 { 308 {
309 var retorno = retorno.data 309 var retorno = retorno.data
310 var arqs = retorno.split(",") 310 var arqs = retorno.split(",")
311 - var ins = "<b>Clique nos links para pegar os arquivos. Para obter os metadados, veja o link na árvore ao lado (o link é mostrado ao expandir o nó correspondente ao tema).</b><br><br>"  
312 - for (var arq=0;arq<arqs.length;arq++) 311 + var n = arqs.length;
  312 + if(retorno == "erro")
  313 + {var ins = "<p style=color:red >Ocorreu um erro. O tema não foi encontrado. Pode ser que o código do tema não existe na definição do mapfile. Informe o administrador do sistema.<br>";}
  314 + else
313 { 315 {
314 - var temp = arqs[arq].split(".");  
315 - arqs[arq] = temp[0];  
316 - ins += "<a href='"+window.location.protocol+"//"+window.location.host+arqs[arq]+".shp'>"+arqs[arq]+".shp<br>"  
317 - ins += "<a href='"+window.location.protocol+"//"+window.location.host+arqs[arq]+".dbf'>"+arqs[arq]+".dbf<br>"  
318 - ins += "<a href='"+window.location.protocol+"//"+window.location.host+arqs[arq]+".shx'>"+arqs[arq]+".shx<br><br>" 316 + var ins = "<b>Clique nos links para pegar os arquivos. Para obter os metadados, veja o link na árvore ao lado (o link é mostrado ao expandir o nó correspondente ao tema).</b><br><br>"
  317 + for (var arq=0;arq<n;arq++)
  318 + {
  319 + ins += "<a href='"+window.location.protocol+"//"+window.location.host+"/"+arqs[arq]+"'>"+arqs[arq]+"<br>"
  320 + }
319 } 321 }
320 - document.getElementById("corpo").innerHTML = ins  
321 } 322 }
322 else 323 else
323 { 324 {
324 - document.getElementById("corpo").innerHTML = "<p style=color:red >Ocorreu um erro<br>" 325 + var ins = "<p style=color:red >Ocorreu um erro<br>"
325 } 326 }
  327 + document.getElementById("corpo").innerHTML = ins
326 } 328 }
327 /* 329 /*
328 Function: dataDownloadLinks 330 Function: dataDownloadLinks
classesphp/funcoes_gerais.php
@@ -1186,7 +1186,7 @@ function agrupaValores($lista,$indiceChave,$indiceValor,$tipo) @@ -1186,7 +1186,7 @@ function agrupaValores($lista,$indiceChave,$indiceValor,$tipo)
1186 /* 1186 /*
1187 function: pegaItens 1187 function: pegaItens
1188 1188
1189 -Pega os itens de um tema e armazena em cache. 1189 +Pega os itens da tabela de atributos de um tema.
1190 1190
1191 parameter: 1191 parameter:
1192 $layer - objeto layer 1192 $layer - objeto layer
@@ -1199,14 +1199,6 @@ function pegaItens($layer) @@ -1199,14 +1199,6 @@ function pegaItens($layer)
1199 else 1199 else
1200 $items = array(); 1200 $items = array();
1201 return $items; 1201 return $items;
1202 -/*  
1203 - if ($layer->type != 3)  
1204 - {$layer->open();}  
1205 - $items = $layer->getItems();  
1206 - if ($layer->type != 3)  
1207 - {$layer->close();}  
1208 - return $items;  
1209 -*/  
1210 } 1202 }
1211 /* 1203 /*
1212 function: buscaRapida 1204 function: buscaRapida
@@ -1604,6 +1596,9 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE) @@ -1604,6 +1596,9 @@ function criaSHP($tema,$map_file,$locaplic,$dir_tmp,$nomeRand=TRUE)
1604 foreach ($items as $ni) 1596 foreach ($items as $ni)
1605 { 1597 {
1606 $temp = strtoupper($ni); 1598 $temp = strtoupper($ni);
  1599 + //
  1600 + //nao tem como descobrir o tamanho e tipo do campo
  1601 + //
1607 $def[] = array($temp,"C","254"); 1602 $def[] = array($temp,"C","254");
1608 } 1603 }
1609 $db = xbase_create($nomeshp.".dbf", $def); 1604 $db = xbase_create($nomeshp.".dbf", $def);
@@ -1675,6 +1670,9 @@ function downloadTema($map_file,$tema,$locaplic,$dir_tmp) @@ -1675,6 +1670,9 @@ function downloadTema($map_file,$tema,$locaplic,$dir_tmp)
1675 include_once($locaplic."/ms_configura.php"); 1670 include_once($locaplic."/ms_configura.php");
1676 else 1671 else
1677 include_once("../ms_configura.php"); 1672 include_once("../ms_configura.php");
  1673 + //
  1674 + //cria o arquivo mapfile, caso ele não exista, que servirá de base para obtenção dos dados
  1675 + //
1678 if (($map_file == "") || (!@ms_newMapObj($map_file))) //a funcao foi chamada do aplicativo datadownload 1676 if (($map_file == "") || (!@ms_newMapObj($map_file))) //a funcao foi chamada do aplicativo datadownload
1679 { 1677 {
1680 if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) 1678 if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN'))
@@ -1684,6 +1682,11 @@ function downloadTema($map_file,$tema,$locaplic,$dir_tmp) @@ -1684,6 +1682,11 @@ function downloadTema($map_file,$tema,$locaplic,$dir_tmp)
1684 $map_file = $dir_tmp."/".nomerandomico(20).".map"; 1682 $map_file = $dir_tmp."/".nomerandomico(20).".map";
1685 $map_tmp->save($map_file); 1683 $map_tmp->save($map_file);
1686 } 1684 }
  1685 + //
  1686 + //verifica se o tema existe no mapfile
  1687 + //se não existir, tenta inserir com base no mapfile existente no diretório temas
  1688 + //o tema pode existir se a função estiver sendo chamada da árvore de temas de um mapa já aberto
  1689 + //
1687 $temasdir = $locaplic."/temas"; 1690 $temasdir = $locaplic."/temas";
1688 $map = ms_newMapObj($map_file); 1691 $map = ms_newMapObj($map_file);
1689 $teste = @$map->getlayerbyname($tema); 1692 $teste = @$map->getlayerbyname($tema);
@@ -1697,13 +1700,22 @@ function downloadTema($map_file,$tema,$locaplic,$dir_tmp) @@ -1697,13 +1700,22 @@ function downloadTema($map_file,$tema,$locaplic,$dir_tmp)
1697 ms_newLayerObj($map, $ll); 1700 ms_newLayerObj($map, $ll);
1698 } 1701 }
1699 } 1702 }
  1703 + //
  1704 + //verifica novamente se o layer existe
  1705 + //
1700 $teste = @$map->getlayerbyname($tema); 1706 $teste = @$map->getlayerbyname($tema);
1701 if ($teste == "") 1707 if ($teste == "")
1702 {return "erro";} 1708 {return "erro";}
  1709 + //
  1710 + //salva o mapfile com um outro nome para evitar que o mapa atual, se estiver aberto, seja modificado
  1711 + //
1703 $map->save(str_replace(".map","tmp.map",$map_file)); 1712 $map->save(str_replace(".map","tmp.map",$map_file));
1704 $map_file = str_replace(".map","tmp.map",$map_file); 1713 $map_file = str_replace(".map","tmp.map",$map_file);
1705 $map = ms_newMapObj($map_file); 1714 $map = ms_newMapObj($map_file);
  1715 + //
1706 //verifica se existe mais de um tema (grupo) montando o array com os temas 1716 //verifica se existe mais de um tema (grupo) montando o array com os temas
  1717 + //os grupos podem ter o nome do layer em GROUP ao invés de NAME
  1718 + //
1707 $multilayer = 0; 1719 $multilayer = 0;
1708 $grupos = $map->getAllGroupNames(); 1720 $grupos = $map->getAllGroupNames();
1709 foreach ($grupos as $grupo) 1721 foreach ($grupos as $grupo)
@@ -1733,11 +1745,21 @@ function downloadTema($map_file,$tema,$locaplic,$dir_tmp) @@ -1733,11 +1745,21 @@ function downloadTema($map_file,$tema,$locaplic,$dir_tmp)
1733 { 1745 {
1734 if (file_exists($dados)) 1746 if (file_exists($dados))
1735 { 1747 {
1736 - $arq = basename($dados);  
1737 - $resultado[] = str_replace("/img","/",$map->web->imageurl).$arq;  
1738 - $arq = explode(".",$arq);  
1739 - $resultado[] = str_replace("/img","/",$map->web->imageurl).$arq[0].".wld"; 1748 + $dir = dirname($dados);
  1749 + $arq = explode(".",basename($dados));
  1750 + $nomecopia = $dir_tmp."/".$arq[0];
  1751 + $exts = array("jpg","jpw","tif","tifw","tfw","png","pngw","jpgw","wld");
  1752 + foreach($exts as $ext)
  1753 + {
  1754 + $copia = $nomecopia.".".$ext;
  1755 + if(!file_exists($copia) && file_exists($dir."/".$arq[0].".".$ext))
  1756 + {copy($dir."/".$arq[0].".".$ext,$copia);}
  1757 + if(file_exists($copia))
  1758 + $resultado[] = basename($dir_tmp)."/".basename($copia);
  1759 + }
1740 } 1760 }
  1761 + else
  1762 + {return "erro";}
1741 } 1763 }
1742 else 1764 else
1743 { 1765 {
@@ -1762,13 +1784,15 @@ function downloadTema($map_file,$tema,$locaplic,$dir_tmp) @@ -1762,13 +1784,15 @@ function downloadTema($map_file,$tema,$locaplic,$dir_tmp)
1762 copy($arq[0].".shx",$nomeshp.".shx"); 1784 copy($arq[0].".shx",$nomeshp.".shx");
1763 copy($arq[0].".dbf",$nomeshp.".dbf"); 1785 copy($arq[0].".dbf",$nomeshp.".dbf");
1764 } 1786 }
1765 - $resultado[] = str_replace($radtmp,"",$nomeshp);  
1766 } 1787 }
1767 else 1788 else
1768 { 1789 {
1769 $restemp = criaSHP($tema,$map_file,$locaplic,$dir_tmp,FALSE); 1790 $restemp = criaSHP($tema,$map_file,$locaplic,$dir_tmp,FALSE);
1770 - $resultado[] = str_replace($radtmp,"",$restemp); 1791 + $novonomelayer = str_replace($radtmp,"",$restemp);
1771 } 1792 }
  1793 + $resultado[] = basename($dir_tmp)."/".$novonomelayer.".shp";
  1794 + $resultado[] = basename($dir_tmp)."/".$novonomelayer.".dbf";
  1795 + $resultado[] = basename($dir_tmp)."/".$novonomelayer.".shx";
1772 } 1796 }
1773 } 1797 }
1774 return(implode(",",$resultado)); 1798 return(implode(",",$resultado));
ferramentas/download/index.htm
@@ -13,7 +13,7 @@ body { @@ -13,7 +13,7 @@ body {
13 </style> 13 </style>
14 </head> 14 </head>
15 <body style='background-color:white;margin:0px'> 15 <body style='background-color:white;margin:0px'>
16 -<div style="top:0px;left:10px;width:90%;" id='resultado' >&nbsp;Aguarde...</div> 16 +<div style="top:0px;left:10px;width:90%;overflow:auto;height:150px;" id='resultado' >&nbsp;Aguarde...</div>
17 <script language="JavaScript" type="text/javascript" src="../funcoes.js"></script> 17 <script language="JavaScript" type="text/javascript" src="../funcoes.js"></script>
18 <script src="../../pacotes/cpaint/cpaint2.inc.compressed.js" type="text/javascript"></script> 18 <script src="../../pacotes/cpaint/cpaint2.inc.compressed.js" type="text/javascript"></script>
19 <script language="JavaScript" type="text/javascript" src="index.js"></script> 19 <script language="JavaScript" type="text/javascript" src="index.js"></script>
ferramentas/download/index.js
@@ -33,32 +33,28 @@ function download() @@ -33,32 +33,28 @@ function download()
33 } 33 }
34 function mostraDownload(retorno) 34 function mostraDownload(retorno)
35 { 35 {
  36 +
  37 + aguarde("none")
36 if (retorno.data != undefined) 38 if (retorno.data != undefined)
37 { 39 {
38 var retorno = retorno.data 40 var retorno = retorno.data
39 - aguarde("none")  
40 var arqs = retorno.split(",") 41 var arqs = retorno.split(",")
41 - var ins = "Clique nos links para pegar os arquivos e gravar em seu computador. Caso vc deseje alterar os nomes, mantenha as extensões e use o mesmo nome para cada arquivo.<br><br>"  
42 - for (arq=0;arq<arqs.length;arq++) 42 + var n = arqs.length;
  43 + if(retorno == "erro")
  44 + {var ins = "<p style=color:red >Ocorreu um erro. O tema não foi encontrado. Pode ser que o código do tema não existe na definição do mapfile. Informe o administrador do sistema.<br>";}
  45 + else
43 { 46 {
44 - var temp = arqs[arq].split(".");  
45 - if ((temp[1] == "png") || (temp[1] == "tif") || (temp[1] == "wld"))  
46 - {  
47 - ins += "<a href='"+window.location.protocol+"//"+window.location.host+arqs[arq]+"'>"+arqs[arq]+"<br>"  
48 - }  
49 - else 47 + var ins = "<b>Clique nos links para pegar os arquivos.</b><br><br>"
  48 + for (var arq=0;arq<n;arq++)
50 { 49 {
51 - arqs[arq] = temp[0];  
52 - ins += "<a href='"+window.location.protocol+"//"+window.location.host+arqs[arq]+".shp'>"+arqs[arq]+".shp<br>"  
53 - ins += "<a href='"+window.location.protocol+"//"+window.location.host+arqs[arq]+".dbf'>"+arqs[arq]+".dbf<br>"  
54 - ins += "<a href='"+window.location.protocol+"//"+window.location.host+arqs[arq]+".shx'>"+arqs[arq]+".shx<br><br>" 50 + ins += "<a href='"+window.location.protocol+"//"+window.location.host+"/"+arqs[arq]+"'>"+arqs[arq]+"<br>"
55 } 51 }
56 } 52 }
57 - $i("resultado").innerHTML = ins  
58 } 53 }
59 else 54 else
60 { 55 {
61 - $i("resultado").innerHTML = "<p style=color:red >Ocorreu um erro<br>" 56 + var ins = "<p style=color:red >Ocorreu um erro<br>"
62 } 57 }
63 - aguarde("none") 58 + document.getElementById("resultado").innerHTML = ins
  59 +
64 } 60 }
65 \ No newline at end of file 61 \ No newline at end of file
menutemas/admin.db
No preview for this file type
temas/biomashp.map
@@ -2,7 +2,6 @@ MAP @@ -2,7 +2,6 @@ MAP
2 SYMBOLSET ../symbols/simbolos.sym 2 SYMBOLSET ../symbols/simbolos.sym
3 FONTSET "../symbols/fontes.txt" 3 FONTSET "../symbols/fontes.txt"
4 LAYER 4 LAYER
5 - CONNECTION ""  
6 DATA "c:\ms4w\apache\htdocs\geodados\brasil\vegetacao\biomas.shp" 5 DATA "c:\ms4w\apache\htdocs\geodados\brasil\vegetacao\biomas.shp"
7 METADATA 6 METADATA
8 "CLASSE" "SIM" 7 "CLASSE" "SIM"