classe_plugini3geo.js 23.5 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 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
/**
 * Title: PluginI3Geo
 *
 * i3GEO.pluginI3geo
 *
 * Implementa os plugins do i3Geo que adicionam camadas especiais ao mapa,
 * normalmente dados vetoriais processados no navegador Web.
 *
 * Arquivo:
 *
 * i3geo/classesjs/classe_plugini3geo.js
 *
 * Licença:
 *
 * GPL2
 *
 * 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@gmail.com
 *
 * 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;
 *
 * Este programa é distribuído na expectativa de que seja
 * útil, porém, SEM NENHUMA GARANTIA; nem mesmo a garantia
 * implícita de COMERCIABILIDADE OU ADEQUACÃ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') {
	var i3GEO = {};
}
i3GEO.pluginI3geo = {
	OBJETOS : {},
	/**
	 * Lista de plugins
	 *
	 * Utilizado no editor de mapfiles do sistema de administracao
	 */
	PLUGINS : [
			{
				"classe" : "heatmap",
				"nome" : "Mapa de calor",
				"editor" : true
			}, {
				"classe" : "markercluster",
				"nome" : "Agrupamento de pontos (cluster)",
				"editor" : true
			}
	],
	/**
	 * Inicia a execucao de um plugin
	 *
	 * Camada e um objeto gerado pelo i3Geo quando uma camada e adicionada ao
	 * mapa O objeto i3GEO.arvoreDeCamadas.CAMADAS guarda todas as camadas
	 * adicionadas ao mapa Ao adicionar uma camada pelo catalogo, o i3Geo
	 * verifica se a camada possui plugin e direciona para ca Os plugins sao
	 * definidos como metadados em cada mapfile de cada tema
	 *
	 * Veja em i3geo/classesphp/classe_mapa.php funcao parametrostemas
	 */
	inicia : function(camada) {
		if (i3GEO.janela) {
			i3GEO.janela.AGUARDEMODAL = true;
			i3GEO.janela.abreAguarde(
					"aguardePlugin",
					"Plugin...");
			i3GEO.janela.AGUARDEMODAL = false;
		}
		// chama a funcao conforme o tipo de plugin e a interface atual
		// para cada plugin deve haver um objeto com as funcoes especificas
		// para
		// cada interface
		i3GEO.pluginI3geo[camada.plugini3geo.plugin][i3GEO.Interface.ATUAL].inicia(camada);
	},
	/**
	 * Retorna o HTML com o formulario para editar os parametros do plugin
	 */
	formAdmin : function(plugin, configString) {
		return i3GEO.pluginI3geo[plugin].formAdmin(configString);
	},
	linkAjuda : function(plugin) {
		return i3GEO.pluginI3geo[plugin].linkAjuda();
	},
	ligaCamada : function(nomecamada) {
		if (i3GEO.pluginI3geo.OBJETOS[nomecamada]
				&& i3GEO.pluginI3geo.OBJETOS[nomecamada].ligaCamada) {
			i3GEO.pluginI3geo.OBJETOS[nomecamada].ligaCamada();
			return true;
		}
		return false;
	},
	desligaCamada : function(nomecamada) {
		if (i3GEO.pluginI3geo.OBJETOS[nomecamada]
				&& i3GEO.pluginI3geo.OBJETOS[nomecamada].desLigaCamada) {
			i3GEO.pluginI3geo.OBJETOS[nomecamada].desLigaCamada();
			return true;
		}
		return false;
	},
	removeCamada : function(nomecamada) {
		if (i3GEO.pluginI3geo.OBJETOS[nomecamada]
				&& i3GEO.pluginI3geo.OBJETOS[nomecamada].removeCamada) {
			i3GEO.pluginI3geo.OBJETOS[nomecamada].removeCamada();
			delete (i3GEO.pluginI3geo.OBJETOS[nomecamada]);
			return true;
		}
		return false;
	},
	atualizaCamada : function(nomecamada) {
		if (i3GEO.pluginI3geo.OBJETOS[nomecamada]
				&& i3GEO.pluginI3geo.OBJETOS[nomecamada].atualizaCamada) {
			i3GEO.pluginI3geo.OBJETOS[nomecamada].atualizaCamada();
			return true;
		}
		return false;
	},
	existeObjeto : function(nomecamada) {
		if (i3GEO.pluginI3geo.OBJETOS[nomecamada]
				&& i3GEO.pluginI3geo.OBJETOS[nomecamada].atualizaCamada) {
			return true;
		}
		return false;
	},
	/**
	 * Aplica as propriedades em um objeto do tipo tema
	 *
	 * tema e fornecido por i3GEO.arvoreDeCamadas o ajuste das propriedades e
	 * necessario para que as propriedades aparecam de forma correta na arvore
	 * de camadas
	 */
	aplicaPropriedades : function(camada) {
		if (camada.plugini3geo
				&& camada.plugini3geo != "") {
			camada = i3GEO.pluginI3geo[camada.plugini3geo.plugin][i3GEO.Interface.ATUAL].aplicaPropriedades(camada);
		}
		return camada;
	},
	/**
	 * Function: heatmap
	 *
	 * Mapa de calor
	 *
	 * Gera um layer do tipo mapa de calor e adiciona ao mapa
	 *
	 * As dependências em javascript sao carregadas via script tag por
	 * meio de ferramentas/heatmap
	 *
	 * Esse programa também obtém os dados necessários ao
	 * plugin
	 *
	 * O layer existente no mapfile deve conter um metadata chamado PLUGINI3GEO
	 *
	 * Esse matadado deve conter uma string que será transformada em um
	 * objeto javascript para uso no plugin
	 *
	 * Exemplo:
	 *
	 * "PLUGINI3GEO" '{"plugin":"heatmap","parametros":{"tipoGradiente":
	 * "default","coluna":"teste","max":"10","radius":"15"}}'
	 *
	 * Coluna é a que contém os dados numéricos que definem
	 * a quantidade de uma medida em cada ponto e é usada para gerar a
	 * representação. Se for vazia, considera-se o valor como 1
	 *
	 * As cores das classes existentes no LAYER serão utilizadas para
	 * calcular as cores do mapa de calor. Se tipoGradiente for igual a
	 * "default" será utilizado o gradiente padrão.
	 *
	 */
	heatmap : {
		linkAjuda : function() {
			return i3GEO.configura.locaplic
					+ "/ajuda_usuario.php?idcategoria=3&idajuda=121";
		},
		formAdmin : function(config) {
			// {"plugin":"heatmap","parametros":{"coluna":"","radius":15,"max":10}}
			var parametros, ins = "", configDefault = '{"plugin":"heatmap","parametros":{"tipoGradiente": "default","valorPonto":1,"coluna":"","radius":15}}';
			if (config === "") {
				config = configDefault;
			}
			config = YAHOO.lang.JSON.parse(config);
			if (config.plugin != "heatmap") {
				config = YAHOO.lang.JSON.parse(configDefault);
			}
			parametros = config.parametros;
			ins += ""
					+ "<p>Coluna que cont&eacute;m os dados:"
					+ "<br><input name='coluna' type='text' value='"
					+ parametros.coluna
					+ "' size='30'></p>"
					+ "<p>Ou valor num&eacute;rico para cada ponto:"
					+ "<br><input name='valorPonto' type='text' value='"
					+ parametros.valorPonto
					+ "' size='30'></p>"
					+ "<p>Raio de cada ponto em pixels:"
					+ "<br><input name='radius' type='text' value='"
					+ parametros.radius
					+ "' size='30'></p>"
					// + "<p>Valor m&aacute;ximo em cada ponto:"
					// + "<br><input name='max' type='text' value='"
					// + parametros.max
					// + "' size='30'></p>"
					+ "<p>Tipo de gradiente (deixe vazio para utilizar as classes definidas no Layer ou escreva 'default' para usar o normal):"
					+ "<br><input name='tipoGradiente' type='text' value='"
					+ parametros.tipoGradiente
					+ "' size='30'></p>"
					+ "<p>Para definir os cortes no gradiente de cores utilize valores entre 0 e 1."
					+ " As cores s&atilde;o definidas nas classes do LAYER, sendo que o nome define o valor superior do gradiente e COLOR define a cor."
					+ " Veja o exemplo utilizado no tema _lmapadecalor.map</p>";
			return ins;
		},
		googlemaps : {
			aplicaPropriedades : function(camada) {
				camada.sel = "nao";
				camada.download = "nao";
				camada.AGUARDALEGENDA = false;
				camada.temporizador = "";
				camada.copia = false;
				camada.procurar = false;
				camada.toponimia = false;
				camada.etiquetas = false;
				camada.tabela = false;
				camada.grafico = false;
				camada.destacar = false;
				camada.wms = false;
				camada.classe = "NAO";
				return camada;
			},
			inicia : function(camada) {
				var nomeScript = "heatmap_script", p = i3GEO.configura.locaplic
						+ "/ferramentas/heatmap/googlemaps_js.php", carregaJs = "nao", criaLayer;
				criaLayer = function() {
					var heatmap, pontos;

					heatmap = new HeatmapOverlay(i3GeoMap, camada.name, {
						"radius" : camada.plugini3geo.parametros.radius,
						"visible" : true,
						"opacity" : camada.transparency,
						"gradient" : heatmap_config.gradient,
						"legend" : {
							"title" : camada.tema,
							"position" : "bl",
							"offset" : [
									5, 50
							]
						}
					});
					// i3GeoMap.overlayMapTypes.insertAt(0, heatmap);
					pontos = {
						max : camada.plugini3geo.parametros.max,
						data : heatmap_dados
					};
					i3GEO.janela.fechaAguarde("aguardePlugin");
					heatmap.setDataSet(pontos);
					heatmap.ligaCamada = function() {
						this.liga();
					};
					heatmap.desLigaCamada = function() {
						this.desliga();
					};
					heatmap.removeCamada = function() {
						this.destroy();
					};
					heatmap.atualizaCamada = function() {
						this.draw();
					};
					i3GEO.pluginI3geo.OBJETOS[camada.name] = heatmap;
					heatmap_dados = null;
				};
				// se o script nao existir carrega o codigo e os dados
				// caso contrario, carrega apenas os dados no script
				if (!$i(nomeScript)) {
					carregaJs = "sim";
				} else {
					nomeScript = "";
				}
				p += "?carregajs="
						+ carregaJs
						+ "&layer="
						+ camada.name
						+ "&coluna="
						+ camada.plugini3geo.parametros.coluna
						+ "&tipoGradiente="
						+ camada.plugini3geo.parametros.tipoGradiente
						+ "&g_sid="
						+ i3GEO.configura.sid
						+ "&nomevariavel=heatmap_dados&nomevariavelConfig=heatmap_config";
				i3GEO.util.scriptTag(
						p,
						criaLayer,
						nomeScript);
			}
		},
		//
		// O script que adiciona a camada
		// define os eventos visibilitychanged, moveend e removed
		// A camada e adicionada como um objeto layer, permitindo que as funcoes
		// do i3Geo operem normalmente, sem muitas modificacoes
		//
		openlayers : {
			aplicaPropriedades : function(camada) {
				camada.sel = "nao";
				camada.download = "nao";
				camada.AGUARDALEGENDA = false;
				camada.temporizador = "";
				camada.copia = false;
				camada.procurar = false;
				camada.toponimia = false;
				camada.etiquetas = false;
				camada.tabela = false;
				camada.grafico = false;
				camada.destacar = false;
				camada.wms = false;
				camada.classe = "NAO";
				return camada;
			},
			inicia : function(camada, objMapa) {
				var nomeScript = "heatmap_script", p = i3GEO.configura.locaplic
						+ "/ferramentas/heatmap/openlayers_js.php", carregaJs = "nao", criaLayer;
				criaLayer = function() {
					var temp, heatmap, transformedTestData = {
						max : 1,
						data : []
					}, data = heatmap_dados, datalen = heatmap_dados.length, nudata = [], max = 0;

					// para uso com o mashup
					if (!objMapa) {
						objMapa = i3geoOL;
					}
					// in order to use the OpenLayers Heatmap Layer we have
					// to
					// transform our data into
					// { max: <max>, data: [{lonlat: <OpenLayers.LonLat>,
					// count:
					// <count>},...]}
					while (datalen--) {
						temp = heatmap_dados[datalen].count;
						nudata.push({
							lonlat : new OpenLayers.LonLat(data[datalen].lng, heatmap_dados[datalen].lat),
							count : temp
						});
						max = Math.max(
								max,
								temp);
					}
					transformedTestData.max = max;
					transformedTestData.data = nudata;
					// create our heatmap layer
					heatmap = new OpenLayers.Layer.Heatmap(camada.name, objMapa, objMapa.baseLayer, {
						"visible" : true,
						"opacity" : camada.transparency,
						"radius" : camada.plugini3geo.parametros.radius,
						"gradient" : heatmap_config.gradient,
						"legend" : {
							"title" : camada.tema,
							"position" : "bl",
							"offset" : [
									5, 50
							]
						}
					}, {
						isBaseLayer : false,
						projection : new OpenLayers.Projection("EPSG:4326"),
						displayInLayerSwitcher : true
					});
					heatmap.ligaCamada = function() {
						this.toggle();
						this.updateLayer();
					};
					heatmap.desLigaCamada = function() {
						this.toggle();
						this.updateLayer();
					};
					heatmap.removeCamada = function() {
						this.destroy();
					};
					heatmap.atualizaCamada = function() {
						this.updateLayer();
					};

					i3GEO.pluginI3geo.OBJETOS[camada.name] = heatmap;
					objMapa.addLayer(heatmap);
					heatmap.setDataSet(transformedTestData);
					heatmap_dados = null;
					if (i3GEO.janela) {
						i3GEO.janela.fechaAguarde("aguardePlugin");
					}
				};
				// se o script nao existir carrega o codigo e os dados
				// caso contrario, carrega apenas os dados no script
				if (!$i(nomeScript)) {
					carregaJs = "sim";
				} else {
					nomeScript = "";
				}
				if (!i3GEO.configura
						|| !i3GEO.configura.sid) {
					i3GEO.configura.sid = "";
				}
				p += "?carregajs="
						+ carregaJs
						+ "&layer="
						+ camada.name
						+ "&coluna="
						+ camada.plugini3geo.parametros.coluna
						+ "&tipoGradiente="
						+ camada.plugini3geo.parametros.tipoGradiente
						+ "&g_sid="
						+ i3GEO.configura.sid
						+ "&nomevariavel=heatmap_dados&nomevariavelConfig=heatmap_config";
				i3GEO.util.scriptTag(
						p,
						criaLayer,
						nomeScript);
			}
		},
		googleearth : {
			inicia : function() {
				alert("Plugin nao disponivel");
			}
		}
	},
	/**
	 * Function: markercluster
	 *
	 * Markercluster
	 *
	 * Gera um layer que agrupa pontos conforme a dist&acirc;ncia entre eles e
	 * insere um contador adiciona ao mapa
	 *
	 * As depend&ecirc;ncias em javascript sao carregadas via script tag por
	 * meio de ferramentas/markercluster
	 *
	 * Esse programa tamb&eacute;m obt&eacute;m os dados necess&aacute;rios ao
	 * plugin
	 *
	 * O layer existente no mapfile deve conter um metadata chamado PLUGINI3GEO
	 *
	 * Esse matadado deve conter uma string que ser&aacute; transformada em um
	 * objeto javascript para uso no plugin
	 *
	 * Exemplo:
	 *
	 * "PLUGINI3GEO"
	 * '{"plugin":"markercluster","parametros":{"coluna":"teste","gridSize":"50"}}'
	 *
	 * Coluna &eacute; a que cont&eacute;m os dados num&eacute;ricos que definem
	 * a quantidade de uma medida em cada ponto e &eacute; usada para gerar a
	 * representa&ccedil;&atilde;o. Se for vazia, considera-se o valor como 1
	 *
	 */
	markercluster : {
		linkAjuda : function() {
			return i3GEO.configura.locaplic
					+ "/ajuda_usuario.php?idcategoria=3&idajuda=121";
		},
		formAdmin : function(config) {
			var parametros, ins = "", configDefault = '{"plugin":"markercluster","parametros":{"tipoEstilos": "default","gridSize":50}}';
			if (config === "") {
				config = configDefault;
			}
			config = YAHOO.lang.JSON.parse(config);
			if (config.plugin != "markercluster") {
				config = YAHOO.lang.JSON.parse(configDefault);
			}
			parametros = config.parametros;
			ins += ""
					+ "<p>Dist&acirc;ncia m&aacute;xima entre ponto em pixels:"
					+ "<br><input name='gridSize' type='text' value='"
					+ parametros.gridSize
					+ "' size='30'></p>"
					+ "<p>Tipo de estilos (deixe vazio para utilizar as classes definidas no Layer ou escreva 'default' para usar o normal):"
					+ "<br><input name='tipoEstilos' type='text' value='"
					+ parametros.tipoEstilos
					+ "' size='30'></p>"
					+ "<p>Os s&iacute;mbolos utilizados podem ser customizados alterando-se as classes do Mapfile</p>"
					+ "<p>Veja o exemplo utilizado no tema _lmapadecluster.map</p>";

			return ins;
		},
		googlemaps : {
			aplicaPropriedades : function(camada) {
				camada.sel = "nao";
				camada.download = "nao";
				camada.AGUARDALEGENDA = false;
				camada.temporizador = "";
				camada.copia = false;
				camada.procurar = false;
				camada.toponimia = false;
				camada.etiquetas = false;
				camada.tabela = false;
				camada.grafico = false;
				camada.destacar = false;
				camada.wms = false;
				camada.classe = "NAO";
				return camada;
			},
			inicia : function(camada) {
				var nomeScript = "markercluster_script", p = i3GEO.configura.locaplic
						+ "/ferramentas/markercluster/googlemaps_js.php", carregaJs = "nao", criaLayer;
				criaLayer = function() {
					var markercluster, marcas, latLng, marker, n, i;
					n = markercluster_dados.length;
					marcas = [];
					for (i = 0; i < n; i++) {
						latLng = new google.maps.LatLng(markercluster_dados[i].lat, markercluster_dados[i].lng);
						marker = new google.maps.Marker({
							'position' : latLng,
							icon : {
								url : markercluster_config.ponto.url,
								scaledSize : new google.maps.Size(markercluster_config.ponto.width, markercluster_config.ponto.height)
							}
						});
						marcas.push(marker);
					}
					markercluster = new MarkerClusterer(i3GeoMap, marcas, {
						"gridSize" : parseInt(
								camada.plugini3geo.parametros.gridSize,
								10),
						"visible" : true,
						"opacity" : camada.transparency,
						"name" : camada.name,
						"styles" : markercluster_config.estilos
					});
					i3GEO.janela.fechaAguarde("aguardePlugin");
					i3GEO.eventos.cliquePerm.ativo = false;

					markercluster.ligaCamada = function() {
						i3GEO.pluginI3geo.OBJETOS[camada.name].ready_ = true;
						i3GEO.pluginI3geo.OBJETOS[camada.name].redraw();
						i3GEO.eventos.cliquePerm.ativo = false;
					};
					markercluster.desLigaCamada = function() {
						i3GEO.pluginI3geo.OBJETOS[camada.name].resetViewport(true);
						i3GEO.pluginI3geo.OBJETOS[camada.name].ready_ = false;
						i3GEO.eventos.cliquePerm.ativo = true;
					};
					markercluster.removeCamada = function() {
						i3GEO.pluginI3geo.OBJETOS[camada.name].clearMarkers();
						i3GEO.eventos.cliquePerm.ativo = true;
					};
					markercluster.atualizaCamada = function() {
						i3GEO.pluginI3geo.OBJETOS[camada.name].ready_ = true;
						i3GEO.pluginI3geo.OBJETOS[camada.name].redraw();
						i3GEO.eventos.cliquePerm.ativo = false;
					};
					i3GEO.pluginI3geo.OBJETOS[camada.name] = markercluster;
					markercluster_dados = null;
				};
				// se o script nao existir carrega o codigo e os dados
				// caso contrario, carrega apenas os dados no script
				if (!$i(nomeScript)) {
					carregaJs = "sim";
				} else {
					nomeScript = "";
				}
				p += "?carregajs="
						+ carregaJs
						+ "&layer="
						+ camada.name
						+ "&g_sid="
						+ i3GEO.configura.sid
						+ "&tipoEstilos="
						+ camada.plugini3geo.parametros.tipoEstilos
						+ "&nomevariavel=markercluster_dados&nomevariavelConfig=markercluster_config";
				i3GEO.util.scriptTag(
						p,
						criaLayer,
						nomeScript);
			}
		},
		openlayers : {
			aplicaPropriedades : function(camada) {
				camada.sel = "nao";
				camada.download = "nao";
				camada.AGUARDALEGENDA = false;
				camada.temporizador = "";
				camada.copia = false;
				camada.procurar = false;
				camada.toponimia = false;
				camada.etiquetas = false;
				camada.tabela = false;
				camada.grafico = false;
				camada.destacar = false;
				camada.wms = false;
				camada.classe = "NAO";
				return camada;
			},
			inicia : function(camada, objMapa) {
				var nomeScript = "markercluster_script", p = i3GEO.configura.locaplic
						+ "/ferramentas/markercluster/openlayers_js.php", carregaJs = "nao", criaLayer;
				criaLayer = function() {
					var layerListeners, logMax, logMin, classes, min, max, markercluster, marcas, lonlat, n, i, style, nestilos, intervalo, regra, regras = [];

					nestilos = markercluster_config.estilos.length;
					n = markercluster_dados.length;

					classes = Array();
					logMax = Math.log(n)
							/ Math.LN10; // max decimal logarithm (or base
											// 10)
					logMin = Math.log(1)
							/ Math.LN10;
					intervalo = (logMax - logMin)
							/ nestilos;
					// we compute log bounds
					for (i = 0; i < nestilos; i++) {
						if (i == 0) {
							classes[i] = logMin;
						} else {
							classes[i] = classes[i - 1]
									+ intervalo;
						}
					}
					// we compute antilog
					classes = classes.map(function(x) {
						return Math.pow(
								10,
								x);
					});
					// and we finally add max value
					classes.push(n);

					// ponto sozinho
					regra = new OpenLayers.Rule({
						filter : new OpenLayers.Filter.Comparison({
							type : OpenLayers.Filter.Comparison.LESS_THAN,
							property : "count",
							value : 2
						}),
						symbolizer : {
							externalGraphic : markercluster_config.ponto.url,
							graphicWidth : markercluster_config.ponto.width,
							graphicHeight : markercluster_config.ponto.height,
							graphicYOffset : (markercluster_config.ponto.height / 2)
									* -1
						}
					});
					regras.push(regra);
					min = 2;
					for (i = 0; i < nestilos; i++) {
						max = classes[i + 1];
						regra = new OpenLayers.Rule({
							filter : new OpenLayers.Filter.Comparison({
								type : OpenLayers.Filter.Comparison.BETWEEN,
								property : "count",
								lowerBoundary : min,
								upperBoundary : max
							}),
							symbolizer : {
								externalGraphic : markercluster_config.estilos[i].url,
								graphicWidth : markercluster_config.estilos[i].width,
								graphicHeight : markercluster_config.estilos[i].height,
								label : "${count}",
								labelOutlineWidth : 1,
								fontColor : "#000000",
								fontOpacity : 1,
								fontSize : "12px"
							}
						});
						regras.push(regra);
						min = max;
					}

					// Create a Style that uses the three previous rules
					style = new OpenLayers.Style(null, {
						rules : regras
					});
					// para uso com o mashup
					if (!objMapa) {
						objMapa = i3geoOL;
					}

					layerListeners = {
						featureclick : function(e) {
							if (e.feature.cluster.length > 1) {
								objMapa.setCenter([e.feature.geometry.x,e.feature.geometry.y],objMapa.getZoom() + 1,false,false);
								//objMapa.zoomIn();
							}
							return false;
						}
					};

					markercluster = new OpenLayers.Layer.Vector(camada.name, {
						renderers : [
								'Canvas', 'SVG'
						],
						strategies : [
							new OpenLayers.Strategy.AnimatedCluster({
								distance : parseInt(
										camada.plugini3geo.parametros.gridSize,
										10)
							})
						],
						styleMap : new OpenLayers.StyleMap(style),
						eventListeners : layerListeners
					});
					objMapa.addLayer(markercluster);

					marcas = [];
					for (i = 0; i < n; i++) {
						lonlat = new OpenLayers.LonLat(markercluster_dados[i].lng, markercluster_dados[i].lat);
						if (i3GEO.Interface.openlayers.googleLike === true) {
							lonlat.transform(
									new OpenLayers.Projection("EPSG:4326"),
									new OpenLayers.Projection("EPSG:900913"));
						}
						marcas.push(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)));
					}
					markercluster.addFeatures(marcas);

					i3GEO.janela.fechaAguarde("aguardePlugin");
					i3GEO.eventos.cliquePerm.ativo = false;

					markercluster.ligaCamada = function() {
						i3GEO.eventos.cliquePerm.ativo = false;
					};
					markercluster.desLigaCamada = function() {
						i3GEO.eventos.cliquePerm.ativo = true;
					};
					markercluster.removeCamada = function() {
						i3GEO.eventos.cliquePerm.ativo = true;
					};
					markercluster.atualizaCamada = function() {
						i3GEO.eventos.cliquePerm.ativo = false;
					};
					i3GEO.pluginI3geo.OBJETOS[camada.name] = markercluster;
					markercluster_dados = null;
				};
				// se o script nao existir carrega o codigo e os dados
				// caso contrario, carrega apenas os dados no script
				if (!$i(nomeScript)) {
					carregaJs = "sim";
				} else {
					nomeScript = "";
				}
				p += "?carregajs="
						+ carregaJs
						+ "&layer="
						+ camada.name
						+ "&g_sid="
						+ i3GEO.configura.sid
						+ "&tipoEstilos="
						+ camada.plugini3geo.parametros.tipoEstilos
						+ "&nomevariavel=markercluster_dados&nomevariavelConfig=markercluster_config";
				i3GEO.util.scriptTag(
						p,
						criaLayer,
						nomeScript);
			}
		}
	}
};