/* Title: Utilitários File: i3geo/classesjs/classe_util.js About: Licença I3Geo Interface Integrada de Ferramentas de Geoprocessamento para Internet Direitos Autorais Reservados (c) 2006 Ministério do Meio Ambiente Brasil Desenvolvedor: Edmar Moretti edmar.moretti@mma.gov.br Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo sob os termos da Licença Pública Geral GNU conforme publicada pela Free Software Foundation; tanto a versão 2 da Licença. Este programa é distribuído na expectativa de que seja útil, porém, SEM NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral do GNU para mais detalhes. Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto com este programa; se não, escreva para a Free Software Foundation, Inc., no endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. */ if(typeof(i3GEO) == 'undefined'){ i3GEO = new Array(); } /* Variable: navm Verdadeiro (true) se o navegador for o Internet Explorer */ navm = false; /* Variable: navn Verdadeiro (true) se o navegador for o Firefox */ navn = false; //seta as variáveis navn e navm var app = navigator.appName.substring(0,1); if (app=='N') navn=true; else navm=true; /* Variable: g_operacao Nome da última operação que foi executada. Dependendo do tipo de operação são aplicadas as atualizações necessárias aos componentes do mapa. Por exemplo, redesenha o corpo do mapa, atualiza a lista de temas, etc. Essas operações são controladas pela função ajaxiniciaparametros. */ g_operacao = ""; /* Variable: g_tipoacao Tipo de ação que está sendo executada. Quando o usuário clica no mapa, essa variável é pesquisada para definir o tipo de operação que deve ser executada. É definida quando o usuário seleciona uma determinada ferramenta do i3Geo. */ g_tipoacao = "zoomli"; g_postpx = "px"; g_tipotop = "top"; g_tipoleft = "left"; if (navm) { g_postpx = ""; //utilizado para crossbrowser g_tipotop = "pixelTop"; //utilizado para crossbrowser g_tipoleft = "pixelLeft"; //utilizado para crossbrowser } /* Function: $i Obtém um elemento DOM a partir de seu id Parameters: id - {String} ID do elemento. Returns: {Object} Objeto. */ $i = function(id) {return document.getElementById(id);}; /* Function: Array.remove() Extende os métodos de um objeto Array, permitindo remover um elemento. */ Array.prototype.remove=function(s){ try{ var i = this.indexOf(s); if(i != -1) this.splice(i, 1); }catch(e){} }; /* Class: i3GEO.util Utilitários. */ i3GEO.util = { /* Variable: PINS Elementos IMG criados na função criaPin Type: {Array} */ PINS: new Array(), /* Variable: BOXES Elementos DIV criados na função criaBox Type: {Array} */ BOXES: new Array(), /* Function: escapeURL Converte uma string em uma url válida Parameters: sUrl {String} - url que será convertida Return: Type: {String} */ escapeURL: function(sUrl){ var sUrl = escape(sUrl); var re = new RegExp("%3F", "g"); var sUrl = sUrl.replace(re,'?'); var re = new RegExp("%3D", "g"); var sUrl = sUrl.replace(re,'='); var re = new RegExp("%26", "g"); var sUrl = sUrl.replace(re,'&'); return sUrl; }, /* Function: insereCookie Cria um novo cookie. Parameters: nome - {String} Nome do cookie. valor - (String) Valor do cookie */ insereCookie: function(nome,valor) { document.cookie = nome+"="+valor+";path=/"; }, /* Function: pegaCookie Pega o valor de um cookie. Parameters: nome - {String} Nome do cookie. Returns: (String) - valor do cookie */ pegaCookie: function(nome){ var cookies = document.cookie; var i = cookies.indexOf(nome); if(i == -1) {return null;} var fim = cookies.indexOf(";",i); if (fim == -1) {var fim = cookies.length;} return (unescape(cookies.substring(i,fim))).split("=")[1]; }, /* Function: listaChaves Lista as chaves de um objeto. Parameters: obj - {Object} Return: (Array) - array com as chaves. */ listaChaves: function (obj) { var keys = []; for(var key in obj){ keys.push(key); } return keys; }, /* Function: criaBotaoAplicar Cria um botão flutuante do tipo aplicar. O novo botão é adicionado no DOM com ID "i3geo_aplicar" e posicionado sobre o objeto definido Parameters: nomeFuncao - {String} Nome da função que será executada quando o botão for cllicado titulo - (opcional) {String} Título que será mostrado no botão classe - (opcional) {String} Nome da classe (estilo) que será aplicado ao botão. obj - (opcional) {Objeto} Objeto DOM que foi clicado para provocar a criação do botão. Return: (Object) - Objeto DOM criado. */ criaBotaoAplicar: function (nomeFuncao,titulo,classe,obj) { try{clearTimeout(tempoBotaoAplicar);}catch(e){}; tempoBotaoAplicar = eval("setTimeout('"+nomeFuncao+"\(\)',(i3GEO.configura.tempoAplicar))"); autoRedesenho("reinicia"); if(arguments.length == 1) {var titulo = "Aplicar";} if(arguments.length == 1 || arguments.length == 2) {var classe = "i3geoBotaoAplicar";} if (!document.getElementById("i3geo_aplicar")) { var novoel = document.createElement("input"); novoel.id = 'i3geo_aplicar'; novoel.type = 'button'; novoel.value = titulo; novoel.style.cursor="pointer"; novoel.style.fontSize="10px"; novoel.style.zIndex = 15000; novoel.style.position="absolute"; novoel.style.display="none"; novoel.onmouseover = function(){this.style.display="block";}; novoel.onmouseout = function(){this.style.display="none";}; novoel.className = classe; document.body.appendChild(novoel); } else {var novoel = document.getElementById("i3geo_aplicar");} novoel.onclick = function(){ clearTimeout(i3GEO.parametros.tempo); i3GEO.parametros.tempo = ""; this.style.display='none'; eval(nomeFuncao+"\(\)"); }; //reposiciona o botao if(arguments.length == 4){ novoel.style.display="block"; var xy = YAHOO.util.Dom.getXY(obj); YAHOO.util.Dom.setXY(novoel,xy); } return (novoel); }, /* Function: arvore Cria uma árvore com base em um objeto contendo aspropriedades. Parameters: titulo - {String} cabeçaljo da árvore onde - {String} nome do id doelemento que conterá a árvore obj - {Object} objeto contendo os parâmetros, exemplo g_listaPropriedades = { "propriedades": [ { text: "p2", url: "javascript:tipoimagem()" } ]} */ arvore: function(titulo,onde,obj){ //YAHOO.log("arvore", "i3geo"); if(!$i(onde)){return;} var currentIconMode; try{ arvore = new YAHOO.widget.TreeView(onde); root = arvore.getRoot(); var tempNode = new YAHOO.widget.TextNode('', root, false); tempNode.isLeaf = false; tempNode.enableHighlight = false; } catch(e){} var titulo = "
"+titulo+"
"; var d = {html:titulo}; var tempNode = new YAHOO.widget.HTMLNode(d, root, true,true); tempNode.enableHighlight = false; var c = obj.propriedades.length; for (var i=0, j=c; i"+$trad(linha.text)+""; var d = {html:conteudo}; var temaNode = new YAHOO.widget.HTMLNode(d, tempNode, false,true); temaNode.enableHighlight = false; } arvore.collapseAll(); arvore.draw(); //YAHOO.log("Fim arvore", "i3geo"); }, /* Function: removeAcentos Remove acentos de uma palavra ou frase Parameters: palavra {String} Return: {String} */ removeAcentos: function(palavra) { var re = /ã|á|à|â/gi; palavra = palavra.replace(re,"a"); var re = /é/gi; palavra = palavra.replace(re,"e"); var re = /í/gi; palavra = palavra.replace(re,"i"); var re = /ó|õ/gi; palavra = palavra.replace(re,"o"); var re = /ç/gi; palavra = palavra.replace(re,"c"); var re = /ú/gi; palavra = palavra.replace(re,"u"); return(palavra); }, /* Function protocolo Obtém o protocoloutilizado na URL atual Return: {String} - protocolo */ protocolo: function(){ var u = window.location.href; var u = u.split(":"); return (u[0]); }, /* Function: pegaPosicaoObjeto Retorna a posição x,y de um objeto em relação a tela do navegador Parameters: obj {Object} - objeto dom Return: {Array} - array com a posição [x,y] */ pegaPosicaoObjeto: function(obj){ if(obj) { if(!obj.style) {return [0,0];} if(obj.style.position == "absolute") {return [(parseInt(obj.style.left)),(parseInt(obj.style.top))];} else{ var curleft = curtop = 0; if(obj){ if (obj.offsetParent) { do { curleft += obj.offsetLeft-obj.scrollLeft; curtop += obj.offsetTop-obj.scrollTop; } while (obj = obj.offsetParent); } } return [curleft+document.body.scrollLeft,curtop+document.body.scrollTop]; } } else {return [0,0];} }, /* Function: pegaElementoPai Pega o elemento pai de um elemento clicado para identificar o código do tema. Parameters: e - elemento do DOM. Return: {Node} - objeto DOM */ pegaElementoPai: function(e){ var targ; if (!e) {var e = window.event;} if (e.target) {targ = e.target;} else if (e.srcElement) {targ = e.srcElement;} if (targ.nodeType == 3) {targ = targ.parentNode;} var tname; tparent=targ.parentNode; return(tparent); }, /* Function: mudaCursor Altera o cursor do ponteiro do mouse. Os cursores disponíveis são definidos por default em classe_configura.js Parameters: cursores {i3GEO.configura.cursores} - objeto JSON com as URIs de cada cursor (veja i3GEO.configura.cursores) tipo {String} - tipo de cursor disponível em cursores idobjeto {String} - id do objeto que terá o estilo alterado para o cursor desejado locaplic {String} - onde está instalado o i3Geo */ mudaCursor: function(cursores,tipo,idobjeto,locaplic){ var o = document.getElementById(idobjeto); var c = eval("cursores."+tipo+".ie"); if(c == "default" || c == "pointer" || c == "crosshair" || c == "help" || c == "move" || c == "text") o.style.cursor = c; else{ if(o){ if(navm){ o.style.cursor = "URL(\""+locaplic+eval("cursores."+tipo+".ie")+"\"),auto"; } else{ o.style.cursor = "URL(\""+locaplic+eval("cursores."+tipo+".ff")+"\"),auto"; } } } }, /* Function: criaBox Cria um elemento div na página atual. Esse elemento pode ser utilizado para desenhar retângulos sobre o mapa Parameters: id {String} - id do elemento que será criado. Por default, será 'boxg' */ criaBox: function(id){ if(arguments.length == 0) {var id = "boxg"} if (!$i(id)) { var novoel = document.createElement("div"); novoel.id = id; novoel.style.zIndex=1; novoel.innerHTML = ''; document.body.appendChild(novoel); novoel.onmouseover = function(){novoel.style.display='none';}; novoel.onmouseout = function(){novoel.style.display='block';}; i3GEO.util.BOXES.push(id); } else $i(id).style.display="block"; }, /* Function: escondeBox Esconde os BOXES com IDs registrados em i3GEO.util.BOXES Os ids são criado pela função criaBox */ escondeBox: function(){ var l = i3GEO.util.BOXES.length; for (i=0; i"; return i; }, /* Function: $top ou nome curto $top Muda a posição (superior) de um objeto tanto no IE como no Firefox. Exemplo: $top("imagem",100) Parâmetros: id - identificador do objeto valor - posição em relação ao topo. */ $top: function(id,valor){ if (document.getElementById(id).style){ if (document.getElementById(id).style.pixelTop) {document.getElementById(id).style.pixelTop=valor;} else {document.getElementById(id).style.top=valor+"px";} } }, /* Function: $left ou nome curto $left Muda a posição (esquerda) de um objeto tanto no IE como no Firefox. Exemplo: $left("imagem",100) Parâmetros: id - identificador do objeto valor - posição em relação a esquerda. */ $left: function(id,valor){ if (document.getElementById(id).style){ if (document.getElementById(id).style.pixelLeft) {document.getElementById(id).style.pixelLeft=valor;} else {document.getElementById(id).style.left=valor+"px";} } }, /* Function: insereMarca Insere ou remove pontos no mapa. */ insereMarca:{ /* Variable: CONTAINER Armazena o valor do ID do div criado para inserir pontos Type: {Array} */ CONTAINER: new Array(), /* Function: cria Insere um ponto no mapa Os pontos são inseridos em um contaier de pontos e mostrados temporáriamente Parameters: xi {Numeric} - coordenada x. yi {Numeric} - coordenada y. funcaoOnclick {String} - funcao que sera executada quando a marca for clicada, se for "", o container será esvaziado ao ser clicado na marca container {String} - id do container que receberá os pontos */ cria:function(xi,yi,funcaoOnclick,container){ try{ if(i3GEO.util.insereMarca.CONTAINER.toString().search(container) < 0) i3GEO.util.insereMarca.CONTAINER.push(container); //verifica se existe o container para os pontos if (!$i(container)){ var novoel = document.createElement("div"); novoel.id = container; var i = novoel.style; i.position = "absolute"; i.top = parseInt($i(i3GEO.interface.IDCORPO).style.top); i.left = parseInt($i(i3GEO.interface.IDCORPO).style.left); document.body.appendChild(novoel); } var container = $i(container); var novoel = document.createElement("div"); var i = novoel.style; i.position = "absolute"; i.zIndex=2000; i.top=(yi - 4)+"px"; i.left=(xi - 4)+"px"; i.width="4px"; i.height="4px"; var novoimg = document.createElement("img"); if (funcaoOnclick != "") {novoimg.onclick = funcaoOnclick;} else {novoimg.onclick=function(){i3GEO.util.insereMarca.limpa();}} novoimg.src=i3GEO.configura.locaplic+"/imagens/dot1.gif"; with (novoimg.style){width="6px";height="6px";zIndex=2000;} novoel.appendChild(novoimg); container.appendChild(novoel); if(i3GEO.eventos.NAVEGAMAPA.toString().search("i3GEO.util.insereMarca.limpa()") < 0) {i3GEO.eventos.NAVEGAMAPA.push("i3GEO.util.insereMarca.limpa()");} } catch(e){alert("Ocorreu um erro. inseremarca"+e);} }, limpa: function(){ try{ var n = i3GEO.util.insereMarca.CONTAINER.length; for(i=0;i 0){ var tempoFade = setTimeout(fade, tempo); } else{ clearTimeout(tempoFade); obj.style.display = "none"; if (navm) {obj.style.filter='alpha(opacity=100)';} else {obj.style.opacity= 1;} if(removeobj){ var p = obj.parentNode; if(p) p.removeChild(obj); } } }; var tempoFade = setTimeout(fade, tempo); }, /* Function: wkt2ext Calcula a extensão geográfica de uma geometria fornecida no formato WKT Parameters: wkt {String} - geometria no formato wkt tipo {String} - tipo de geometria (polygon,point,line) Return: {String} - extensão geográfica (xmin ymin xmax ymax) */ wkt2ext:function(wkt,tipo){ var tipo = tipo.toLowerCase(); ext = false; if(tipo == "polygon"){ try{ var re = new RegExp("POLYGON", "g"); var wkt = wkt.replace(re,""); var wkt = wkt.split("(")[2].split(")")[0]; var wkt = wkt.split(","); var x = new Array(); var y = new Array(); for (w=0;w