//TODO incluir balao de informacoes como um elemento grafico de desenho
//TODO incluir caixas de texto
//TODO incluir undo na edicao
//TODO incluir opção para digitar coordenadas do novo ponto ou vertice
/*
Title: Editor vetorial para OpenLayers
i3GEO.editorOL
Funções utilizadas pelo OpenLayers nas opções de edição de dados vetoriais.
É utilizado também pelo mashup com navegação via OpenLayers e com OSM.
Para adicionar novos botoes, modifique também i3GEO.editorOL.botoes existente em i3GEO.barraDeBotoes.openlayers.ativaPainel
Mesmo em interfaces de debug, esse javascript só é carregado depois de cmpactado
Arquivo: i3geo/classesjs/classe_editorol.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 ADEQUACAtilde;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 (!i3GEO || typeof (i3GEO) === 'undefined') {
var i3GEO = {};
i3GEO.Interface = {};
navn = false;
navm = false;
$i = function(id) {
return document.getElementById(id);
};
app = navigator.appName.substring(0, 1);
if (app === 'N') {
navn = true;
} else {
navm = true;
}
}
i3GEO.editorOL =
{
simbologia : {
opacidade : 0.8,
texto : "",
fillColor : "250,180,15",
strokeWidth : 5,
strokeColor : "250,150,0",
pointRadius : 4,
graphicName : "square",
fontSize : "12px",
fontColor : "0,0,0",
externalGraphic : "",
graphicHeight : 25,
graphicWidth : 25
},
backup : new ol.layer.Vector({
source : new ol.source.Vector({
features : new ol.Collection(),
useSpatialIndex : false,
name : "Backup"
}),
visible : false,
map : i3geoOL
}),
nomeFuncaoSalvar : "i3GEO.editorOL.salvaGeo()",
kml : [],
layersIniciais : [],
//essa configuracao dos botoes afeta apenas o mashup
//para a configuração do editor dentro de um mapa normal, veja i3GEO.barraDebotoes.editor.ativaPainel()
botoes : {
'pan' : true,
'zoombox' : true,
'zoomtot' : true,
'zoomin' : true,
'zoomout' : true,
'distancia' : true,
'area' : true,
'identifica' : true,
'linha' : true,
'ponto' : true,
'poligono' : true,
'texto' : true,
'edita' : true,
'listag' : true,
'corta' : true,
'apaga' : true,
'procura' : true,
'selecao' : true,
'selecaotudo' : true,
'salva' : true,
'ajuda' : true,
'propriedades' : true,
'fecha' : false,
'tools' : true,
'undo' : false,
'frente' : false,
'legenda' : true,
'rodadomouse' : true,
'novaaba' : false
},
pontos : [],
marca : "../pacotes/openlayers/img/marker-gold.png",
controles : [],
tiles : true,
incluilayergrafico : true,
ativalayerswitcher : false,
ativarodadomouse : true,
legendahtml : false,
numzoom : 12,
minresolution : 0.703125,
maxext : "",
mapext : [-76.5125927, -39.3925675209, -29.5851853, 9.49014852081],
mapa : "",
//ids das features graficas selecionadas
idsSelecionados : [],
//backup das features
featuresBackup : [],
//utilizado pelo mashup
inicia : function() {
// ativabotoes e boolean
if(i3GEO.editorOL.controles.length === 0){
i3GEO.editorOL.controles = [
new ol.interaction.DoubleClickZoom(),
new ol.interaction.KeyboardPan(),
new ol.interaction.KeyboardZoom(),
new ol.interaction.MouseWheelZoom(),
new ol.interaction.PinchRotate(),
new ol.interaction.PinchZoom(),
new ol.interaction.DragZoom(),
new ol.interaction.DragPan(),
new ol.control.Zoom(),
new ol.control.ZoomSlider(),
new ol.control.ScaleLine()
];
}
var alayers = [], fundo = (i3GEO.editorOL.fundo).split(","), nfundo = fundo.length, ncontroles =
i3GEO.editorOL.controles.length, i, n, temp;
if (i3GEO.editorOL.ativarodadomouse === "false") {
i3GEO.editorOL.ativarodadomouse = false;
}
if (i3GEO.editorOL.ativarodadomouse === "true") {
i3GEO.editorOL.ativarodadomouse = true;
}
if (i3GEO.editorOL.legendahtml === "false") {
i3GEO.editorOL.legendahtml = false;
}
if (i3GEO.editorOL.legendahtml === "true") {
i3GEO.editorOL.legendahtml = true;
}
if (i3GEO.editorOL.incluilayergrafico === "false") {
i3GEO.editorOL.incluilayergrafico = false;
}
if (i3GEO.editorOL.incluilayergrafico === "true") {
i3GEO.editorOL.incluilayergrafico = true;
}
if (i3GEO.editorOL.incluilayergrafico === true) {
if (!i3GEO.desenho.layergrafico) {
i3GEO.editorOL.criaLayerGrafico();
}
} else {
i3GEO.desenho.layergrafico = "";
i3GEO.editorOL.botoes.linha = false;
i3GEO.editorOL.botoes.ponto = false;
i3GEO.editorOL.botoes.poligono = false;
i3GEO.editorOL.botoes.texto = false;
i3GEO.editorOL.botoes.edita = false;
i3GEO.editorOL.botoes.listag = false;
i3GEO.editorOL.botoes.corta = false;
i3GEO.editorOL.botoes.apaga = false;
i3GEO.editorOL.botoes.selecao = false;
i3GEO.editorOL.botoes.selecaotudo = false;
i3GEO.editorOL.botoes.salva = false;
i3GEO.editorOL.botoes.propriedades = false;
i3GEO.editorOL.botoes.fecha = false;
i3GEO.editorOL.botoes.tools = false;
i3GEO.editorOL.botoes.undo = false;
i3GEO.editorOL.botoes.frente = false;
i3GEO.editorOL.botoes.novaaba = false;
}
if (i3GEO.editorOL.mapa === "") {
alert("O objeto i3GEO.editorOL.mapa nao existe. Precisa ser criado com new OpenLayers.Map()");
return;
}
for (i = 0; i < ncontroles; i++) {
i3GEO.editorOL.mapa.addControl(i3GEO.editorOL.controles[i]);
}
if (i3GEO.editorOL.fundo != "") {
for (i = nfundo - 1; i >= 0; i--) {
if (fundo[i] != "") {
try {
i3GEO.editorOL[fundo[i]].transitionEffect = 'resize';
i3GEO.editorOL[fundo[i]].setVisibility(false);
i3GEO.editorOL[fundo[i]].singleTile = false;
alayers.push(i3GEO.editorOL[fundo[i]]);
} catch (e) {
if (alayers[0]) {
alayers[0].setVisibility(true);
}
}
}
}
}
i3GEO.editorOL.mapa.addLayers(alayers);
if (i3GEO.editorOL.layersIniciais !== "") {
n = i3GEO.editorOL.layersIniciais.length;
for (i = 0; i < n; i++) {
// singleTile deve ser definido em cada layer
// i3GEO.editorOL.layersIniciais[i].singleTile = single;
i3GEO.editorOL.mapa.addLayer(i3GEO.editorOL.layersIniciais[i]);
}
}
if (!i3GEO.desenho.layergrafico && i3GEO.editorOL.incluilayergrafico === true) {
i3GEO.editorOL.mapa.addLayers([
i3GEO.desenho.layergrafico
]);
}
i3GEO.editorOL.adicionaKml();
i3GEO.editorOL.adicionaMarcas();
i3GEO.editorOL.coordenadas();
i3GEO.editorOL.criaJanelaBusca();
i3GEO.editorOL.criaBotoes(i3GEO.editorOL.botoes);
if (i3GEO.editorOL.ativalayerswitcher === true) {
i3GEO.editorOL.ativaLayerSwitcher();
}
if (i3GEO.editorOL.ativarodadomouse === false) {
i3GEO.editorOL.desativaRodaDoMouse();
}
if (i3GEO.editorOL.numzoom !== "") {
i3GEO.editorOL.mapa.setOptions({
numZoomLevels : i3GEO.editorOL.numzoom
});
}
if (i3GEO.editorOL.maxext !== "") {
i3GEO.editorOL.mapa.setOptions({
maxExtent : i3GEO.editorOL.maxext
});
}
if (i3GEO.editorOL.mapext != "") {
var m = i3GEO.util.extGeo2OSM(i3GEO.editorOL.mapext);
i3GEO.editorOL.mapa.zoomToExtent(m);
} else {
i3GEO.editorOL.mapa.zoomToMaxExtent();
}
i3GEO.editorOL.sobeLayersGraficos();
// evita que botoes de opcoes propaguem
// o mashup utiliza esse tipo de botal junto ao nome do layer
temp = i3GEO.editorOL.pegaControle("OpenLayers.Control.LayerSwitcher");
if (temp) {
temp = temp.dataLayersDiv.getElementsByTagName("label");
n = temp.length;
for (i = 0; i < n; i++) {
// YAHOO.util.Event.addListener(temp[i], "click", YAHOO.util.Event.stopEvent);
temp[i].onclick = "";
}
}
},
criaLayerGrafico : function() {
i3GEO.desenho.openlayers.criaLayerGrafico();
},
layersLigados : function() {
var l, layers = i3GEO.editorOL.mapa.getLayers(), nlayers = layers.getLength(), ins = [], i;
for (i = 0; i < nlayers; i++) {
l = layers.item(i);
if (l.getVisible() === true) {
ins.push(l);
}
}
return ins;
},
layerPorParametro : function(parametro, valor) {
var layers = i3GEO.editorOL.mapa.layers, nlayers = layers.length, ins = [], i;
for (i = 0; i < nlayers; i++) {
if (layers[i][parametro] || layers[i][parametro.toLowerCase()]) {
if (layers[i][parametro] === valor || layers[i][parametro.toLowerCase()] === valor) {
ins.push(layers[i]);
}
} else {
if (layers[i].params && layers[i].params[parametro] && layers[i].params[parametro] === valor) {
ins.push(layers[i]);
}
}
}
return ins;
},
// layers clonados sao copias WMS de layers TMS necessarios para realizar o getfeature
// sao criados quando o layer e adicionado
layersClonados : function(paramsLayers) {
var layers = i3GEO.editorOL.mapa.layers, nlayers = layers.length, i;
for (i = 0; i < nlayers; i++) {
if (layers[i].params && layers[i].params.CLONETMS === paramsLayers) {
return (layers[i]);
}
}
return false;
},
layertms2wms : function(tms) {
var layer, url;
url = tms.url.replace("&cache=sim", "&DESLIGACACHE=sim");
url = url.replace("&Z=${z}&X=${x}&Y=${y}", "");
url = url.replace("Z=${z}&X=${x}&Y=${y}", "");
layer = new OpenLayers.Layer.WMS(tms.layername + "_clone", url, {
layers : tms.name,
transparent : true
}, {
gutter : 0,
isBaseLayer : false,
displayInLayerSwitcher : false,
opacity : 1,
visibility : true,
singleTile : true
});
// i3GEO.editorOL.mapa.addLayer(layer);
return layer;
},
// remove o layer clonado com layertms2wms
removeClone : function() {
var nome = i3GEO.editorOL.layerAtivo().layername + "_clone", busca = i3GEO.editorOL.mapa.getLayersByName(nome);
if (busca.length > 0) {
i3GEO.editorOL.mapa.removeLayer(i3GEO.editorOL.mapa.getLayersByName(camada.name)[0], false);
}
},
coordenadas : function() {
//
// substitui o controle que mostra as coordenadas
//
var idcoord = i3GEO.editorOL.mapa.getControlsBy("separator", " ");
if (idcoord[0]) {
i3GEO.editorOL.mapa.events.register("mousemove", i3GEO.editorOL.mapa, function(e) {
var p, lonlat, d;
if (navm) {
p = new OpenLayers.Pixel(e.x, e.y);
} else {
p = e.xy;
}
// altera o indicador de localizacao
lonlat = i3GEO.editorOL.mapa.getLonLatFromPixel(p);
lonlat = i3GEO.util.projOSM2Geo(lonlat);
d = i3GEO.calculo.dd2dms(lonlat.lon, lonlat.lat);
try {
$i(idcoord[0].id).innerHTML = "Long: " + d[0] + "
Lat: " + d[1];
} catch (e) {
if (typeof (console) !== 'undefined') {
console.error(e);
}
}
});
}
},
criaJanelaBusca : function() {
var layers = i3GEO.editorOL.layersLigados(), nlayers = layers.length, i, ins, combo =
"";
ins = "
" + $trad("a7") + ":
" + combo;
ins += "
" + $trad("x64") + ":
";
ins += "
" + $trad("t23") + ":
";
ins += "
";
ins += "
'" + $trad("result") + "':
";
YAHOO.namespace("procura.container");
YAHOO.procura.container.panel = new YAHOO.widget.Panel("panelprocura", {
zIndex : 2000,
iframe : false,
width : "250px",
visible : false,
draggable : true,
close : true
});
YAHOO.procura.container.panel.setHeader("Encontre no mapa");
YAHOO.procura.container.panel.setBody(ins);
YAHOO.procura.container.panel.setFooter("");
YAHOO.procura.container.panel.render(document.body);
YAHOO.procura.container.panel.center();
document.getElementById("i3GEOOLbotaoBusca").onclick =
function() {
var layer = i3GEO.editorOL.layerAtivo(), item = document.getElementById("i3GEOOLbuscaItem").value, palavra =
document.getElementById("i3GEOOLpalavraBusca").value;
if (item === "" || palavra === "") {
alert("Escolha o item e o texto de busca");
return;
}
i3GEO.editorOL.busca(layer, item, palavra, "i3GEOOLcomboresultado");
};
document.getElementById("i3GEOOLlistaTemasBusca").onchange = function() {
i3GEO.editorOL.ativaTema(this.value);
document.getElementById("i3GEOOLcomboitens").innerHTML = "...";
i3GEO.editorOL.listaItens(i3GEO.editorOL.layerAtivo(), "i3GEOOLcomboitens", "i3GEOOLbuscaItem");
};
},
criaComboTemas : function() {
var layers = i3GEO.editorOL.layersLigados(), nlayers = layers.length, i, nometema = "", combo =
"";
return combo;
},
atualizaJanelaAtivaTema : function() {
var combo = i3GEO.editorOL.criaComboTemas();
YAHOO.temaativo.container.panel.setBody(combo);
},
criaJanelaAtivaTema : function() {
var temp;
if (!document.getElementById("paneltemaativo")) {
YAHOO.namespace("temaativo.container");
YAHOO.temaativo.container.panel = new YAHOO.widget.Panel("paneltemaativo", {
zIndex : 20000,
iframe : true,
width : "250px",
visible : false,
draggable : true,
close : true
});
YAHOO.temaativo.container.panel.setBody("");
if (i3GEO && typeof i3GEO != undefined && i3GEO != "") {
YAHOO.temaativo.container.panel
.setHeader("Tema ativo");
} else {
YAHOO.temaativo.container.panel.setHeader($trad("tativo"));
}
YAHOO.temaativo.container.panel.setFooter("");
YAHOO.temaativo.container.panel.render(document.body);
YAHOO.temaativo.container.panel.show();
YAHOO.temaativo.container.panel.center();
i3GEO.editorOL.atualizaJanelaAtivaTema();
YAHOO.util.Event.addListener(YAHOO.temaativo.container.panel.close, "click", function() {
i3GEO.editorOL.marcaBotao();
if (i3GEO.eventos) {
i3GEO.eventos.adicionaEventos("ATUALIZAARVORECAMADAS", [
"i3GEO.editorOL.atualizaJanelaAtivaTema()"
]);
}
});
if (i3GEO && typeof i3GEO != undefined && i3GEO != "") {
if (i3GEO.eventos) {
i3GEO.eventos.adicionaEventos("ATUALIZAARVORECAMADAS", [
"i3GEO.editorOL.atualizaJanelaAtivaTema()"
]);
}
}
temp = $i("paneltemaativo_minimizaCabecalho");
if (temp) {
temp.onclick = function() {
i3GEO.janela.minimiza("paneltemaativo");
};
}
} else {
YAHOO.temaativo.container.panel.show();
i3GEO.editorOL.atualizaJanelaAtivaTema();
}
},
ativaTema : function(id) {
document.getElementById("i3GEOOLlistaTemasAtivos").value = id;
},
layerAtivo : function() {
var id = document.getElementById("i3GEOOLlistaTemasAtivos");
if (id) {
id = id.value;
} else {
id = i3GEO.temaAtivo;
}
if (id == "") {
return [];
} else {
return i3GEO.editorOL.layersLigados()[id];
}
},
listaItens : function(layer, idonde, idobj) {
if (!layer) {
return;
}
if (!layer.params) {
return;
}
var u = layer.url + "&request=describefeaturetype&service=wfs&version=1.0.0";
u += "&typename=" + layer.params.LAYERS;
document.body.style.cursor = "wait";
document.getElementById("i3geoMapa").style.cursor = "wait";
OpenLayers.Request.issue({
method : "GET",
url : u,
callback : function(retorno) {
document.body.style.cursor = "default";
document.getElementById("i3geoMapa").style.cursor = "default";
var fromgml = new OpenLayers.Format.WFSDescribeFeatureType({
geometryName : "msGeometry"
}), gml = fromgml.read(retorno.responseText), prop = gml.featureTypes[0].properties, nprop = prop.length, i, combo =
"";
document.getElementById(idonde).innerHTML = combo;
},
failure : function() {
document.body.style.cursor = "default";
document.getElementById("i3geoMapa").style.cursor = "default";
alert("Erro");
}
});
},
busca : function(layer, item, palavra, onde) {
document.body.style.cursor = "wait";
document.getElementById("i3geoMapa").style.cursor = "wait";
var u = layer.url + "&request=getfeature&service=wfs&version=1.0.0";
u = u.replace("Z=${z}&X=${x}&Y=${y}", "");
u += "&OUTPUTFORMAT=gml2&typename=" + layer.params.LAYERS;
u +=
"&filter=" + item
+ "*"
+ palavra
+ "*";
document.body.style.cursor = "wait";
document.getElementById("i3geoMapa").style.cursor = "wait";
document.getElementById(onde).innerHTML = "...";
OpenLayers.Request.issue({
method : "GET",
url : u,
callback : function(retorno) {
document.body.style.cursor = "default";
document.getElementById("i3geoMapa").style.cursor = "default";
var fromgml = new OpenLayers.Format.GML({
geometryName : "msGeometry"
}), gml = fromgml.read(retorno.responseText), ngml = gml.length, i, ins =
"";
document.getElementById(onde).innerHTML = ins;
},
failure : function() {
document.body.style.cursor = "default";
document.getElementById("i3geoMapa").style.cursor = "default";
alert("Erro");
}
});
},
zoomPara : function(bbox) {
var b = new OpenLayers.Bounds.fromString(bbox);
i3GEO.editorOL.mapa.zoomToExtent(b);
},
mostraLegenda : function() {
var prop, layer, layers = i3GEO.editorOL.mapa.getLayers(), nlayers = layers.getLength(), ins = "", i, icone = "", url, f = "";
for (i = 0; i < nlayers; i++) {
layer = layers.item(i);
prop = layer.getProperties();
//monta a url para fazer a requisicao da legenda
//para os temas que nao sao baselayers
if(prop.source.getUrls){
url = prop.source.getUrls()[0];
url = url.replace("&cache=sim", "&DESLIGACACHE=sim");
url = url.replace("&Z=${z}&X=${x}&Y=${y}", "");
url = url.replace("Z=${z}&X=${x}&Y=${y}", "");
url += "&REQUEST=getlegendgraphic&service=wms&version=1.0.0";
if (i3GEO.Interface.openlayers.googleLike === true) {
url += "&SRS=EPSG:3857";
}
icone = "";
//TODO criar a legenda para uso no mashup
//caso do mashup
if (i3GEO.editorOL.legendahtml === true) {
// os parametros FORMAT e SERVICE sao inseridos de forma redundante para grantir
// caso seja um TMS
url = url.replace("image%2Fpng", "text/html") + "&FORMAT=text/html&SERVICE=WMS";
// verifica se a camada veio de um plugin de classe_plugini3geo
// e insere o icone se for necessario
/*
if (layers[i].options.plugini3geo) {
if (layers[i].params.LAYERS) {
// wms
icone = i3GEO.pluginI3geo[layers[i].options.plugini3geo].iconeArvoreDeCamadas(layers[i].params.LAYERS);
} else {
// tms
icone = i3GEO.pluginI3geo[layers[i].options.plugini3geo].iconeArvoreDeCamadas(layers[i].layers);
}
}
//
// verifica se a camada tem ferramentas parametrizadas
// insere o icone
//
fers = layers[i].options.ferramentas;
for (fer in fers) {
if (i3GEO.configura.ferramentasLayers[fer]) {
icone = i3GEO.configura.ferramentasLayers[fer].icone(layers[i]);
}
}
*/
ins += icone + prop.name + "
";
// necessario pq nao e sincrono
eval("var f = function(retorno){document.getElementById('legendaL_" + i
+ "').innerHTML = retorno.responseText;};");
url = url.replace("LAYERS", "LAYER");
var config = {
method : "GET",
url : url,
callback : f
};
OpenLayers.Request.issue(config);
} else if (prop.isBaseLayer === false && prop.visible === true) {
//caso a legenda seja aberta dentro do i3Geo
url = url.replace("LAYERS", "LAYER");
url += "&FORMAT=image/png";
ins += prop.title + "
![](" + url + ")
";
}
}
}
if (!document.getElementById("panellegendaeditorOL")) {
YAHOO.namespace("legendaeditorOL.container");
YAHOO.legendaeditorOL.container.panel = new YAHOO.widget.Panel("panellegendaeditorOL", {
zIndex : 20000,
iframe : true,
width : "auto",
visible : false,
draggable : true,
close : true
});
YAHOO.legendaeditorOL.container.panel.setBody(ins);
YAHOO.legendaeditorOL.container.panel.setHeader($trad("p3"));
YAHOO.legendaeditorOL.container.panel.setFooter("");
YAHOO.legendaeditorOL.container.panel.render(document.body);
YAHOO.legendaeditorOL.container.panel.show();
YAHOO.legendaeditorOL.container.panel.center();
YAHOO.util.Event.addListener(YAHOO.legendaeditorOL.container.panel.close, "click", function() {
YAHOO.legendaeditorOL.container.panel.destroy();
});
} else {
YAHOO.legendaeditorOL.container.panel.setBody(ins);
YAHOO.legendaeditorOL.container.panel.show();
}
},
captura : function(x,y,tema,idunico) {
var d = 0.001,
layer = i3geoOL.getLayersByName(tema)[0],
xy = [x,y],
u = layer.getSource().getUrls()[0],
poligono, retorno;
u += "&REQUEST=getfeature&service=wfs&version=1.0.0";
u += "&OUTPUTFORMAT=gml2&typename=undefined";
// remove parametros nao desejados
if (i3GEO.Interface.openlayers.googleLike === true) {
u += "&SRS=EPSG:3857";
}
u = u.replace("&cache=sim", "&DESLIGACACHE=sim");
u = u.replace("&Z=${z}&X=${x}&Y=${y}", "");
u = u.replace("Z=${z}&X=${x}&Y=${y}", "");
xy[0] = xy[0] * 1;
xy[1] = xy[1] * 1;
poligono =
(xy[0] - d) + ","
+ (xy[1] + d)
+ " "
+ (xy[0] + d)
+ ","
+ (xy[1] + d)
+ " "
+ (xy[0] + d)
+ ","
+ (xy[1] - d)
+ " "
+ (xy[0] - d)
+ ","
+ (xy[1] - d)
+ " "
+ (xy[0] - d)
+ ","
+ (xy[1] + d);
u +=
"&filter=Geometry" + poligono
+ "";
retorno = function(r){
var fs,c,format, f, n, i;
format = new ol.format.WKT();
fs = format.readFeatures(r[0]);
n = fs.length;
c = i3GEO.desenho.layergrafico.getSource();
for(i=0; i 0) {
if ($i("panelsalvageometrias")) {
if (YAHOO.i3GEO) {
YAHOO.salvaGeometrias.container.panel = YAHOO.i3GEO.janela.manager.find("panelsalvageometrias");
}
YAHOO.salvaGeometrias.container.panel.show();
YAHOO.salvaGeometrias.container.panel.bringToTop();
} else {
try {
YAHOO.namespace("salvaGeometrias.container");
YAHOO.salvaGeometrias.container.panel = new YAHOO.widget.Panel("panelsalvageometrias", {
zIndex : 2000,
iframe : false,
width : "250px",
visible : false,
draggable : true,
close : true
});
YAHOO.salvaGeometrias.container.panel.setHeader($trad("u6"));
YAHOO.salvaGeometrias.container.panel.setBody("");
YAHOO.salvaGeometrias.container.panel.setFooter("");
YAHOO.salvaGeometrias.container.panel.render(document.body);
YAHOO.salvaGeometrias.container.panel.center();
if (YAHOO.i3GEO && YAHOO.i3GEO.janela) {
YAHOO.i3GEO.janela.manager.register(YAHOO.salvaGeometrias.container.panel);
}
YAHOO.salvaGeometrias.container.panel.show();
} catch (e) {
}
}
ins += "" + n + " " + $trad("geosel") + "
";
ins +=
"" + $trad("listar")
+ " ";
if (i3GEO.editorOL.nomeFuncaoSalvar && i3GEO.editorOL.nomeFuncaoSalvar != "") {
ins += "" + $trad("sdados") + " ";
}
if (typeof i3geoOL !== "undefined") {
ins += "" + $trad("incorpo") + "
";
ins += "" + $trad("ajudaEditorOlSalva") + "
";
}
YAHOO.salvaGeometrias.container.panel.setBody(ins);
} else {
i3GEO.janela.tempoMsg($trad("selum"));
}
},
exportarSHP : function() {
i3GEO.editorOL.processageo("converteSHP");
},
incorporar : function() {
i3GEO.editorOL.processageo("incorporar");
},
listaGeometriasSel : function() {
var n = i3GEO.editorOL.idsSelecionados.length,
ins = "",
s = i3GEO.desenho.layergrafico.getSource(),
i, w, g;
for (i = 0; i < n; i++) {
g = s.getFeatureById(i3GEO.editorOL.idsSelecionados[i]);
ins += "" + $trad("u6") + ": #" + i + "
" + i3GEO.editorOL.google2wgs(g.getGeometry().getCoordinates()) + "
";
}
w = window.open();
w.document.write(ins);
w.document.close();
},
testeSalvar : function() {
alert("Funcao nao disponivel. Defina o nome da funcao em i3GEO.editorOL.nomeFuncaoSalvar ");
},
salvaGeo : function() {
var s = i3GEO.desenho.layergrafico.getSource(),
n = i3GEO.editorOL.idsSelecionados.length,
funcaoOK = function() {
// verifica se a geometria contem o atributo que indica a coluna ou codigo unico
var f = s.getFeatureById(i3GEO.editorOL.idsSelecionados[0]),
g = f.getGeometry(),
tema = $i("editorOLcomboTemaEditavel").value,
redesenha, p, format;
g = i3GEO.editorOL.google2wgs(g);
format = new ol.format.WKT();
f.setGeometry(g);
if (tema == "") {
return;
}
redesenha = function(retorno) {
i3GEO.janela.fechaAguarde("aguardeSalvaPonto");
i3GEO.editorOL.removeFeaturesSel();
i3GEO.Interface.atualizaTema("", tema);
};
i3GEO.janela.AGUARDEMODAL = true;
i3GEO.janela.abreAguarde("aguardeSalvaPonto", $trad("adic") + "...");
i3GEO.janela.AGUARDEMODAL = false;
// cria um novo registro
if(!f.getProperties().idUnico || f.getProperties().idUnico == ""){
p = i3GEO.configura.locaplic
+ "/ferramentas/editortema/exec.php?funcao=adicionaGeometria&g_sid="
+ i3GEO.configura.sid;
cpJSON.call(p, "foo", redesenha, "&tema=" + tema + "&wkt=" + format.writeFeatures([f]));
} else {
// atualiza a geometria
p = i3GEO.configura.locaplic
+ "/ferramentas/editortema/exec.php?funcao=atualizaGeometria&g_sid="
+ i3GEO.configura.sid;
cpJSON.call(
p,
"foo",
redesenha,
"&idunico=" + f.getProperties().idUnico + "&tema=" + tema + "&wkt=" + format.writeFeatures([f])
);
}
},
funcaoCombo = function(obj) {
$i("editorOLondeComboTemaEditavel").innerHTML = obj.dados;
},
texto = $trad("stema") + ":
"+$trad("salvaDadosEditor")+"
";
//monta a janela para o usuario escolher em qual camada os dados serao salvos
if (n != 1) {
i3GEO.janela.tempoMsg($trad("seluma"));
} else {
i3GEO.janela.confirma(texto, 300, $trad("salva"), $trad("canc"), funcaoOK);
i3GEO.util.comboTemas("editorOLcomboTemaEditavel", funcaoCombo, "editorOLondeComboTemaEditavel", "", false, "editavel");
}
},
//muda a classe do botao para marca-lo como ativo
marcaBotao : function(classeBotao){
//desmarca todos os botoes
var i, n, botoes = $i("i3GEObarraEdicao").getElementsByTagName("div");
n = botoes.length;
for(i = 0; i < n; i++){
botoes[i].className = botoes[i].className.replace("ItemActive","ItemInactive");
if(classeBotao){
botoes[i].className = botoes[i].className.replace(classeBotao+"ItemInactive",classeBotao+"ItemActive");
}
}
i3GEO.editorOL.removeInteracoes();
},
//interacoes criadas ao ativar algum botao
//usado para remover as interacoes
interacoes : [],
removeInteracoes: function(){
var i, n;
n = i3GEO.editorOL.interacoes.length;
for(i = 0; i < n; i++){
i3geoOL.removeInteraction(i3GEO.editorOL.interacoes[i]);
}
i3GEO.editorOL.interacoes = [];
},
botaoProcura : function(){
var temp = document.createElement("div");
temp.className = "editorOLprocuraItemInactive olButton";
temp.title = $trad("t23");
temp.onclick = function(){
i3GEO.editorOL.criaJanelaBusca();
YAHOO.procura.container.panel.show();
};
return temp;
},
botaoPan : function(){
var temp = document.createElement("div");
temp.className = "editorOLpanItemInactive olButton";
temp.title = "pan";
temp.onclick = function(){
i3GEO.editorOL.marcaBotao("editorOLpan");
};
return temp;
},
botaoZoomBox : function(){
var temp = document.createElement("div");
temp.className = "editorOLzoomboxItemInactive olButton";
temp.title = "zoombox";
temp.onclick = function(){
i3GEO.barraDeBotoes.defBotao("zoomli").funcaoonclick();
};
return temp;
},
botaoZoomTot : function(){
var temp = document.createElement("div");
temp.className = "editorOLzoomtotItemInactive olButton";
temp.title = $trad("d2t");
temp.onclick = function(){
if (i3GEO.editorOL.mapext && i3GEO.editorOL.mapext != "") {
i3GEO.Interface.openlayers.zoom2ext(i3GEO.editorOL.mapext.join(" "));
} else {
i3GEO.Interface.openlayers.zoom2ext(i3GEO.parametros.extentTotal);
}
};
return temp;
},
botaoZoomIn : function(){
var temp = document.createElement("div");
temp.className = "editorOLzoominItemInactive olButton";
temp.title = $trad("d5t");
temp.onclick = function(){
var v = i3GEO.editorOL.mapa.getView();
v.setZoom(v.getZoom() + 1);
};
return temp;
},
botaoZoomOut : function(){
var temp = document.createElement("div");
temp.className = "editorOLzoomoutItemInactive olButton";
temp.title = $trad("d5t");
temp.onclick = function(){
var v = i3GEO.editorOL.mapa.getView();
v.setZoom(v.getZoom() - 1);
};
return temp;
},
botaoLegenda : function(){
var temp = document.createElement("div");
temp.className = "editorOLlegendaItemInactive olButton";
temp.title = $trad("p3");
temp.onclick = function(){
i3GEO.editorOL.mostraLegenda();
};
return temp;
},
botaoDistancia : function(){
var temp = document.createElement("div");
temp.className = "editorOLdistanciaItemInactive olButton";
temp.onclick = function(){
i3GEO.editorOL.marcaBotao("editorOLdistancia");
i3GEO.barraDeBotoes.defBotao("mede").funcaoonclick();
};
return temp;
},
botaoArea: function(){
var temp = document.createElement("div");
temp.className = "editorOLareaItemInactive olButton";
temp.onclick = function(){
i3GEO.editorOL.marcaBotao("editorOLarea");
i3GEO.barraDeBotoes.defBotao("area").funcaoonclick();
};
return temp;
},
botaoLinha: function(){
var temp = document.createElement("div");
temp.className = "editorOLlinhaItemInactive olButton";
temp.title = $trad("dlinha");
temp.onclick = function(){
i3GEO.eventos.cliquePerm.desativa();
i3GEO.editorOL.marcaBotao("editorOLlinha");
var draw = new ol.interaction.Draw({
type : "LineString"
});
//adiciona a interacao para poder ser removida
i3GEO.editorOL.interacoes.push(draw);
//desativa ol.interaction.DoubleClickZoom
i3GEO.Interface.openlayers.interacoes[0].setActive(false);
draw.on("drawend", function(evt) {
evt.feature.setStyle(
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(' + i3GEO.editorOL.simbologia.strokeColor + ',' + i3GEO.editorOL.simbologia.opacidade + ')',
width: i3GEO.editorOL.simbologia.strokeWidth
}),
fill: new ol.style.Fill({
color: 'rgba(' + i3GEO.editorOL.simbologia.fillColor + ',' + i3GEO.editorOL.simbologia.opacidade + ')'
})
})
);
evt.feature.setId(i3GEO.util.uid());
i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature);
draw.setActive(false);
draw.setActive(true);
if (document.getElementById("panellistagEditor")) {
i3GEO.editorOL.listaGeometrias();
}
});
i3geoOL.addInteraction(draw);
};
return temp;
},
botaoPonto: function(){
i3GEO.eventos.cliquePerm.desativa();
var temp = document.createElement("div");
temp.className = "editorOLpontoItemInactive olButton";
temp.title = $trad("dponto");
temp.onclick = function(){
i3GEO.eventos.cliquePerm.desativa();
i3GEO.editorOL.marcaBotao("editorOLponto");
var draw = new ol.interaction.Draw({
type : "Point"
});
//adiciona a interacao para poder ser removida
i3GEO.editorOL.interacoes.push(draw);
i3GEO.Interface.openlayers.interacoes[0].setActive(false);
draw.on("drawend", function(evt) {
var simbolo, url;
url = i3GEO.editorOL.simbologia.externalGraphic;
if(url === ""){
simbolo = new ol.style.Circle({
radius: i3GEO.editorOL.simbologia.pointRadius,
fill: new ol.style.Fill({
color: 'rgba(' + i3GEO.editorOL.simbologia.fillColor + ',' + i3GEO.editorOL.simbologia.opacidade + ')'
}),
stroke: new ol.style.Stroke({
color: 'rgba(' + i3GEO.editorOL.simbologia.strokeColor + ',' + i3GEO.editorOL.simbologia.opacidade + ')',
width: i3GEO.editorOL.simbologia.pointRadius / 3
})
});
}
else{
simbolo = new ol.style.Icon({
src : url,
size : [i3GEO.editorOL.simbologia.graphicWidth,i3GEO.editorOL.simbologia.graphicHeight]
});
}
evt.feature.setStyle(
new ol.style.Style({
image: simbolo
})
);
evt.feature.setId(i3GEO.util.uid());
i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature);
draw.setActive(false);
draw.setActive(true);
if (document.getElementById("panellistagEditor")) {
i3GEO.editorOL.listaGeometrias();
}
});
i3geoOL.addInteraction(draw);
};
return temp;
},
botaoPoligono: function(){
i3GEO.eventos.cliquePerm.desativa();
var temp = document.createElement("div");
temp.className = "editorOLpoligonoItemInactive olButton";
temp.title = $trad("dpol");
temp.onclick = function(){
i3GEO.editorOL.marcaBotao("editorOLpoligono");
var draw = new ol.interaction.Draw({
type : "Polygon"
});
/*
snap = new ol.interaction.Snap({
source: i3GEO.desenho.layergrafico.getSource()
});
i3GEO.editorOL.interacoes.push(snap);
*/
//adiciona a interacao para poder ser removida
i3GEO.editorOL.interacoes.push(draw);
i3GEO.Interface.openlayers.interacoes[0].setActive(false);
draw.on("drawend", function(evt) {
evt.feature.setStyle(
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(' + i3GEO.editorOL.simbologia.strokeColor + ',' + i3GEO.editorOL.simbologia.opacidade + ')',
width: i3GEO.editorOL.simbologia.strokeWidth
}),
fill: new ol.style.Fill({
color: 'rgba(' + i3GEO.editorOL.simbologia.fillColor + ',' + i3GEO.editorOL.simbologia.opacidade + ')'
})
})
);
evt.feature.setId(i3GEO.util.uid());
i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature);
draw.setActive(false);
draw.setActive(true);
if (document.getElementById("panellistagEditor")) {
i3GEO.editorOL.listaGeometrias();
}
});
i3geoOL.addInteraction(draw);
};
return temp;
},
botaoTexto: function(){
i3GEO.eventos.cliquePerm.desativa();
var temp = document.createElement("div");
temp.className = "editorOLtextoItemInactive olButton";
temp.title = $trad("dtexto");
temp.onclick = function(){
i3GEO.eventos.cliquePerm.desativa();
i3GEO.editorOL.marcaBotao("editorOLtexto");
var draw = new ol.interaction.Draw({
type : "Point"
});
//adiciona a interacao para poder ser removida
i3GEO.editorOL.interacoes.push(draw);
i3GEO.Interface.openlayers.interacoes[0].setActive(false);
draw.on("drawend", function(evt) {
var texto = window.prompt("Texto", "");
evt.feature.setStyle(
new ol.style.Style({
text: new ol.style.Text({
text: texto,
font: 'Bold ' + parseInt(i3GEO.editorOL.simbologia.fontSize,10) + 'px Arial',
textAlign: 'left',
stroke: new ol.style.Stroke({
color: 'white',
width: i3GEO.editorOL.simbologia.strokeWidth
}),
fill: new ol.style.Fill({
color: i3GEO.editorOL.simbologia.fontColor
}),
zIndex: 2000
})
})
);
evt.feature.setId(i3GEO.util.uid());
i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature);
draw.setActive(false);
draw.setActive(true);
i3GEO.editorOL.marcaBotao();
});
i3geoOL.addInteraction(draw);
};
return temp;
},
botaoSelecao: function(){
i3GEO.eventos.cliquePerm.desativa();
var temp = document.createElement("div");
temp.className = "editorOLselecaoItemInactive olButton";
temp.title = $trad("d24t");
temp.onclick = function(){
i3GEO.editorOL.marcaBotao("editorOLselecao");
var sel = new ol.interaction.Select();
//adiciona a interacao para poder ser removida
i3GEO.editorOL.interacoes.push(sel);
i3GEO.Interface.openlayers.interacoes[0].setActive(false);
sel.on("select", function(evt) {
var s,i, n, id, f;
n = evt.selected.length;
for(i=0; i 0){
x = window.confirm($trad("excsel") + "?");
if(x){
i3GEO.editorOL.removeFeaturesSel();
i3GEO.desenho.layergrafico.getSource().changed();
}
}
else{
i3GEO.janela.tempoMsg($trad("selum"));
}
};
return temp;
},
botaoFrente: function(){
var temp = document.createElement("div");
temp.className = "editorOLfrenteItemInactive olButton";
temp.title = $trad("frente");
temp.onclick = function(){
var nsel = i3GEO.editorOL.idsSelecionados.length;
if(nsel > 0){
i3GEO.editorOL.marcaBotao();
i3GEO.editorOL.trazParaFrente();
}
else{
i3GEO.janela.tempoMsg($trad("selum"));
}
};
return temp;
},
//FIXME Translate nao funciona nessa versao do openlayers 3x precisa atualizar
botaoEdita: function(){
i3GEO.eventos.cliquePerm.desativa();
var temp = document.createElement("div");
temp.className = "editorOLeditaItemInactive olButton";
temp.title = $trad("dpol");
temp.onclick = function(){
i3GEO.editorOL.featuresBackup = [];
var draw, nsel, f, c;
nsel = i3GEO.editorOL.idsSelecionados.length;
if(nsel > 0){
i3GEO.editorOL.marcaBotao("editorOLedita");
f = i3GEO.desenho.layergrafico.getSource().getFeatureById(i3GEO.editorOL.idsSelecionados[nsel - 1]);
i3GEO.editorOL.featuresBackup.push(f.clone());
c = new ol.Collection();
c.push(f);
draw = new ol.interaction.Modify({
features: c
});
//adiciona a interacao para poder ser removida
i3GEO.editorOL.interacoes.push(draw);
i3GEO.Interface.openlayers.interacoes[0].setActive(false);
i3geoOL.addInteraction(draw);
}
else{
i3GEO.janela.tempoMsg($trad("selum"));
}
};
return temp;
},
botaoCorta: function(){
i3GEO.eventos.cliquePerm.desativa();
var temp = document.createElement("div");
temp.className = "editorOLcortaItemInactive olButton";
temp.title = $trad("cortaf");
temp.onclick = function(){
var nsel = i3GEO.editorOL.idsSelecionados.length;
if (nsel != 1) {
alert("Selecione primeiro um elemento para ser cortado");
} else {
i3GEO.janela.tempoMsg("Desenhe um polígono");
i3GEO.editorOL.marcaBotao("editorOLcorta");
var draw = new ol.interaction.Draw({
type : "Polygon"
});
//adiciona a interacao para poder ser removida
i3GEO.editorOL.interacoes.push(draw);
i3GEO.Interface.openlayers.interacoes[0].setActive(false);
draw.on("drawend", function(evt) {
var temp, f, c, format, fwkt, cwkt;
f = evt.feature;
c = i3GEO.desenho.layergrafico.getSource().getFeatureById(i3GEO.editorOL.idsSelecionados[nsel - 1]);
i3GEO.editorOL.featuresBackup.push(c.clone());
i3GEO.editorOL.marcaBotao();
//corta
format = new ol.format.WKT();
if(f && c){
fwkt = format.writeFeatures([f]);
cwkt = format.writeFeatures([c]);
if(fwkt && cwkt){
temp = function(retorno) {
i3GEO.janela.fechaAguarde("i3GEO.cortador");
if (retorno != "" && retorno.data && retorno.data != "") {
i3GEO.janela.fechaAguarde("i3GEO.cortador");
c.setGeometry(format.readGeometry(retorno.data));
if (document.getElementById("panellistagEditor")) {
i3GEO.editorOL.listaGeometrias();
}
}
};
i3GEO.janela.abreAguarde("i3GEO.cortador", "Cortando");
i3GEO.php.funcoesGeometriasWkt(temp, cwkt + "|" + fwkt, "difference");
}
}
});
i3geoOL.addInteraction(draw);
}
};
return temp;
},
botaoListaGeometrias: function(){
var temp = document.createElement("div");
temp.className = "editorOLlistagItemInactive olButton";
temp.title = $trad("listag");
temp.onclick = function(){
i3GEO.editorOL.listaGeometrias();
};
return temp;
},
botaoNovaaba: function(){
var temp = document.createElement("div");
temp.className = "editorOLnovaabaItemInactive olButton";
temp.title = $trad("novaaba");
temp.onclick = function(){
window.open(window.location, '_blank');
};
return temp;
},
botaoAjuda: function(){
var temp = document.createElement("div");
temp.className = "editorOLajudaItemInactive olButton";
temp.title = $trad("s1");
temp.onclick = function(){
if(i3GEO.configura && i3GEO.configura.locaplic){
i3GEO.janela.cria("400px", "200px", i3GEO.configura.locaplic
+ "/mashups/openlayers_ajuda.php?completo=none", "", "", $trad("s1"), "editorOlAjuda");
}
else{
window.open("openlayers_ajuda.php");
}
};
return temp;
},
botaoFecha: function(){
var temp = document.createElement("div");
temp.className = "editorOLfechaItemInactive olButton";
temp.title = $trad("x74");
temp.onclick = function(){
i3GEO.editorOL.unselTodos();
i3GEO.editorOL.featuresBackup = [];
i3GEO.editorOL.marcaBotao();
i3GEO.eventos.cliquePerm.ativa();
$i("i3GEObarraEdicao").style.display = "none";
};
return temp;
},
botaoTools: function(){
var temp = document.createElement("div");
temp.className = "editorOLtoolsItemInactive olButton";
temp.title = $trad("u15a");
temp.onclick = function(){
// fora do i3geo, usa o jsts
if (i3GEO.php) {
i3GEO.editorOL.ferramentas();
} else {
i3GEO.editorOL.carregajts("i3GEO.editorOL.ferramentas()");
}
};
return temp;
},
botaoPropriedades: function(){
var temp = document.createElement("div");
temp.className = "editorOLpropriedadesItemInactive olButton";
temp.title = $trad("p13");
temp.onclick = function(){
i3GEO.editorOL.propriedades();
};
return temp;
},
botaoIdentifica: function(){
i3GEO.eventos.cliquePerm.desativa();
var temp = document.createElement("div");
temp.className = "editorOLidentificaItemInactive olButton";
temp.title = $trad("d7t");
temp.onclick = function(){
i3GEO.editorOL.criaJanelaAtivaTema();
i3GEO.eventos.cliquePerm.desativa();
i3GEO.editorOL.marcaBotao("editorOLidentifica");
var draw = new ol.interaction.Draw({
type : "Point"
});
//adiciona a interacao para poder ser removida
i3GEO.editorOL.interacoes.push(draw);
i3GEO.Interface.openlayers.interacoes[0].setActive(false);
draw.on("drawend", function(evt) {
var xy, p, retorno, url, layer, tema = $i("i3GEOOLlistaTemasAtivos");
if(tema){
layer = i3geoOL.getLayersByName(tema.value)[0];
url = layer.getSource().getUrls()[0];
xy = evt.target.downPx_;
retorno = function(r){
var valorunico = "", camada, texto = "", lonlattexto, xy, temp, temp1, n, i, f = [], textoN = r.split(":");
camada = i3GEO.arvoreDeCamadas.pegaTema(tema.value, "", "name");
xy = evt.feature.getGeometry().getFirstCoordinate();
i3GEO.eventos.cliquePerm.ativo = true;
try {
if (textoN.length > 1) {
temp = textoN[2].replace(/\n\r/g, "");
temp = temp.replace(/'/g, "");
temp = temp.replace(/\n/g, "|");
temp = temp.replace(/_/g, " ");
temp = temp.replace(/=/g, ":");
temp = temp.split("|");
n = temp.length;
for (i = 0; i < n; i++) {
temp1 = temp[i].replace(/^\s+/, "");
temp1 = temp1.replace(/\s+$/, "");
if (temp1 != ""){
//verifica se a coluna eh o idunico e pega o valor
if(camada.colunaidunico != "" && temp1.split(":")[0].trim() == camada.colunaidunico){
valorunico = temp1.split(":")[1].trim();
temp1 = "(*) "+temp1;
}
f.push(temp1);
}
}
texto = "" + f.join("
") + "
";
}
} catch (e) {}
//funcao para capturar a geometria
lonlattexto =
"edita geometria
";
i3GEO.Interface.openlayers.balao("" + lonlattexto + texto + "
","", xy[0], xy[1], false, false);
i3GEO.eventos.cliquePerm.ativo = false;
};
p = i3GEO.configura.locaplic + "/classesphp/proxy.php?"
+ url
+ "&tipoRetornoProxy=string&REQUEST=GetFeatureInfo&TIPOIMAGEM=nenhum&DESLIGACACHE=sim&STYLES=&SERVICE=WMS&VERSION=1.1.1&FEATURE_COUNT=1"
+ "&FORMAT=image/png&INFO_FORMAT=text/plain&SRS=EPSG:4326"
+ "&LAYERS=" + tema.value
+ "&layer=" + tema.value
+ "&QUERY_LAYERS=" + tema.value
+ "&HEIGHT=" + i3GEO.parametros.h
+ "&WIDTH=" + i3GEO.parametros.w
+ "&BBOX=" + i3geoOL.getExtent().toBBOX().split(",").join(" ")
+ "&X=" + xy[0] + "&Y=" + xy[1];
cpJSON.call(p, "foo", retorno, "");
}
});
i3geoOL.addInteraction(draw);
};
return temp;
},
botaoSalva: function(){
var temp = document.createElement("div");
temp.className = "editorOLsalvaItemInactive olButton";
temp.title = $trad("salva");
temp.onclick = function(){
i3GEO.editorOL.salvaGeometrias();
};
return temp;
},
criaBotoes : function(botoes) {
if($i("i3GEObarraEdicao")){
$i("i3GEObarraEdicao").style.display = "block";
return;
}
//cria o painel onde entrarao os icones
i3GEOpanelEditor = document.createElement("div");
i3GEOpanelEditor.id = "i3GEObarraEdicao";
i3GEOpanelEditor.className = "olControlEditingToolbar1 noprint";
//cria os icones
if (botoes.novaaba === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoNovaaba());
}
if (botoes.procura === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoProcura());
}
if (botoes.pan === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoPan());
}
if (botoes.zoombox === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoZoomBox());
}
if (botoes.zoomtot === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoZoomTot());
}
if (botoes.zoomin === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoZoomIn());
}
if (botoes.zoomout === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoZoomOut());
}
if (botoes.legenda === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoLegenda());
}
if (botoes.distancia === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoDistancia());
}
if (botoes.area === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoArea());
}
if (botoes.identifica === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoIdentifica());
}
if (botoes.linha === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoLinha());
}
if (botoes.ponto === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoPonto());
}
if (botoes.poligono === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoPoligono());
}
if (botoes.texto === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoTexto());
}
if (botoes.edita === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoEdita());
}
if (botoes.selecao === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoSelecao());
}
if (botoes.selecaotudo === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoSelecaoTudo());
}
if (botoes.apaga === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoApaga());
}
if (botoes.frente === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoFrente());
}
if (botoes.edita === true && botoes.corta === true && i3GEO.php) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoCorta());
}
if (botoes.edita === true && botoes.listag === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoListaGeometrias());
}
if (botoes.tools === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoTools());
}
if (botoes.propriedades === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoPropriedades());
}
if (botoes.salva === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoSalva());
}
if (botoes.ajuda === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoAjuda());
}
if (botoes.fecha === true) {
i3GEOpanelEditor.appendChild(i3GEO.editorOL.botaoFecha());
}
i3GEOpanelEditor.style.width = i3GEOpanelEditor.getElementsByTagName("div").length * 33 + "px";
i3GEO.editorOL.mapa.getViewport().getElementsByClassName("ol-overlaycontainer-stopevent")[0].appendChild(i3GEOpanelEditor);
},
removeFeaturesSel : function(){
var s, i, nsel, f;
nsel = i3GEO.editorOL.idsSelecionados.length;
s = i3GEO.desenho.layergrafico.getSource();
for(i=0; iEstilos (utilize a cor no formato r,g,b):'
+ 'Cor do contorno
'
+ ''
+ ''
+ '
'
+ '
Cor do preenchimento
'
+ ''
+ ''
+ '
'
+ '
Cor da fonte
'
+ ''
+ ''
+ '
'
+ '
Tamanho da fonte
'
+ ''
+ ''
+ '
'
+ '
Opacidade (de 0 a 1)
'
+ ''
+ ''
+ '
'
+ '
Largura da linha/contorno
'
+ ''
+ ''
+ '
'
+ '
Url de uma imagem
'
+ ''
+ ''
+ '
'
+ '
Largura da imagem
'
+ ''
+ ''
+ '
'
+ '
Altura da imagem
'
+ ''
+ ''
+ '
';
//TODO implementar ao atualizar OL3
/*
+ '
'
+ 'Ajusta nó em edição para o(a):
'
+ ''
+ '
'
+ 'Divide intersecção ao digitalizar
'
+ ''
+ '
'
+ 'Operação ativada pelo botão de modificação da figura
'
+ '';
*/
YAHOO.editorOL.container.panel.setBody(ins);
if (i3GEO && typeof i3GEO != undefined && i3GEO != "") {
YAHOO.editorOL.container.panel
.setHeader("Propriedades");
} else {
YAHOO.editorOL.container.panel.setHeader("Propriedades");
}
YAHOO.editorOL.container.panel.setFooter("");
YAHOO.editorOL.container.panel.render(document.body);
YAHOO.editorOL.container.panel.center();
YAHOO.util.Event.addListener(YAHOO.editorOL.container.panel.close, "click", function() {
});
temp = $i("panelpropriedadesEditor_minimizaCabecalho");
if (temp) {
temp.onclick = function() {
i3GEO.janela.minimiza("panelpropriedadesEditor");
};
}
i3GEO.util.aplicaAquarela("panelpropriedadesEditor");
}
YAHOO.editorOL.container.panel.show();
temp = $i("panelpropriedadesEditor").getElementsByTagName("div");
if (temp && temp[2]) {
temp[2].style.overflow = "auto";
}
},
listaGeometrias : function() {
if (!document.getElementById("panellistagEditor")) {
YAHOO.namespace("editorOL.listaGeometrias");
YAHOO.editorOL.listaGeometrias.panel = new YAHOO.widget.Panel("panellistagEditor", {
zIndex : 20000,
iframe : true,
width : "320px",
visible : false,
draggable : true,
close : true
});
if (i3GEO && typeof i3GEO != undefined && i3GEO != "") {
YAHOO.editorOL.listaGeometrias.panel
.setHeader($trad("u6") + " ");
} else {
YAHOO.editorOL.listaGeometrias.panel.setHeader($trad("u6"));
}
YAHOO.editorOL.listaGeometrias.panel.setFooter("");
YAHOO.editorOL.listaGeometrias.panel.render(document.body);
YAHOO.editorOL.listaGeometrias.panel.center();
YAHOO.util.Event.addListener(YAHOO.editorOL.listaGeometrias.panel.close, "click", function() {
YAHOO.editorOL.listaGeometrias.panel.destroy();
});
temp = $i("panellistagEditor_minimizaCabecalho");
if (temp) {
temp.onclick = function() {
i3GEO.janela.minimiza("panellistagEditor");
};
}
} else {
YAHOO.editorOL.listaGeometrias.panel.render(document.body);
}
var id, temp, geos = i3GEO.desenho.layergrafico.getSource().getFeatures(), n = geos.length, ins = "";
ins += "" + $trad("u6") + " | " + $trad("opcoes") + " | |
";
while (n > 0) {
n -= 1;
id = geos[n].getId();
if(id){
ins +=
"" + id
+ " | seleciona | limpa |
";
}
}
ins += "
";
if (geos.length === 0) {
ins = $trad("meneditor2");
}
YAHOO.editorOL.listaGeometrias.panel.show();
if (i3GEO.configura) {
temp = $i("panellistagEditor").getElementsByTagName("div")[2];
} else {
temp = $i("panellistagEditor").getElementsByTagName("div")[1];
}
temp.style.overflow = "auto";
temp.style.height = "100px";
temp.innerHTML = ins;
},
ferramentas : function() {
var b, ins;
if (!document.getElementById("panelferramentasEditor")) {
YAHOO.namespace("editorOL.ferramentas");
YAHOO.editorOL.ferramentas.panel = new YAHOO.widget.Panel("panelferramentasEditor", {
zIndex : 20000,
iframe : true,
width : "300px",
height : "150px",
visible : false,
draggable : true,
close : true
});
ins =
"" + ''
+ $trad("opsel")
+ ':
'
+ ''
+ '';
ins += '
';
ins += '
';
YAHOO.editorOL.ferramentas.panel.setBody(ins);
if (i3GEO && typeof i3GEO != undefined && i3GEO != "") {
YAHOO.editorOL.ferramentas.panel
.setHeader("Ferramentas
");
} else {
YAHOO.editorOL.ferramentas.panel.setHeader("Ferramentas");
}
YAHOO.editorOL.ferramentas.panel.setFooter("");
YAHOO.editorOL.ferramentas.panel.render(document.body);
YAHOO.editorOL.ferramentas.panel.center();
YAHOO.util.Event.addListener(YAHOO.editorOL.ferramentas.panel.close, "click", function() {
});
temp = $i("panelferramentasEditor_minimizaCabecalho");
if (temp) {
temp.onclick = function() {
i3GEO.janela.minimiza("panelferramentasEditor");
};
}
b = new YAHOO.widget.Button(
"panelferramentasEditorAplicar",{
onclick:{
fn: function(){
i3GEO.editorOL.processageo($i("panelferramentasEditorOpcoes").value);
}
}
});
b.addClass("rodar");
} else {
YAHOO.editorOL.ferramentas.panel.render(document.body);
}
YAHOO.editorOL.ferramentas.panel.show();
},
//TODO implementar ao atualizar OL3
snap : function() {
var target = i3GEOOLsnap.targets[0], tipos = [
"node", "vertex", "edge"
], ntipos = tipos.length, i, temp, ativa = false;
i3GEOOLsnap.deactivate();
for (i = 0; i < ntipos; i++) {
temp = $i("target_" + tipos[i]);
target[tipos[i]] = temp.checked;
if (temp.checked === true) {
ativa = true;
}
temp = $i("target_" + tipos[i] + "Tolerance");
target[tipos[i] + "Tolerance"] = temp.value;
}
if (ativa === true) {
i3GEOOLsnap.activate();
}
},
split : function() {
i3GEOOLsplit.deactivate();
var temp = $i("edge_split_toggle");
if (temp.checked === true) {
i3GEOOLsplit.activate();
}
},
processageo : function(operacao) {
if (operacao === "") {
return;
}
var polis, linhas, pontos, temp, nsel = i3GEO.editorOL.idsSelecionados.length;
if (nsel > 0) {
temp = function(retorno) {
if (i3GEO.janela) {
i3GEO.janela.fechaAguarde("i3GEO.editorPoli");
i3GEO.janela.fechaAguarde("i3GEO.editorLinhas");
i3GEO.janela.fechaAguarde("i3GEO.editorPontos");
}
if (retorno != "" && retorno.data && retorno.data != "" && operacao != "converteSHP") {
i3GEO.editorOL.substituiFeaturesSel(retorno.data);
}
if (operacao === "converteSHP") {
i3GEO.atualiza();
i3GEO.janela.minimiza("paneltemaativo");
}
};
if (operacao === "incorporar") {
polis = i3GEO.editorOL.retornaFeaturesTipo("Polygon");
linhas = i3GEO.editorOL.retornaFeaturesTipo("LineString");
pontos = i3GEO.editorOL.retornaFeaturesTipo("Point");
if (polis.length > 0) {
temp = i3GEO.editorOL.merge(polis);
}
if (linhas.length > 0) {
temp = i3GEO.editorOL.merge(linhas);
}
if (pontos.length > 0) {
temp = i3GEO.editorOL.merge(pontos);
}
if (i3GEO.mapa) {
i3GEO.mapa.dialogo.wkt2layer(temp);
}
return;
}
if (operacao === "union" && !i3GEO.php) {
polis = i3GEO.editorOL.retornaFeaturesTipo("Polygon");
linhas = i3GEO.editorOL.retornaFeaturesTipo("LineString");
pontos = i3GEO.editorOL.retornaFeaturesTipo("Point");
if (polis.length > 0) {
temp = i3GEO.editorOL.uniaojts(polis);
i3GEO.editorOL.substituiFeaturesSel(temp);
}
if (linhas.length > 0) {
temp = i3GEO.editorOL.uniaojts(linhas);
i3GEO.editorOL.substituiFeaturesSel(temp);
}
if (pontos.length > 0) {
temp = i3GEO.editorOL.uniaojts(pontos);
i3GEO.editorOL.substituiFeaturesSel(temp);
}
} else {
polis = i3GEO.editorOL.retornaGeometriasTipo("Polygon");
linhas = i3GEO.editorOL.retornaGeometriasTipo("LineString");
pontos = i3GEO.editorOL.retornaGeometriasTipo("Point");
if (polis.length > 0) {
i3GEO.janela.abreAguarde("i3GEO.editorPoli", "Poligonos");
i3GEO.php.funcoesGeometriasWkt(temp, polis.join("|"), operacao);
}
if (linhas.length > 0) {
i3GEO.janela.abreAguarde("i3GEO.editorLinhas", "Linhas");
i3GEO.php.funcoesGeometriasWkt(temp, linhas.join("|"), operacao);
}
if (pontos.length > 0) {
i3GEO.janela.abreAguarde("i3GEO.editorPontos", "Pontos");
i3GEO.php.funcoesGeometriasWkt(temp, pontos.join("|"), operacao);
}
}
i3GEO.desenho.layergrafico.getSource().changed();
return;
} else {
i3GEO.janela.tempoMsg("Selecione pelo menos dois elementos");
}
},
merge : function(geoms) {
var n = geoms.length,
w = new Wkt.Wkt(),
g, m, i,f,
format = new ol.format.WKT();
f = format.writeFeatures([geoms[0]]);
w.read(f);
if (n > 1) {
for (i = 1; i < n; i++) {
g = format.writeFeatures([geoms[i]]);
m = new Wkt.Wkt();
m.read(g);
w.merge(m);
}
}
return w.write();
},
uniaojts : function(geoms) {
var n = geoms.length,
fwkt = new ol.format.WKT(),
rwkt = new jsts.io.WKTReader(),
wwkt = new jsts.io.WKTWriter(),
g, i, uniao;
if (n > 1) {
//converte em wkt
uniao = fwkt.writeFeatures([geoms[0]]);
//le na jsts
uniao = rwkt.read(uniao);
for (i = 1; i <= n; i++) {
g = fwkt.writeFeatures([geoms[i]]);
uniao = uniao.union(rwkt.read(g));
}
//gera em wkt
uniao = wwkt.write(uniao);
return [
fwkt.readFeatures(uniao)
];
} else {
return false;
}
},
retornaGeometriasTipo : function(tipo) {
var n = i3GEO.editorOL.idsSelecionados.length, lista = [], i,
s = i3GEO.desenho.layergrafico.getSource(),
fwkt = new ol.format.WKT();
for (i = 0; i < n; i++) {
f = s.getFeatureById(i3GEO.editorOL.idsSelecionados[i]);
if (f.getGeometry().getType() == tipo) {
lista.push(fwkt.writeFeatures([f]));
}
}
return lista;
},
retornaFeaturesTipo : function(tipo) {
var n = i3GEO.editorOL.idsSelecionados.length, lista = [], i,
s = i3GEO.desenho.layergrafico.getSource();
for (i = 0; i < n; i++) {
f = s.getFeatureById(i3GEO.editorOL.idsSelecionados[i]);
if (f.getGeometry().getType() == tipo) {
lista.push(f);
}
}
return lista;
},
guardaBackup : function() {
return;
// if(!i3GEO.editorOL.backup)
// {i3GEO.editorOL.backup = new OpenLayers.Layer.Vector("Backup",{displayInLayerSwitcher:false,visibility:false});}
// else
// {i3GEO.editorOL.backup.removeFeatures(i3GEO.editorOL.backup.features);}
// i3GEO.editorOL.backup.addFeatures(i3GEO.desenho.layergrafico.features);
},
selTodos : function() {
i3GEO.editorOL.unselTodos();
var features, n, f, i, id, st;
features = i3GEO.desenho.layergrafico.getSource().getFeatures();
n = features.length;
for (i = 0; i < n; i++) {
f = features[i];
id = f.getId();
if(!id){
id = i3GEO.util.uid();
f.setId(id);
}
i3GEO.editorOL.idsSelecionados.push(id);
st = f.getStyle();
//para o caso de pontos
if(st && st.getImage()){
f.setStyle(
new ol.style.Style({
image: new ol.style.Circle({
radius: i3GEO.editorOL.simbologia.pointRadius,
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.5)'
}),
stroke: new ol.style.Stroke({
color: 'blue',
width: i3GEO.editorOL.simbologia.pointRadius / 3
})
})
})
);
if(st.getImage().getSrc){
f.setProperties({
fillColor: "",
strokeColor: "",
externalGraphic: st.getImage().getSrc(),
graphicHeight : st.getImage().getSize()[1],
graphicWidth : st.getImage().getSize()[0]
});
}
else{
f.setProperties({
fillColor: st.getImage().getFill().getColor(),
strokeColor: st.getImage().getStroke().getColor(),
externalGraphic: "",
graphicHeight: "",
graphicWidth: ""
});
}
}
else if (st){
f.setProperties({
fillColor: st.getFill().getColor(),
strokeColor: st.getStroke().getColor()
});
st.getFill().setColor('rgba(255, 255, 255, 0.5)');
st.getStroke().setColor('blue');
}
}
i3GEO.desenho.layergrafico.getSource().changed();
},
unselTodos : function() {
var i, n, f, s, st;
s = i3GEO.desenho.layergrafico.getSource();
n = i3GEO.editorOL.idsSelecionados.length;
for(i=0; i 0) {
i3GEO.desenho.layergrafico.removeFeatures(i3GEO.desenho.layergrafico.features);
i3GEO.desenho.layergrafico.addFeatures(i3GEO.editorOL.backup.features);
}
if (document.getElementById("panellistagEditor")) {
i3GEO.editorOL.listaGeometrias();
}
// i3GEO.editorOL.backup.removeFeatures(i3GEO.editorOL.backup.features);
},
substituiFeaturesSel : function(f) {
i3GEO.editorOL.removeFeaturesSel();
var fwkt = new ol.format.WKT();
f = fwkt.readFeatures(f)[0];
f.setStyle(
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(' + i3GEO.editorOL.simbologia.strokeColor + ',' + i3GEO.editorOL.simbologia.opacidade + ')',
width: i3GEO.editorOL.simbologia.strokeWidth
}),
fill: new ol.style.Fill({
color: 'rgba(' + i3GEO.editorOL.simbologia.fillColor + ',' + i3GEO.editorOL.simbologia.opacidade + ')'
})
})
);
f.setId(i3GEO.util.uid());
i3GEO.desenho.layergrafico.getSource().addFeature(f);
},
adicionaFeatureWkt : function(wkt, atributos) {
var f, fwkt = new OpenLayers.Format.WKT();
if (atributos.externalGraphic && atributos.externalGraphic != "") {
var style_mark = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
style_mark.externalGraphic = atributos.externalGraphic;
style_mark.graphicWidth = atributos.graphicWidth;
style_mark.graphicHeight = atributos.graphicHeight;
style_mark.fillOpacity = atributos.opacidade;
f = fwkt.read(wkt);
f["attributes"] = atributos;
f["style"] = style_mark;
} else {
f = fwkt.read(wkt);
f["attributes"] = atributos;
}
i3GEO.desenho.layergrafico.addFeatures([
f
]);
if (document.getElementById("panellistagEditor")) {
i3GEO.editorOL.listaGeometrias();
}
},
flashFeaturesI : function(index) {
i3GEO.editorOL.flashFeatures([
i3GEO.desenho.layergrafico.features[index]
], 0);
},
flashFeatures : function(features, index) {
if (!index) {
index = 0;
}
var current = features[index];
if (current && current.layer === i3GEO.desenho.layergrafico) {
i3GEO.desenho.layergrafico.drawFeature(features[index], "select");
}
var prev = features[index - 1];
if (prev && prev.layer === i3GEO.desenho.layergrafico) {
i3GEO.desenho.layergrafico.drawFeature(prev, "default");
}
++index;
if (index <= features.length) {
window.setTimeout(function() {
i3GEO.editorOL.flashFeatures(features, index);
}, 75);
}
},
selFeature : function(id) {
var s,f;
s = i3GEO.desenho.layergrafico.getSource();
f = s.getFeatureById(id);
if(!i3GEO.util.in_array(id,i3GEO.editorOL.idsSelecionados)){
i3GEO.editorOL.idsSelecionados.push(id);
f.setProperties({
fillColor: f.getStyle().getFill().getColor(),
strokeColor: f.getStyle().getStroke().getColor(),
externalGraphic: ""
});
f.getStyle().getFill().setColor('rgba(255, 255, 255, 0.5)');
f.getStyle().getStroke().setColor('blue');
s.changed();
}
},
carregajts : function(funcao) {
if (i3GEO.configura) {
i3GEO.util.scriptTag(i3GEO.configura.locaplic + "/pacotes/jsts/lib/jsts.js", funcao, "i3GEOjts", true);
} else {
i3GEO.util.scriptTag("../pacotes/jsts/lib/jsts.js", funcao, "i3GEOjts", true);
}
},
trazParaFrente : function() {
var s, i, nsel, id, clone;
s = i3GEO.desenho.layergrafico.getSource();
nsel = i3GEO.editorOL.idsSelecionados.length;
for(i=0; i