if (typeof (i3GEOF) === 'undefined') {
var i3GEOF = {};
}
i3GEOF.distancia =
{
position: [150,0],
/**
* Armazena os pontos clicados para realizar os calculos
*/
pontos : {},
/**
* Armazena o WKT da ultima linha
*/
ultimoWkt : "",
/**
* Armazena a ultima medida
*/
ultimaMedida : "",
renderFunction: i3GEO.janela.formModal,
_parameters : {
"mustache": "",
"idContainer": "i3GEOdistanciaContainer",
"namespace": "distancia"
},
start : function(){
var p = this._parameters,
i3f = this,
t1 = i3GEO.configura.locaplic + "/ferramentas/"+p.namespace+"/template_mst.html";
if(p.mustache === ""){
i3GEO.janela.abreAguarde();
$.get(t1).done(function(r1) {
i3GEO.janela.fechaAguarde();
p.mustache = r1;
i3f.html();
}).fail(function(data) {
i3GEO.janela.fechaAguarde();
i3GEO.janela.snackBar({content: "Erro. " + data.status, style:'red'});
i3f.destroy();
});
} else {
i3f.html();
}
},
destroy: function(){
//nao use this aqui
i3GEOF.distancia.renderFunction.call();
i3GEO.analise.pontos = {
xpt : [],
ypt : []
};
i3GEOF.distancia.ultimaMedida = "";
i3GEOF.distancia[i3GEO.Interface["ATUAL"]].fechaJanela();
},
html:function() {
var p = this._parameters,
i3f = this,
hash = {
locaplic: i3GEO.configura.locaplic,
namespace: p.namespace,
idContainer: p.idContainer,
caixaDeEstilos: i3GEO.desenho.caixaEstilos(),
...i3GEO.idioma.objetoIdioma(i3f.dicionario)
};
i3f.renderFunction.call(
this,
{
texto: Mustache.render(p.mustache, hash),
header: "",
onclose: i3f.destroy
});
i3GEO.eventos.cliquePerm.desativa();
i3GEOF.distancia[i3GEO.Interface["ATUAL"]].inicia();
i3GEO.janela.snackBar({content: $trad("inicia",i3f.dicionario)});
},
perfil: function (){
var js = i3GEO.configura.locaplic + "/ferramentas/perfil/dependencias.php", temp = function() {
i3GEOF.perfil.iniciaJanelaFlutuante(i3GEO.analise.pontos);
};
i3GEO.util.scriptTag(js, temp, "i3GEOF.perfil_script");
},
isOn : function() {
if($i("i3GEOF.distancia")){
return true;
} else {
return false;
}
},
/**
* Converte a lista de pontos em WKT
*/
pontos2wkt : function() {
var pontos = [], x = i3GEOF.distancia.pontos.xpt, y = i3GEOF.distancia.pontos.ypt, n = x.length, i;
for (i = 0; i < n; i++) {
pontos.push(x[i] + " " + y[i]);
}
return "LINESTRING(" + pontos.join(",") + ")";
},
removeFiguras : function(){
i3GEOF.distancia[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.distancia.openlayers.draw);
i3GEOF.distancia.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() {
i3GEOF.distancia.openlayers.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.estiloPadrao = "normal";
var m = i3GEOF.distancia.openlayers;
i3GEO.desenho[i3GEO.Interface["ATUAL"]].inicia();
m.removeControle();
m.draw = new ol.interaction.Draw({
type : "LineString"
});
i3GEO.Interface.openlayers.parametrosMap.interactions[0].setActive(false);
m.draw.on("drawend", function(evt) {
evt.feature.setProperties({
origem : "medeDistancia"
});
var m = i3GEOF.distancia.openlayers;
evt.feature.setStyle(
new ol.style.Style({
stroke: new ol.style.Stroke({
color: i3GEO.desenho.estilos[i3GEO.desenho.estiloPadrao].linecolor,
width: 5
})
})
);
i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature);
m.draw.setActive(false);
m.draw.setActive(true);
});
m.draw.on('drawstart', function(evt) {
i3GEOF.distancia.pontos = {
xpt : [],
ypt : [],
dist : []
};
//usado no perfil
i3GEO.analise.pontos = {
xpt : [],
ypt : []
};
var m = i3GEOF.distancia.openlayers,
sketch = evt.feature;
m.estilo = sketch.getStyle();
m.numpontos = 1;
m.featureListener = sketch.getGeometry().on('change', function(evt) {
var ponto,
geom = evt.target,
coords = geom.getCoordinates(),
n = coords.length,
m = i3GEOF.distancia.openlayers;
ponto = new ol.geom.Point(coords[n-1]);
if(m.numpontos === n-1){
//clicou
m.numpontos = n;
m.point(ponto);
}
else{
m.modify(ponto);
}
});
});
i3geoOL.addInteraction(m.draw);
},
modify : function(point) {
var temp, n, x1, y1, x2, y2, trecho, parcial, direcao,
coord = point.getCoordinates();
n = i3GEOF.distancia.pontos.ypt.length;
if (n > 0) {
x1 = i3GEOF.distancia.pontos.xpt[n - 1];
y1 = i3GEOF.distancia.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];
}
//console.info(x1+" "+y1+" "+x2+" "+y2)
trecho = i3GEO.calculo.distancia(x1, y1, x2, y2);
parcial = i3GEOF.distancia.openlayers.somaDist();
direcao = i3GEO.calculo.direcao(x1, y1, x2, y2);
direcao = i3GEO.calculo.dd2dms(direcao, direcao);
direcao = direcao[0];
i3GEOF.distancia.openlayers.mostraParcial(trecho, parcial, direcao);
}
},
point : function(point) {
i3GEO.eventos.cliquePerm.desativa();
var n, x1, y1, x2, y2, trecho, temp, circ, label, raio,
estilo = i3GEO.desenho.estilos[i3GEO.desenho.estiloPadrao],
coord = point.getCoordinates(),
total = 0;
i3GEOF.distancia.pontos.xpt.push(coord[0]);
i3GEOF.distancia.pontos.ypt.push(coord[1]);
i3GEO.analise.pontos.xpt.push(coord[0]);
i3GEO.analise.pontos.ypt.push(coord[1]);
n = i3GEOF.distancia.pontos.ypt.length;
if (n > 1) {
x1 = i3GEOF.distancia.pontos.xpt[n - 2];
y1 = i3GEOF.distancia.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.distancia.pontos.dist.push(trecho);
total = i3GEOF.distancia.openlayers.somaDist();
i3GEOF.distancia.openlayers.mostraTotal(trecho, total);
i3GEOF.distancia.ultimoWkt = i3GEOF.distancia.pontos2wkt();
// raio
if ($i("pararraios") && $i("pararraios").checked === true) {
temp = i3GEO.util.projGeo2OSM(new ol.geom.Point([x1*1, y1*1]));
circ = new ol.Feature({
geometry: new ol.geom.Circle(temp.getCoordinates(),raio)
});
circ.setProperties({
origem : "medeDistanciaExcluir"
});
circ.setStyle(
new ol.style.Style({
stroke: new ol.style.Stroke({
color: estilo.circcolor,
width: 1
}),
zIndex: 2
})
);
i3GEO.desenho.layergrafico.getSource().addFeature(circ);
}
// desenha ponto
if ($i("parartextos") && $i("parartextos").checked === true) {
label = new ol.Feature({
geometry: i3GEO.util.projGeo2OSM(new ol.geom.Point([x2*1, y2*1]))
});
label.setProperties({
origem : "medeDistanciaExcluir"
});
label.setStyle(
new ol.style.Style({
image: new ol.style.Circle({
radius: 3,
fill: new ol.style.Fill({
color: estilo.circcolor
}),
stroke: new ol.style.Stroke({
color: estilo.circcolor,
width: 1
})
}),
text: new ol.style.Text({
text : $.number(trecho,3,$trad("dec"),$trad("mil")),
font: 'Bold 14px Arial',
textAlign: 'left',
stroke: new ol.style.Stroke({
color: 'white',
width: 1
}),
fill: new ol.style.Fill({
color: estilo.textcolor
}),
zIndex: 2000
})
})
);
i3GEO.desenho.layergrafico.getSource().addFeature(label);
}
}
},
/**
* Soma os valores de distancia guardados em pontos.dist
*/
somaDist : function() {
var n, i, total = 0;
n = i3GEOF.distancia.pontos.dist.length;
for (i = 0; i < n; i++) {
total += i3GEOF.distancia.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(false);
var m = i3GEOF.distancia.openlayers;
ol.Observable.unByKey(m.featureListener);
m.featureListener = null;
m.removeControle();
m.numpontos = 0;
i3GEO.eventos.cliquePerm.ativa();
i3GEOF.distancia.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 === "medeDistancia" || f.getProperties().origem === "medeDistanciaExcluir") {
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(trecho, total) {
var mostra = $i("mostradistancia_calculo"), texto;
if (mostra) {
texto =
"Total
" + $trad("x96")
+ " km: "
+ $.number(total,3,$trad("dec"),$trad("mil"))
+ "
"
+ $trad("x96")
+ " m: "
+ $.number((total * 1000),2,$trad("dec"),$trad("mil"))
+ "