diff --git a/classesjs/classe_plugini3geo.js b/classesjs/classe_plugini3geo.js index 9d35545..4f15463 100644 --- a/classesjs/classe_plugini3geo.js +++ b/classesjs/classe_plugini3geo.js @@ -1,25 +1,25 @@ /** * 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 @@ -34,7 +34,7 @@ i3GEO.pluginI3geo = OBJETOS : {}, /** * Lista de plugins - * + * * Utilizado no editor de mapfiles do sistema de administracao */ PLUGINS : [ @@ -51,11 +51,11 @@ i3GEO.pluginI3geo = ], /** * 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) { @@ -116,7 +116,7 @@ i3GEO.pluginI3geo = }, /** * 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 */ @@ -128,29 +128,29 @@ i3GEO.pluginI3geo = }, /** * 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() { @@ -209,7 +209,8 @@ i3GEO.pluginI3geo = return camada; }, inicia : function(camada) { - var nomeScript = "heatmap_script", p = i3GEO.configura.locaplic + "/ferramentas/heatmap/googlemaps_js.php", carregaJs = "nao", criaLayer; + var nomeScript = "heatmap_script", p = i3GEO.configura.locaplic + "/ferramentas/heatmap/googlemaps_js.php", carregaJs = + "nao", criaLayer; criaLayer = function() { var heatmap, pontos; @@ -249,12 +250,11 @@ i3GEO.pluginI3geo = 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 + // 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{ + } else { nomeScript = ""; } p += @@ -288,7 +288,8 @@ i3GEO.pluginI3geo = return camada; }, inicia : function(camada, objMapa) { - var nomeScript = "heatmap_script", p = i3GEO.configura.locaplic + "/ferramentas/heatmap/openlayers_js.php", carregaJs = "nao", criaLayer; + var nomeScript = "heatmap_script", p = i3GEO.configura.locaplic + "/ferramentas/heatmap/openlayers_js.php", carregaJs = + "nao", criaLayer; criaLayer = function() { var heatmap, transformedTestData = { max : camada.plugini3geo.parametros.max, @@ -354,12 +355,11 @@ i3GEO.pluginI3geo = i3GEO.janela.fechaAguarde("aguardePlugin"); } }; - //se o script nao existir carrega o codigo e os dados - //caso contrario, carrega apenas os dados no script + // 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{ + } else { nomeScript = ""; } if (!i3GEO.configura || !i3GEO.configura.sid) { @@ -380,33 +380,34 @@ i3GEO.pluginI3geo = }, /** * Function: markercluster - * + * * Markercluster - * + * * Gera um layer que agrupa pontos conforme a distância entre eles e insere um contador adiciona ao mapa - * + * * As dependências em javascript sao carregadas via script tag por meio de ferramentas/markercluster - * + * * 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":"markercluster","parametros":{"coluna":"teste","gridSize":"50"}}' - * + * * 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 - * + * */ 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}}'; + var parametros, ins = "", configDefault = + '{"plugin":"markercluster","parametros":{"tipoEstilos": "default","gridSize":50}}'; if (config === "") { config = configDefault; } @@ -416,12 +417,13 @@ i3GEO.pluginI3geo = } parametros = config.parametros; ins += - "" + "

Distância máxima entre ponto em pixels:" + "

" - + "

Tipo de estilos (deixe vazio para utilizar as classes definidas no Layer ou escreva 'default' para usar o normal):" - + "

" + + "

Tipo de estilos (deixe vazio para utilizar as classes definidas no Layer ou escreva 'default' para usar o normal):" + + "

" + "

Os símbolos utilizados podem ser customizados alterando-se as classes do Mapfile

" + "

Veja o exemplo utilizado no tema _lmapadecluster.map

"; @@ -445,7 +447,8 @@ i3GEO.pluginI3geo = return camada; }, inicia : function(camada) { - var nomeScript = "markercluster_script", p = i3GEO.configura.locaplic + "/ferramentas/markercluster/googlemaps_js.php", carregaJs = "nao", criaLayer; + 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; @@ -493,19 +496,17 @@ i3GEO.pluginI3geo = 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 + // 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{ + } else { nomeScript = ""; } p += - "?carregajs=" + carregaJs + "&layer=" + camada.name + "&coluna=" + camada.plugini3geo.parametros.coluna - + "&g_sid=" + i3GEO.configura.sid - + "&tipoEstilos=" + camada.plugini3geo.parametros.tipoEstilos - + "&nomevariavel=markercluster_dados&nomevariavelConfig=markercluster_config"; + "?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); } }, @@ -526,68 +527,138 @@ i3GEO.pluginI3geo = camada.classe = "NAO"; return camada; }, - inicia : function(camada) { - var nomeScript = "markercluster_script", p = i3GEO.configura.locaplic + "/ferramentas/markercluster/openlayers_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) + inicia : function(camada, objMapa) { + var nomeScript = "markercluster_script", p = i3GEO.configura.locaplic + "/ferramentas/markercluster/openlayers_js.php", carregaJs = + "nao", criaLayer; + criaLayer = + function() { + var 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); }); - 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; + // and we finally add max value + classes.push(n); - 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(); + // 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 + } + }); + 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 + }); + + 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) + }); + // para uso com o mashup + if (!objMapa) { + objMapa = i3geoOL; + } + 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; }; - 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 + // 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{ + } else { nomeScript = ""; } p += - "?carregajs=" + carregaJs + "&layer=" + camada.name + "&coluna=" + camada.plugini3geo.parametros.coluna - + "&g_sid=" + i3GEO.configura.sid - + "&tipoEstilos=" + camada.plugini3geo.parametros.tipoEstilos - + "&nomevariavel=markercluster_dados&nomevariavelConfig=markercluster_config"; + "?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); } } -- libgit2 0.21.2