classe_barradebotoes.js
13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
/*
Title: Barra de botões
File: i3geo/classesjs/classe_barradebotoes.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();
}
/*
Class: i3GEO.barradebotoes
Constrói a barra de botões flutuante
*/
i3GEO.barraDeBotoes = {
/*
Variable: BARRAS
Array com os objetos YAHOO.janelaBotoes.xp.panel criados
*/
BARRAS: new Array(),
/*
Property: PERMITEFECHAR
Mostra o botão para fechar as barras ou não.
Type:
{boolean}
*/
PERMITEFECHAR: true,
/*
Property: PERMITEDESLOCAR
Permite deslocar as barras ou não.
Type:
{boolean}
*/
PERMITEDESLOCAR: true,
/*
Property: LISTABOTOES
Objeto com a lista de botões.
Por default utiliza os botoes definidos em i3GEO.configura.funcoesBotoes.botoes
Type:
{JSON}
*/
LISTABOTOES: i3GEO.configura.funcoesBotoes.botoes,
/*
Property: BOTAOPADRAO
Botão que será ativado ao inicializar os botões com ativaBotoes.
Correpsonde ao item iddiv de LISTABOTOES
Type:
{String}
*/
BOTAOPADRAO: "pan",
/*
Variable: BOTAOCLICADO
Último icone que foi clicado
Type:
{String}
*/
BOTAOCLICADO: "",
/*
Function: ativaIcone
Altera as bordas de um ícone aplicando um efeito de ícone realçado.
Todos os demais ícones definidos em LISTABOTOES e que tiverem o tipo = "dinamico"
serão processados para alterar as bordas dando o efeito de não ativo.
Parameters:
icone {String} - id do icone que será ativado. Esse id é o mesmo definido em LISTABOTOES
*/
ativaIcone: function(icone){
i3GEO.barraDeBotoes.BOTAOCLICADO = icone;
//desativa todos os ícones
var ko = i3GEO.barraDeBotoes.LISTABOTOES.length-1;
if(ko >= 0)
{
do
{
var temp = $i(i3GEO.barraDeBotoes.LISTABOTOES[ko].iddiv);
if (i3GEO.barraDeBotoes.LISTABOTOES[ko].tipo=="dinamico" && temp)
{
var ist = temp.style;
ist.borderWidth="1px";
ist.borderColor='white';
ist.borderLeftColor='rgb(50,50,50)';
ist.borderBottomColor='rgb(50,50,50)';
}
}
while(ko--)
}
//ativa o icone
if($i(icone))
{with ($i(icone).style){
borderColor='white';
borderWidth="1px";
}}
},
/*
Function: ativaBotoes
Ativa os botoes definidos em LISTABOTOES
Os botoes são construídos e as funções definidas são embutidas no evento onclick
Parameters:
padrao (String} - botao que será mostrado como ativo (opcional).
Se não for definido, será utilizado o botão especificado em BOTAOPADRAO.
O nome do botao deve estar em LISTABOTOES na propriedade iddiv
*/
ativaBotoes:function(padrao){
if(arguments.length == 0)
{var padrao = i3GEO.barraDeBotoes.BOTAOPADRAO;}
i3GEO.barraDeBotoes.BOTAOCLICADO = padrao;
var l = i3GEO.barraDeBotoes.LISTABOTOES;
var b = l.length-1;
if (b >= 0){
do{
if ($i(l[b].iddiv)){
if(l[b].conteudo)
{eval('$i(l[b].iddiv).innerHTML = "'+l[b].conteudo+'"');}
if(l[b].dica){
eval('$i("'+l[b].iddiv+'").onmouseover = function(){i3GEO.ajuda.mostraJanela("'+l[b].dica+'","");}');
eval('$i("'+l[b].iddiv+'").onmouseout = function(){i3GEO.ajuda.mostraJanela("");};');
}
if(l[b].funcaoonclick){
$i(l[b].iddiv).onclick = l[b].funcaoonclick;
if(l[b].iddiv == padrao)
{l[b].funcaoonclick();}
}
if(l[b].constroiconteudo)
{eval(l[b].constroiconteudo);}
}
}
while (b--);
}
},
ativaBarraDeZoom: function(){
$i("vertMaisZoom").onmouseover = function(){
i3GEO.ajuda.mostraJanela('Amplia o mapa mantendo o centro atual.');
};
$i("vertMaisZoom").onclick = function(){
$i("vertHandleDivZoom").onmousedown.call();
g_fatordezoom = 0;
$i("vertHandleDivZoom").onmousemove.call();
g_fatordezoom = -1;
$i("vertHandleDivZoom").onmousemove.call();
i3GEO.barraDeBotoes.BOTAOCLICADO = 'zoomin';
i3GEO.navega.zoomin();
g_fatordezoom = 0;
};
$i("vertMenosZoom").onmouseover = function(){
i3GEO.ajuda.mostraJanela('Reduz o mapa mantendo o centro atual.');
};
$i("vertMenosZoom").onclick = function(){
$i("vertHandleDivZoom").onmousedown.call();
g_fatordezoom = 0;
$i("vertHandleDivZoom").onmousemove.call();
g_fatordezoom = 1;
$i("vertHandleDivZoom").onmousemove.call();
i3GEO.barraDeBotoes.BOTAOCLICADO = 'zoomout';
i3GEO.navega.zoomout();
g_fatordezoom = 0;
};
},
/*
Function: inicializaBarra
Inicializa a barra de botões
Exemplo:
if ($i("barraDeBotoes1"))
i3GEO.barraDeBotoes.inicializaBarra("barraDeBotoes1","i3geo_barra1",true,x1,y1);
if ($i("barraDeBotoes2"))
i3GEO.barraDeBotoes.inicializaBarra("barraDeBotoes2","i3geo_barra2",false,x2,y2);
Os objetos criados são armazenados no array BARRAS, dessa forma, para acessar uma barra utilize
por exemplo:
i3GEO.barraDeBotoes.BARRAS[1].show();
Parameters:
idconteudo {String} - id do elemento existente no HTML e que contém as definições dos botões
idconteudonovo {String} - id do elemento que será criado para adicionar os botoões
barraZoom {boolean} - indica se a barra de zoom será incluída
x {Numeric} - posição x (pixels) da barra em relação ao mapa
y {Numeric} - posição y (pixels) da barra em relação ao mapa
*/
inicializaBarra:function(idconteudo,idconteudonovo,barraZoom,x,y){
var wj = "36px";
var recuo = "0px";
var novoel = document.createElement("div");
novoel.id = idconteudonovo;
novoel.style.display="block";
novoel.style.border="1px solid gray";
novoel.style.background="white";
if (navm)
{novoel.style.filter='alpha(opacity=90)';}
else
{novoel.style.opacity= .85;}
//var temp = '<div class="hd" > </div>';
//temp += '<div class="bd" style="background-color:rgb(250,250,250);width='+wj+'px" >';
var temp = "";
if (barraZoom == true)
{
if (navn){temp += '<div style="text-align:center;position:relative;left:9px" >';}
temp += '<div id="vertMaisZoom" ></div><div id="vertBGDiv" name="vertBGDiv" tabindex="0" x2:role="role:slider" state:valuenow="0" state:valuemin="0" state:valuemax="200" title="Zoom" >';
temp += '<div id="vertHandleDivZoom" ><img alt="" class="slider" src="'+i3GEO.util.$im("branco.gif")+'" /></div></div>';
temp += '<div id=vertMenosZoom ></div>';
if (navn){temp += '</div>';}
}
temp += '<div id="'+idconteudonovo+'_" style="left:'+recuo+';top:-6px;" ></div></div>';
novoel.innerHTML = temp;
//necessário para impedir o desenho da rosa dos ventos
novoel.onmouseover = function(){
//objposicaocursor.imgx = 0;
if($i("i3geo_rosa"))
{$i("i3geo_rosa").style.display="none";}
};
document.body.appendChild(novoel);
//copia os botoes do HTML para a janela
if ($i(idconteudo))
{
$i(idconteudonovo+"_").innerHTML = $i(idconteudo).innerHTML;
$i(idconteudo).innerHTML = "";
}
YAHOO.namespace("janelaBotoes.xp");
YAHOO.janelaBotoes.xp.panel = new YAHOO.widget.Panel(idconteudonovo, {width:wj, fixedcenter: false, constraintoviewport: false, underlay:"none", close:i3GEO.barraDeBotoes.PERMITEFECHAR, visible:true, draggable:i3GEO.barraDeBotoes.PERMITEDESLOCAR, modal:false } );
if((barraZoom == true) && $i("img")){
i3GEO.barraDeBotoes.ativaBarraDeZoom();
verticalSlider = YAHOO.widget.Slider.getVertSlider("vertBGDiv","vertHandleDivZoom", 0, 70);
verticalSlider.onChange = function(offsetFromStart)
{g_fatordezoom = (offsetFromStart - 35) / 5;};
verticalSlider.setValue(35,true);
if ($i("vertBGDiv")){
$i("vertBGDiv").onmouseup = function(){
i3GEO.navega.aplicaEscala(i3GEO.configura.locaplic,i3GEO.configura.sid,i3geo_ns)
g_fatordezoom = 0;
verticalSlider.setValue(35,true);
};
}
if($i("vertHandleDivZoom")){
$i("vertHandleDivZoom").onmousedown = function(){
i3GEO.barraDeBotoes.BOTAOCLICADO='slidezoom';
if (!$i("imgtemp")){
iclone=document.createElement('IMG');
iclone.style.position = "absolute";
iclone.id = "imgtemp";
iclone.style.border="1px solid blue";
$i("img").parentNode.appendChild(iclone);
}
var iclone = $i("imgtemp");
var corpo = $i("img");
if(!corpo){return;}
iclone.src = corpo.src;
iclone.style.width = i3GEO.parametros.w;
iclone.style.heigth = i3GEO.parametros.h;
iclone.style.top = corpo.style.top;
iclone.style.left = corpo.style.left;
$i("img").style.display = "none";
iclone.style.display = "block";
};
}
if($i("vertHandleDivZoom")){
$i("vertHandleDivZoom").onmousemove = function(){
var iclone = $i("imgtemp");
var corpo = $i("img");
if(!corpo){return;}
var nw = i3GEO.parametros.w;
var nh = i3GEO.parametros.h;
var nt = 0;
var nl = 0;
i3geo_ns = parseInt(i3GEO.parametros.mapscale);
if ((g_fatordezoom > 0) && (g_fatordezoom < 7)){
g_fatordezoom = g_fatordezoom + 1;
var velhoh = parseInt(iclone.style.height);
var velhow = parseInt(iclone.style.width);
var nh = i3GEO.parametros.h / g_fatordezoom;
var nw = i3GEO.parametros.w / g_fatordezoom;
var t = parseInt(iclone.style.top);
var l = parseInt(iclone.style.left);
var nt = t + ((velhoh - nh)*.5);
var nl = l + ((velhow - nw)*.5);
var fatorEscala = nh/i3GEO.parametros.h;
i3geo_ns=parseInt(i3GEO.parametros.mapscale / fatorEscala);
}
if ((g_fatordezoom < 0) && (g_fatordezoom > -7)){
g_fatordezoom = g_fatordezoom - 1;
var velhoh = parseInt(iclone.style.height);
var velhow = parseInt(iclone.style.width);
var nh = i3GEO.parametros.h * g_fatordezoom * -1;
var nw = i3GEO.parametros.w * g_fatordezoom * -1;
var t = parseInt(iclone.style.top);
var l = parseInt(iclone.style.left);
var nt = t - ((nh - velhoh)*.5);
var nl = l - ((nw - velhow)*.5);
var fatorEscala = nh/i3GEO.parametros.h;
i3geo_ns=parseInt(i3GEO.parametros.mapscale / fatorEscala);
}
if(iclone){
iclone.style.width = nw;
iclone.style.height = nh;
if (iclone.style.pixelTop)
{iclone.style.pixelTop=nt;}
else
{iclone.style.top=nt+"px";}
if (iclone.style.pixelLeft)
{iclone.style.pixelLeft=nl;}
else
{iclone.style.left=nl+"px";}
}
if ($i("i3geo_escalanum"))
{$i("i3geo_escalanum").value=i3geo_ns;}
};
}
}
YAHOO.janelaBotoes.xp.panel.render();
YAHOO.janelaBotoes.xp.panel.moveTo(x,y);
if($i("sobeferramentas")){
$i("sobeferramentas").onclick = function(){
var elementos = $i(idconteudonovo+"_").getElementsByTagName("div");
if(elementos[0].style.display == "inline")
{return;}
if(elementos.length > 0){
var mostra = elementos[0];
var i = 0;
do{
if(elementos[i].style){
if(elementos[i].style.display == "inline")
{break;}
if(elementos[i].style.display == "none")
{var mostra = elementos[i];}
}
var i = i + 1;
}
while(i < elementos.length)
mostra.style.display="inline";
//esconde o último botao
var i = elementos.length - 1;
var mostra = elementos[i];
do{
if(elementos[i].style){
if(elementos[i].style.display == "inline")
{var mostra = elementos[i];break;}
}
var i = i - 1;
}
while(i >= 0)
mostra.style.display="none";
}
};
}
if($i("desceferramentas")){
$i("desceferramentas").onclick = function(){
var tipo = "inline";
if($i(idconteudonovo+"_")){
var elementos = $i(idconteudonovo+"_").getElementsByTagName("div");
if(elementos[elementos.length - 1].style.display == tipo)
{return;}
if(elementos.length > 0){
//esconde o primeiro botao
var i = 0;
do{
if(elementos[i].style){
if((elementos[i].style.display == "block") || (elementos[i].style.display == "inline") || (elementos[i].style.display == ""))
{elementos[i].style.display="none";break;}
}
var i = i + 1;
}
while(i < elementos.length)
//mostra o último botao
var i = elementos.length-1;
var mostra = elementos[i];
do{
if(elementos[i].style){
if(elementos[i].style.display == tipo)
{break;}
if(elementos[i].style.display == "none")
{var mostra = elementos[i];}
}
var i = i - 1;
}
while(i >= 0)
mostra.style.display=tipo;
}
}
};
}
i3GEO.barraDeBotoes.BARRAS.push(YAHOO.janelaBotoes.xp.panel);
YAHOO.janelaBotoes.xp.panel.show();
},
/*
Function: reativa
Reativa as barras de ferramentas já criadas
Parameters:
indice {Integer} - índice do array BARRAS que guarda os objetos YAHOO com
as barras Se não for definido, todas as barras serão reativadas
*/
reativa: function(indice){
if(arguments.length == 1)
i3GEO.barraDeBotoes.BARRAS[indice].show();
else{
var n = i3GEO.barraDeBotoes.BARRAS.length;
for(i=0;i<n;i++){
i3GEO.barraDeBotoes.BARRAS[i].show();
}
}
}
};
//YAHOO.log("carregou classe barradebotoes", "Classes i3geo");