if (typeof (i3GEOF) === 'undefined') {
var i3GEOF = {};
}
i3GEOF.area =
{
position: [150,0],
/**
* Armazena os pontos clicados para realizar os calculos
*/
pontos : {},
/**
* Armazena o WKT da ultima linha
*/
ultimoWkt : "",
/**
* Armazena a ultima medida
*/
ultimaMedida : "",
MUSTACHE : "",
/**
* Susbtitutos para o template
*/
mustacheHash : function() {
var dicionario = i3GEO.idioma.objetoIdioma(i3GEOF.area.dicionario);
dicionario["sid"] = i3GEO.configura.sid;
dicionario["locaplic"] = i3GEO.configura.locaplic;
return dicionario;
},
inicia : function(iddiv) {
if(i3GEOF.area.MUSTACHE == ""){
$.get(i3GEO.configura.locaplic + "/ferramentas/area/template_mst.html", function(template) {
i3GEOF.area.MUSTACHE = template;
i3GEOF.area.inicia(iddiv);
});
return;
}
i3GEO.eventos.cliquePerm.desativa();
$i(iddiv).innerHTML = i3GEOF.area.html();
i3GEOF.area[i3GEO.Interface["ATUAL"]].inicia();
},
isOn : function() {
if($i("i3GEOF.area")){
return true;
} else {
return false;
}
},
/*
* Function: html
*
* Gera o código html para apresentação das opções da ferramenta
*
* Retorno:
*
* String com o código html
*/
html : function() {
var ins = Mustache.render(i3GEOF.area.MUSTACHE, i3GEOF.area.mustacheHash());
return ins;
},
/*
* Function: iniciaJanelaFlutuante
*
* Cria a janela flutuante para controle da ferramenta.
*/
iniciaJanelaFlutuante : function() {
var minimiza, cabecalho, janela, divid, temp, titulo,imagemxy;
if ($i("i3GEOF.area")) {
return;
}
cabecalho = "";
minimiza = "";
// cria a janela flutuante
titulo = "" + $trad("areaAprox") + "";
janela =
i3GEO.janela.cria(
"250px",
"auto",
"",
"",
"",
titulo,
"i3GEOF.area",
false,
"hd",
cabecalho,
minimiza,
"",
true,
"",
"",
"nao",
"",
"51"
);
divid = janela[2].id;
i3GEOF.area.inicia(divid);
temp =
function() {
i3GEOF.area.pontos = {};
var janela;
i3GEO.eventos.cliquePerm.ativa();
janela = YAHOO.i3GEO.janela.manager.find("area");
if (janela) {
YAHOO.i3GEO.janela.manager.remove(janela);
janela.destroy();
}
i3GEOF.area[i3GEO.Interface["ATUAL"]].fechaJanela();
i3GEO.analise.pontos = {};
};
YAHOO.util.Event.addListener(janela[0].close, "click", temp);
imagemxy = i3GEO.util.pegaPosicaoObjeto($i(i3GEO.Interface.IDCORPO));
janela[0].moveTo(i3GEOF.area.position[0],i3GEOF.area.position[1]);
},
/*
* Function: ativaFoco
*
* Refaz a interface da ferramenta quando a janela flutuante tem seu foco ativado
*/
ativaFoco : function() {
},
/**
* Converte a lista de pontos em WKT
*/
pontos2wkt : function() {
var pontos = [], x = i3GEOF.area.pontos.xpt, y = i3GEOF.area.pontos.ypt, n = x.length, i;
for (i = 0; i < n; i++) {
pontos.push(x[i] + " " + y[i]);
}
pontos.push(x[0] + " " + y[0]);
return "POLYGON((" + pontos.join(",") + "))";
},
removeFiguras : function(){
i3GEOF.area[i3GEO.Interface["ATUAL"]].removeFiguras();
},
/**
* Funcoes especificas da interface openlayers
*/
openlayers : {
draw : "",
estilo: "",
featureListener : null,
//numero de pontos da geometria atual
//utilizado para saber se houve um clique ou nao
numpontos : 0,
removeControle : function() {
i3geoOL.removeInteraction(i3GEOF.area.openlayers.draw);
i3GEOF.area.openlayers.draw = "";
},
/**
* Inicializa o processo Cria a variavel para guardar os pontos Executa a funcao de inicializacao do desenho, que cria o
* layer para receber os graficos
*/
inicia : function() {
var m = i3GEOF.area.openlayers;
m.estilo = new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#ffcc33',
width: 5
}),
fill: new ol.style.Fill({
color: 'rgba(255, 153, 0, 0.8)'
})
});
i3GEO.desenho[i3GEO.Interface["ATUAL"]].inicia();
m.removeControle();
m.draw = new ol.interaction.Draw({
type : "Polygon"
});
i3GEO.Interface.openlayers.parametrosMap.interactions[0].setActive(false);
m.draw.on("drawend", function(evt) {
evt.feature.setProperties({
origem : "i3GeoMedeArea"
});
var m = i3GEOF.area.openlayers;
i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature);
m.draw.setActive(false);
m.draw.setActive(true);
});
m.draw.on('drawstart', function(evt) {
i3GEOF.area.pontos = {
xpt : [],
ypt : [],
dist : []
};
i3GEO.analise.pontos = {
xpt : [],
ypt : []
};
var m = i3GEOF.area.openlayers,
sketch = evt.feature;
m.estilo = sketch.getStyle();
m.numpontos = 2;
m.featureListener = sketch.getGeometry().on('change', function(evt) {
var ponto,
geom = evt.target,
coords = geom.getLinearRing(0).getCoordinates(),
n = coords.length,
m = i3GEOF.area.openlayers;
ponto = new ol.geom.Point(coords[n-2]);
//console.info(coords)
if(m.numpontos === n-1){
//clicou
m.numpontos = n;
m.point(ponto,geom);
}
else{
m.modify(ponto,geom);
}
});
});
i3geoOL.addInteraction(m.draw);
},
modify : function(point,geom) {
var temp,sourceProj,coordinates,wgs84Sphere, per, area, n, x1, y1, x2, y2, trecho, direcao,
coord = point.getCoordinates();
n = i3GEOF.area.pontos.ypt.length;
if (n > 1) {
x1 = i3GEOF.area.pontos.xpt[n - 1];
y1 = i3GEOF.area.pontos.ypt[n - 1];
x2 = coord[0];
y2 = coord[1];
// projeta
if (i3GEO.Interface.openlayers.googleLike) {
temp = i3GEO.util.extOSM2Geo(x1 + " " + y1 + " " + x2 + " " + y2);
temp = temp.split(" ");
x1 = temp[0];
y1 = temp[1];
x2 = temp[2];
y2 = temp[3];
}
trecho = i3GEO.calculo.distancia(x1, y1, x2, y2);
//parcial = i3GEOF.area.openlayers.somaDist();
direcao = i3GEO.calculo.direcao(x1, y1, x2, y2);
direcao = i3GEO.calculo.dd2dms(direcao, direcao);
direcao = direcao[0];
per = i3GEOF.area.openlayers.somaDist();
// soma ate o primeiro ponto
x1 = i3GEOF.area.pontos.xpt[0];
y1 = i3GEOF.area.pontos.ypt[0];
// projeta
if (i3GEO.Interface.openlayers.googleLike) {
temp = i3GEO.util.extOSM2Geo(x1 + " " + y1);
temp = temp.split(" ");
x1 = temp[0];
y1 = temp[1];
}
per += i3GEO.calculo.distancia(x1, y1, x2, y2);
//getGeodesicArea
sourceProj = i3geoOL.getView().getProjection();
geom = (geom.clone().transform(sourceProj, 'EPSG:4326'));
coordinates = geom.getLinearRing(0).getCoordinates();
wgs84Sphere = new ol.Sphere(6378137);
area = Math.abs(wgs84Sphere.geodesicArea(coordinates));
i3GEOF.area.openlayers.mostraParcial(trecho, per, area, direcao);
}
},
point : function(point,geom) {
i3GEO.eventos.cliquePerm.desativa();
var wgs84Sphere,area,coordinates,sourceProj,n, x1, y1, x2, y2, trecho, temp,
coord = point.getCoordinates(),
total = 0;
i3GEOF.area.pontos.xpt.push(coord[0]);
i3GEOF.area.pontos.ypt.push(coord[1]);
i3GEO.analise.pontos.xpt.push(coord[0]);
i3GEO.analise.pontos.ypt.push(coord[1]);
n = i3GEOF.area.pontos.ypt.length;
if (n > 1) {
x1 = i3GEOF.area.pontos.xpt[n - 2];
y1 = i3GEOF.area.pontos.ypt[n - 2];
x2 = coord[0];
y2 = coord[1];
raio = new ol.geom.LineString([[x1, y1],[x2, y2]]).getLength();
// projeta
if (i3GEO.Interface.openlayers.googleLike) {
temp = i3GEO.util.extOSM2Geo(x1 + " " + y1 + " " + x2 + " " + y2);
temp = temp.split(" ");
x1 = temp[0];
y1 = temp[1];
x2 = temp[2];
y2 = temp[3];
}
trecho = i3GEO.calculo.distancia(x1, y1, x2, y2);
i3GEOF.area.pontos.dist.push(trecho);
total = i3GEOF.area.openlayers.somaDist();
sourceProj = i3geoOL.getView().getProjection();
geom = (geom.clone().transform(sourceProj, 'EPSG:4326'));
coordinates = geom.getLinearRing(0).getCoordinates();
wgs84Sphere = new ol.Sphere(6378137);
area = Math.abs(wgs84Sphere.geodesicArea(coordinates));
i3GEOF.area.openlayers.mostraTotal(total, area);
i3GEOF.area.ultimoWkt = i3GEOF.area.pontos2wkt();
}
},
/**
* Soma os valores de distancia guardados em pontos.dist
*/
somaDist : function() {
var n, i, total = 0;
n = i3GEOF.area.pontos.dist.length;
for (i = 0; i < n; i++) {
total += i3GEOF.area.pontos.dist[i];
}
return total;
},
/**
* Fecha a janela que mostra os dados Pergunta ao usuario se os graficos devem ser removidos Os graficos sao marcados com o
* atributo "origem" Os raios e pontos sao sempre removidos
*/
fechaJanela : function() {
i3GEO.Interface.openlayers.parametrosMap.interactions[0].setActive(true);
var m = i3GEOF.area.openlayers;
ol.Observable.unByKey(m.featureListener);
m.featureListener = null;
m.removeControle();
m.numpontos = 0;
i3GEO.eventos.cliquePerm.ativa();
i3GEOF.area.openlayers.removeFiguras();
},
removeFiguras : function(){
var features, n, f, i, remover = [], temp;
features = i3GEO.desenho.layergrafico.getSource().getFeatures();
n = features.length;
for (i = 0; i < n; i++) {
f = features[i];
if (f.getProperties().origem === "i3GeoMedeArea" || f.getProperties().origem === "medeAreaExcluir") {
remover.push(f);
}
}
if (remover.length > 0) {
temp = window.confirm($trad("x94"));
if (temp) {
for (r in remover) {
i3GEO.desenho.layergrafico.getSource().removeFeature(remover[r]);
}
}
}
},
/**
* Mostra a totalizacao das linhas ja digitalizadas
*/
mostraTotal : function(per, area) {
var mostra = $i("mostraarea_calculo"), texto;
if (mostra) {
texto =
"total
" + $trad("d21at")
+ " km2: "
+ format("#.###,000", (area / 1000000).toFixed(3))
+ "
"
+ $trad("d21at")
+ " ha: "
+ format("#.###,00",(area / 10000).toFixed(2))
+ "
"
+ $trad("x98")
+ " km: "
+ format("#.###,00",(per).toFixed(2))
+ "
"
+ $trad("x25")
+ ": "
+ i3GEO.calculo.metododistancia;
mostra.innerHTML = texto + "