/** * Title: Desenho * * Funções compartilhadas pelas operações de desenho de elementos gráficos * * Funcoes de uso geral para desenho de elementos gráficos. * * As funções dependem de cada interface em uso no mapa. * * Aqui estao apenas as funcoes de uso compartilhado. Para mais informacoes veja * as opcoes nos editores vetoriais específicos de cada interface * * Namespace: * * i3GEO.desenho * * Veja: * * * */ /** * 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.desenho = { /** * Constant: layergrafico * * Objeto LAYER para a interface OpenLayers criado com i3GEO.desenho.openlayers.criaLayerGrafico * * Tipo: * * {OpenLayers.Layer.Vector} * */ layergrafico : null, /** * Propriedade: estilos * * Estilos que podem ser utilizados para desenhar os elementos * * Tipo: * * {objeto} */ estilos : { "normal" : { fillcolor : '#ffffff', linecolor : '#000000', linewidth : '2', circcolor : '#ffffff', textcolor : '#787A78' }, "palido" : { fillcolor : '#B5A8A8', linecolor : '#BAA4AE', linewidth : '1', circcolor : '#E0D7DC', textcolor : '#787A78' }, "vermelho" : { fillcolor : '#E8ACAC', linecolor : '#F50707', linewidth : '1', circcolor : '#F09EA6', textcolor : '#787A78' }, "verde" : { fillcolor : '#3CCC2F', linecolor : '#0C6642', linewidth : '1', circcolor : '#C7D9D2', textcolor : '#787A78' } }, // @TODO remover apos refatorar codigo estilosOld : { "normal" : { fillcolor : 'red', linecolor : 'black', linewidth : '1', circcolor : 'white', textcolor : 'gray' }, "palido" : { fillcolor : 'gray', linecolor : 'gray', linewidth : '1', circcolor : 'gray', textcolor : 'gray' }, "vermelho" : { fillcolor : 'gray', linecolor : 'red', linewidth : '1', circcolor : 'pink', textcolor : 'brown' }, "verde" : { fillcolor : 'gray', linecolor : 'green', linewidth : '1', circcolor : 'DarkGreen', textcolor : 'GreenYellow' } }, /** * Propriedade: estiloPadrao * * Estilo utilizado como padrão */ estiloPadrao : "normal", /** * Cria uma caixa de seleção para escolha do estilo a ser utilizado */ caixaEstilos : function() { var lista = i3GEO.util.listaChaves(i3GEO.desenho.estilos), n = lista.length, i, caixa, sel; caixa = ""; return caixa; }, definePadrao : function(valor){ i3GEO.desenho.estiloPadrao = valor; }, /** * Function: addBox * * Adiciona um retangulo * * Parameter: * * {numeric} - novo xmin * * {numeric} - novo ymin * * {numeric} - novo xmax * * {numeric} - novo ymax * * {string} - namespace que identifica o elemento grafico, permitindo busca * * {string} - cor do contorno * * {string} - expessura do contorno */ addBox : function(xmin, ymin, xmax, ymax, namespace, strokeColor, strokeWidth) { return i3GEO.desenho[i3GEO.Interface.ATUAL].addBox(xmin, ymin, xmax, ymax, namespace, strokeColor, strokeWidth); }, /** * Function: moveBox * * Reposiciona um retangulo * * Parameter: * * {object} - box * * {numeric} - novo xmin * * {numeric} - novo ymin * * {numeric} - novo xmax * * {numeric} - novo ymax */ moveBox : function(box, xmin, ymin, xmax, ymax) { return i3GEO.desenho[i3GEO.Interface.ATUAL].moveBox(box, xmin, ymin, xmax, ymax); }, /** * Function: removeBox * * Remove box do mapa (apenas alias para removePins) * * Parameter: * * {string} - namespace que identifica o grupo de marcas que serao removidas */ removeBox : function(namespace) { i3GEO.desenho.removePins(namespace); }, /** * Function: addPin * * Adiciona uma marca no mapa em uma determinada coordenada * * Parameters: * * {numeric} - longitude * * {numeric} - latitude * * {numeric} - largura da imagem * * {numeric} - altura da imagem * * {string} - namespace utilizado para agrupar a marca, permitindo sua remocao * * {boolean} - posiciona a marca no centro do ponto * * {function} - função disparada no evento onclick * * Return: * * {objeto} * */ addPin : function(x, y, w, h, imagem, namespace, centro, funcaoclick) { return i3GEO.desenho[i3GEO.Interface.ATUAL].addPin(x, y, w, h, imagem, namespace, centro); }, /** * Function: removePins * * Remove marcas do mapa * * Parameter: * * {string} - namespace que identifica o grupo de marcas que serao removidas */ removePins : function(namespace) { i3GEO.desenho[i3GEO.Interface.ATUAL].removePins(namespace); }, /** * Function: movePin * * Reposiciona uma marca * * Parameter: * * {object} - marca * * {numeric} - novo x * * {numeric} - novo y */ movePin : function(pin, x, y) { i3GEO.desenho[i3GEO.Interface.ATUAL].movePin(pin, x, y); }, /** * Section: i3GEO.desenho.openlayers * * Funções utilizadas quando o mapa baseia-se na interface OpenLayers */ openlayers : { /** * Function: inicia * * Cria o layer onde os desenhos serao inseridos */ inicia : function() { if (!i3GEO.desenho.layergrafico) { i3GEO.desenho.openlayers.criaLayerGrafico(); } }, addBox : function(xmin, ymin, xmax, ymax, namespace, strokeColor, strokeWidth) { var pol, f; if (!namespace) { namespace = "box"; } if (!strokeColor) { strokeColor = "#FF0000"; } if (!strokeWidth) { strokeWidth = 2; } i3GEO.desenho.openlayers.inicia(); xmin = xmin * 1; ymin = ymin * 1; xmax = xmax * 1; ymax = ymax * 1; pol = new ol.geom.Polygon([[[xmin,ymin],[xmin,ymax],[xmax,ymax],[xmax,ymin],[xmin,ymin]]]); pol = i3GEO.util.extGeo2OSM(pol); f = new ol.Feature({ geometry: pol }); f.setStyle( new ol.style.Style({ stroke: new ol.style.Stroke({ color: strokeColor, width: strokeWidth }) }) ); f.setProperties({ origem : namespace }); i3GEO.desenho.layergrafico.getSource().addFeature(f); return f; }, moveBox : function(box, xmin, ymin, xmax, ymax) { box.getGeometry().setCoordinates([[[xmin,ymin],[xmin,ymax],[xmax,ymax],[xmax,ymin],[xmin,ymin]]]); return box; }, addPin : function(x, y, w, h, imagem, namespace, centro, funcaoclick) { if (!imagem || imagem === "") { imagem = i3GEO.configura.locaplic + "/imagens/google/confluence.png"; } if (!namespace) { namespace = "pin"; } if (!w || w === "") { w = 27; } if (!h || h === "") { h = 27; } if (!funcaoclick) { funcaoclick = function() { i3GEO.desenho.openlayers.removePins(namespace); }; } if (!centro) { centro = false; } i3GEO.desenho.openlayers.inicia(); var point, f, ox, oy; if (centro === true) { ox = 0.5; oy = 0.5; } else { ox = 0.5; oy = 1; } point = new ol.geom.Point([x, y]); point = i3GEO.util.extGeo2OSM(point); f = new ol.Feature({ geometry: point }); f.setProperties({ origem : namespace }); f.setStyle( new ol.style.Style({ image: new ol.style.Icon({ src : imagem, size: [w,h], anchor: [ox,oy] }) }) ); //FIXME como incluir o evento click? //f.on('click',funcaoclick); i3GEO.desenho.layergrafico.getSource().addFeature(f); return f; }, removePins : function(namespace) { if (!namespace) { namespace = "pin"; } if (i3GEO.desenho.layergrafico) { var features, n, f, i; features = i3GEO.desenho.layergrafico.getSource().getFeatures(); n = features.length; for (i = 0; i < n; i++) { f = features[i]; if (f && f.getProperties().origem === namespace) { i3GEO.desenho.layergrafico.getSource().removeFeature(f); } } } }, movePin : function(pin, x, y) { pin.getGeometry().setCoordinates([x,y]); }, criaLayerGrafico : function() { if (!i3GEO.desenho.layergrafico) { i3GEO.desenho.layergrafico = new ol.layer.Vector({ source : new ol.source.Vector({ features : new ol.Collection(), useSpatialIndex : false }), style : new ol.style.Style({ fill : new ol.style.Fill({ color : 'rgba(255, 255, 255, 0.2)' }), stroke : new ol.style.Stroke({ color : '#ffcc33', width : 4 }), image : new ol.style.Circle({ radius : 7, fill : new ol.style.Fill({ color : '#ffcc33' }) }) }) }); i3GEO.desenho.layergrafico.setMap(i3geoOL); i3GEO.desenho.layergrafico.getFeatures = function(){ return i3GEO.desenho.layergrafico.getSource().getFeatures(); }; } return; if (!i3GEO.desenho.layergrafico) { var sketchSymbolizers = { "Point" : { fillColor : "rgb(${fillColor})", fillOpacity : "${opacidade}", strokeWidth : "${strokeWidth}", strokeOpacity : "${opacidade}", strokeColor : "rgb(${strokeColor})", label : "${texto}", pointRadius : "${pointRadius}", graphicName : "${graphicName}", fontSize : "${fontSize}", fontColor : "rgb(${fontColor})", fontFamily : "Arial", fontWeight : "normal", labelAlign : "lb", labelXOffset : "3", labelYOffset : "3", externalGraphic : "${externalGraphic}" }, "Line" : { strokeWidth : "${strokeWidth}", strokeOpacity : "${opacidade}", strokeColor : "rgb(${strokeColor})" }, "Polygon" : { strokeWidth : "${strokeWidth}", strokeOpacity : "${opacidade}", strokeColor : "rgb(${strokeColor})", fillColor : "rgb(${fillColor})", fillOpacity : "${opacidade}", zIndex : 5000 } }, style = new OpenLayers.Style(), styleMap1 = new OpenLayers.StyleMap({ "default" : style, "vertex" : { strokeOpacity : 1, strokeWidth : 1, fillColor : "white", fillOpacity : 0.45, pointRadius : 4 } }, { extendDefault : false }); style.addRules([ new OpenLayers.Rule({ symbolizer : sketchSymbolizers }) ]); i3GEO.desenho.layergrafico = new OpenLayers.Layer.Vector("Graf", { styleMap : styleMap1, displayInLayerSwitcher : true, visibility : true, vertexRenderIntent : "vertex", eventListeners : { featureclick : function(e) { // log(e.object.name + " says: " + e.feature.id // + " clicked."); if (e.feature.data.click) { e.feature.data.click.call(); } return false; } } }); } } }, /** * Section: i3GEO.desenho.googlemaps * * Funções utilizadas quando o mapa baseia-se na interface GoogleMaps */ googlemaps : { /** * Variavel: shapes * * Array que guarda todos os objetos que estao atualmente no mapa E atualizado toda vez que uma figura e acrescentada ou * removida */ shapes : [], inicia : function() { }, addBox : function(xmin, ymin, xmax, ymax, namespace, strokeColor, strokeWidth) { var f; if (!namespace) { namespace = "box"; } if (!strokeColor) { strokeColor = "#FF0000"; } if (!strokeWidth) { strokeWidth = 2; } i3GEO.desenho.googlemaps.inicia(); f = new google.maps.Rectangle({ origem : namespace, strokeColor : strokeColor, strokeWeight : strokeWidth, fillOpacity : 0, map : i3GeoMap, bounds : new google.maps.LatLngBounds(new google.maps.LatLng(ymin, xmin), new google.maps.LatLng(ymax, xmax)) }); i3GEO.desenho.googlemaps.shapes.push(f); return f; }, moveBox : function(box, xmin, ymin, xmax, ymax) { box.setBounds(new google.maps.LatLngBounds(new google.maps.LatLng(ymin, xmin), new google.maps.LatLng(ymax, xmax))); return box; }, addPin : function(x, y, w, h, imagem, namespace, centro, funcaoclick) { if (!imagem || imagem === "") { imagem = i3GEO.configura.locaplic + "/imagens/google/confluence.png"; } if (!namespace) { namespace = "pin"; } if (!w || w === "") { w = 27; } if (!h || h === "") { h = 27; } if (!funcaoclick) { funcaoclick = function() { i3GEO.desenho.googlemaps.removePins(namespace); }; } if (!centro) { centro = false; } i3GEO.desenho.googlemaps.inicia(); var point, f, icon; if (centro === false) { icon = { url : imagem, size : new google.maps.Size(w, h) }; } else { icon = { url : imagem, size : new google.maps.Size(w, h), origin : new google.maps.Point(0, 0), anchor : new google.maps.Point(w / 2, h / 2) }; } point = new google.maps.LatLng(y, x); f = new google.maps.Marker({ position : point, map : i3GeoMap, origem : namespace, icon : icon }); i3GEO.desenho.googlemaps.shapes.push(f); return f; }, removePins : function(namespace) { if (!namespace) { namespace = "pin"; } var f = i3GEO.desenho.googlemaps.getFeaturesByAttribute("origem", namespace); if (f && f.length > 0) { i3GEO.desenho.googlemaps.destroyFeatures(f); } }, movePin : function(pin, x, y) { var point = new google.maps.LatLng(y, x); pin.setPosition(point); }, /** * Function: getFeaturesByAttribute * * Obtém uma figura com base em um atributo * * {string} * * {string} */ getFeaturesByAttribute : function(atributo, valor) { var i, s = [], n = i3GEO.desenho.googlemaps.shapes.length; for (i = 0; i < n; i++) { if (i3GEO.desenho.googlemaps.shapes[i] && i3GEO.desenho.googlemaps.shapes[i] != "") { if (i3GEO.desenho.googlemaps.shapes[i][atributo] == valor) { s.push(i3GEO.desenho.googlemaps.shapes[i]); } } } return s; }, /** * Function: destroyFeatures * * Destroi as figuras * * {array} - lista de objetos */ destroyFeatures : function(f) { if (f) { var i, n = f.length; for (i = 0; i < n; i++) { f[i].setMap(null); f[i] = ""; } } } } }; // YAHOO.log("carregou classe desenho", "Classes i3geo");