392 lines
16 KiB
HTML
392 lines
16 KiB
HTML
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
|
||
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
||
|
||
<script>
|
||
L_NO_TOUCH = false;
|
||
L_DISABLE_3D = false;
|
||
</script>
|
||
|
||
<style>html, body {width: 100%;height: 100%;margin: 0;padding: 0;}</style>
|
||
<style>#map {position:absolute;top:0;bottom:0;right:0;left:0;}</style>
|
||
<script src="folium/leaflet.js"></script>
|
||
<script src="folium/jquery-3.7.1.min.js"></script>
|
||
<script src="folium/bootstrap.bundle.min.js"></script>
|
||
<script src="folium/leaflet.awesome-markers.js"></script>
|
||
<link rel="stylesheet" href="folium/leaflet.css"/>
|
||
<link rel="stylesheet" href="folium/bootstrap.min.css"/>
|
||
<link rel="stylesheet" href="folium/bootstrap.min.css"/>
|
||
<link rel="stylesheet" href="folium/all.min.css"/>
|
||
<link rel="stylesheet" href="folium/leaflet.awesome-markers.css"/>
|
||
<link rel="stylesheet" href="folium/leaflet.awesome.rotate.min.css"/>
|
||
|
||
<meta name="viewport" content="width=device-width,
|
||
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||
<style>
|
||
#map_9558959a04ba909ac452b2d760d4fcd2 {
|
||
position: relative;
|
||
width: 100.0%;
|
||
height: 100.0%;
|
||
left: 0.0%;
|
||
top: 0.0%;
|
||
}
|
||
.leaflet-container { font-size: 1rem; }
|
||
</style>
|
||
|
||
</head>
|
||
<body>
|
||
|
||
|
||
<div class="folium-map" id="map_9558959a04ba909ac452b2d760d4fcd2" ></div>
|
||
|
||
</body>
|
||
<script>
|
||
|
||
|
||
var map_9558959a04ba909ac452b2d760d4fcd2 = L.map(
|
||
"map_9558959a04ba909ac452b2d760d4fcd2",
|
||
{
|
||
center: [-22.178952583333334, -47.37227583333333],
|
||
crs: L.CRS.EPSG3857,
|
||
zoom: 12,
|
||
zoomControl: true,
|
||
preferCanvas: false,
|
||
}
|
||
);
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
var trajetosSelecionados = {};
|
||
var RuasSelecionadas = [];
|
||
function enviarSelecaoParaServidor() {
|
||
client.publish("selecao_ruas_mapa", JSON.stringify(RuasSelecionadas), function (err) {
|
||
/*if (!err) {
|
||
console.log("Mensagem publicada com sucesso");
|
||
} else {
|
||
console.error("Falha ao publicar mensagem", err);
|
||
}*/
|
||
});
|
||
}
|
||
function geo_json_2d5ec7ea69fca7db0e7a7aaa1c4336e5_onEachFeature(feature, layer) {
|
||
layer.on({
|
||
|
||
click: function(e) {
|
||
// Verificar se o trajeto j<> est<73> selecionado
|
||
if (trajetosSelecionados[feature.id]) {
|
||
// Se j<> est<73> selecionado, reverta para a cor original e remova da sele<6C><65>o
|
||
e.target.setStyle({
|
||
color: '#3388ff' // Cor original
|
||
});
|
||
delete trajetosSelecionados[feature.id];
|
||
RuasSelecionadas.splice(RuasSelecionadas.indexOf(feature.id), 1);
|
||
} else {
|
||
// Se n<>o est<73> selecionado, mude a cor para indicar sele<6C><65>o e adicione ao objeto de sele<6C><65>o
|
||
e.target.setStyle({
|
||
color: 'blue' // Cor de sele<6C><65>o
|
||
});
|
||
trajetosSelecionados[feature.id] = true;
|
||
RuasSelecionadas.push(feature.id);
|
||
}
|
||
enviarSelecaoParaServidor();
|
||
}/*, mouseover: function(e) {
|
||
// Mostrar tooltip com o ID da geometria quando o mouse passar sobre a linha
|
||
var tooltip = L.tooltip({
|
||
direction: 'auto', // Leaflet determina a melhor posi<73><69>o
|
||
sticky: true // Faz com que o tooltip siga o cursor do mouse
|
||
})
|
||
.setContent('Rua ' + feature.id); // Define o conte<74>do do tooltip
|
||
|
||
// Abre o tooltip na posi<73><69>o atual do mouse
|
||
var latLng = e.latlng;
|
||
tooltip.setLatLng(latLng);
|
||
layer.bindTooltip(tooltip).openTooltip(latLng);
|
||
}*/
|
||
});
|
||
};
|
||
var geo_json_2d5ec7ea69fca7db0e7a7aaa1c4336e5 = L.geoJson(null, {
|
||
onEachFeature: geo_json_2d5ec7ea69fca7db0e7a7aaa1c4336e5_onEachFeature,
|
||
|
||
});
|
||
|
||
function geo_json_2d5ec7ea69fca7db0e7a7aaa1c4336e5_add (data) {
|
||
geo_json_2d5ec7ea69fca7db0e7a7aaa1c4336e5
|
||
.addData(data);
|
||
}
|
||
geo_json_2d5ec7ea69fca7db0e7a7aaa1c4336e5_add({"features": [{"geometry": {"coordinates": [[-47.372156833333335, -22.178973166666665], [-47.372197666666665, -22.178952], [-47.37225933333333, -22.178925833333334], [-47.372304666666665, -22.178904666666668], [-47.372361833333336, -22.178876166666665]], "id": null, "type": "LineString"}, "id": 0, "properties": {"Dist1": 0, "Dist2": 0, "Id": "1", "Length": 23.747936168010394, "Name": "Projeto"}, "type": "Feature"}, {"geometry": {"coordinates": [[-47.3723795, -22.178883333333335], [-47.372341166666665, -22.178902666666666], [-47.37229466666667, -22.178925666666668], [-47.372234666666664, -22.1789555], [-47.372178166666664, -22.178984833333335]], "id": null, "type": "LineString"}, "id": 1, "properties": {"Dist1": 0, "Dist2": 0, "Id": "2", "Length": 23.891304512285874, "Name": "Projeto"}, "type": "Feature"}, {"geometry": {"coordinates": [[-47.372177666666666, -22.1790005], [-47.3722225, -22.178979166666668], [-47.3722845, -22.178951166666668], [-47.3723305, -22.17893116666667], [-47.372374666666666, -22.178911]], "id": null, "type": "LineString"}, "id": 2, "properties": {"Dist1": 0, "Dist2": 0, "Id": "3", "Length": 23.838775018394195, "Name": "Projeto"}, "type": "Feature"}, {"geometry": {"coordinates": [[-47.37239483333333, -22.178915166666666], [-47.37235066666667, -22.178935166666665], [-47.37228916666667, -22.178960833333335], [-47.372228666666665, -22.17898883333333], [-47.372188, -22.179009166666667]], "id": null, "type": "LineString"}, "id": 3, "properties": {"Dist1": 0, "Dist2": 0, "Id": "4", "Length": 23.760554463105805, "Name": "Projeto"}, "type": "Feature"}, {"geometry": {"coordinates": [[-47.37217866666667, -22.179029], [-47.372224833333334, -22.179004], [-47.372283, -22.178976166666665], [-47.37232683333333, -22.178956333333332], [-47.37238383333333, -22.1789295]], "id": null, "type": "LineString"}, "id": 4, "properties": {"Dist1": 0, "Dist2": 0, "Id": "5", "Length": 23.888166936433826, "Name": "Projeto"}, "type": "Feature"}], "type": "FeatureCollection"});
|
||
|
||
|
||
|
||
geo_json_2d5ec7ea69fca7db0e7a7aaa1c4336e5.addTo(map_9558959a04ba909ac452b2d760d4fcd2);
|
||
|
||
</script>
|
||
|
||
<script>
|
||
function trajeto_json_onEachFeature(feature, layer) {
|
||
layer.on({
|
||
});
|
||
};
|
||
var trajeto_json = L.geoJson(null, {
|
||
onEachFeature: trajeto_json_onEachFeature,
|
||
style: function(feature) {
|
||
return {color: 'red'};
|
||
}
|
||
}
|
||
);
|
||
function trajeto_json_add (data) {
|
||
trajeto_json.addData(data);
|
||
}
|
||
trajeto_json_add({"features": []});
|
||
|
||
trajeto_json.addTo(map_9558959a04ba909ac452b2d760d4fcd2);
|
||
|
||
function adicionarGeometria(novaGeometria) {
|
||
trajeto_json.addData(novaGeometria);
|
||
}
|
||
|
||
function saoCoordenadasIguais(coord1, coord2, tolerancia) {
|
||
return Math.abs(coord1[0] - coord2[0]) < tolerancia && Math.abs(coord1[1] - coord2[1]) < tolerancia;
|
||
}
|
||
|
||
function adicionarCoordenada(idGeometria, novaCoordenada) {
|
||
var feature = trajeto_json.toGeoJSON().features.find(f => f.id === idGeometria);
|
||
if (feature) {
|
||
var ultima = [0.0,0.0];
|
||
if (feature.geometry.coordinates.length > 0) {
|
||
ultima = feature.geometry.coordinates[feature.geometry.coordinates.length - 1];
|
||
}
|
||
if (!saoCoordenadasIguais(ultima, novaCoordenada, 0.000001)) {
|
||
feature.geometry.coordinates.push(novaCoordenada);
|
||
var ft = feature;
|
||
trajeto_json.clearLayers();
|
||
trajeto_json.addData(ft);
|
||
}
|
||
|
||
} else {
|
||
console.log("Feature com ID " + idGeometria + " n<>o encontrada.");
|
||
}
|
||
}
|
||
|
||
adicionarGeometria({
|
||
"type": "Feature",
|
||
"geometry": {
|
||
"type": "LineString",
|
||
"coordinates": []
|
||
},
|
||
"properties": {"Dist1": 0.0, "Dist2": 0.0, "Id": 1517, "Length": 21.724783283, "Name": "Projeto"},
|
||
"id": "Tj"
|
||
});
|
||
|
||
</script>
|
||
|
||
<script>
|
||
function trajeto_dinamico_json_onEachFeature(feature, layer) {
|
||
layer.on({
|
||
});
|
||
};
|
||
var trajeto_dinamico_json = L.geoJson(null, {
|
||
onEachFeature: trajeto_dinamico_json_onEachFeature,
|
||
style: function(feature) {
|
||
return {color: 'green'};
|
||
}
|
||
}
|
||
);
|
||
function trajeto_dinamico_json_add (data) {
|
||
trajeto_dinamico_json.addData(data);
|
||
}
|
||
trajeto_dinamico_json_add({"features": []});
|
||
|
||
trajeto_dinamico_json.addTo(map_9558959a04ba909ac452b2d760d4fcd2);
|
||
|
||
function adicionarGeometriaDinamica(novaGeometria) {
|
||
trajeto_dinamico_json.addData(novaGeometria);
|
||
}
|
||
|
||
function adicionarCoordenadaDinamica(idGeometria, coordenadas) {
|
||
var feature = trajeto_dinamico_json.toGeoJSON().features.find(f => f.id === idGeometria);
|
||
if (feature) {
|
||
feature.geometry.coordinates = [];
|
||
coordenadas.forEach(x => feature.geometry.coordinates.push([x.longitude, x.latitude]));
|
||
var ft = feature;
|
||
trajeto_dinamico_json.clearLayers();
|
||
trajeto_dinamico_json.addData(ft);
|
||
} else {
|
||
console.log("Feature com ID " + idGeometria + " nao encontrada.");
|
||
}
|
||
}
|
||
|
||
adicionarGeometriaDinamica({
|
||
"type": "Feature",
|
||
"geometry": {
|
||
"type": "LineString",
|
||
"coordinates": []
|
||
},
|
||
"properties": {"Dist1": 0.0, "Dist2": 0.0, "Id": 1517, "Length": 21.724783283, "Name": "Projeto"},
|
||
"id": "TjD"
|
||
});
|
||
|
||
</script>
|
||
|
||
<script src="folium/mqtt.min.js"></script>
|
||
<script src="folium/leaflet.rotatedMarker.js"></script>
|
||
<script>
|
||
let posicaoAtualEquipamento = {
|
||
lat: 0,
|
||
long: 0
|
||
};
|
||
|
||
let posicaoAtualBase = {
|
||
lat: 0,
|
||
long: 0
|
||
};
|
||
|
||
var customIcon = L.icon({
|
||
iconUrl: 'folium/images/position_marker.png',
|
||
iconSize: [32, 32],
|
||
iconAnchor: [16, 16],
|
||
popupAnchor: [0, -16]
|
||
});
|
||
|
||
var marcadorEquipamento = L.marker([0, 0], {
|
||
icon: customIcon
|
||
}).addTo(map_9558959a04ba909ac452b2d760d4fcd2);
|
||
|
||
var marcadorBase = L.marker([0, 0], {}).addTo(map_9558959a04ba909ac452b2d760d4fcd2);
|
||
var icon = L.AwesomeMarkers.icon(
|
||
{"extraClasses": "fa-rotate-0", "icon": "info-sign", "iconColor": "white", "markerColor": "red", "prefix": "glyphicon"}
|
||
);
|
||
marcadorBase.setIcon(icon);
|
||
|
||
// Conectar ao broker MQTT
|
||
const client = mqtt.connect('ws://localhost:9001'); // Use wss para conex<65>o segura
|
||
|
||
// Quando conectado, inscreva-se no t<>pico desejado
|
||
client.on('connect', function () {
|
||
console.log('Conectado ao broker MQTT');
|
||
|
||
// Inscrever-se no t<>pico
|
||
client.subscribe('coordenadas_gps', function (err) {
|
||
if (!err) {
|
||
console.log("Inscricao bem-sucedida no topico");
|
||
} else {
|
||
console.error("Falha na inscricao do topico", err);
|
||
}
|
||
});
|
||
client.subscribe('trajetoria_dinamica', function (err) {
|
||
if (!err) {
|
||
console.log("Inscricao bem-sucedida no topico");
|
||
} else {
|
||
console.error("Falha na inscricao do topico", err);
|
||
}
|
||
});
|
||
client.subscribe('selecao_ruas_mapa', function (err) {
|
||
if (!err) {
|
||
console.log("Inscricao bem-sucedida no topico");
|
||
} else {
|
||
console.error("Falha na inscricao do topico", err);
|
||
}
|
||
});
|
||
});
|
||
|
||
// Lidar com mensagens recebidas para o topico inscrito
|
||
client.on('message', function (topic, message) {
|
||
var dados = JSON.parse(message);
|
||
if (topic === "trajetoria_dinamica") {
|
||
adicionarCoordenadaDinamica("TjD", dados); // "Tj" <20> o ID da feature no GeoJSON
|
||
}
|
||
else if (topic === "coordenadas_gps") {
|
||
// A mensagem e um Buffer, converta para string ou objeto conforme necessario
|
||
//console.log(`Mensagem recebida no topico '${topic}': ${message.toString()}`);
|
||
|
||
var id = dados.id;
|
||
var novaLatitude = dados.latitude;
|
||
var novaLongitude = dados.longitude;
|
||
var novaPosicao = [novaLatitude, novaLongitude];
|
||
var orientacao = dados.orientacao;
|
||
var foco = dados.foco;
|
||
|
||
if (id == 1) {
|
||
marcadorBase.setLatLng(novaPosicao);
|
||
|
||
// Calcular angulo de rotacao
|
||
var angulo = dados.orientacao;
|
||
|
||
posicaoAtualBase.lat = novaPosicao[0];
|
||
posicaoAtualBase.long = novaPosicao[1];
|
||
|
||
// Rotacionar o marcador para o angulo calculado
|
||
marcadorBase.setRotationAngle(angulo);
|
||
}
|
||
else {
|
||
marcadorEquipamento.setLatLng(novaPosicao);
|
||
|
||
// Calcular angulo de rotacao
|
||
var angulo = dados.orientacao;
|
||
|
||
posicaoAtualEquipamento.lat = novaPosicao[0];
|
||
posicaoAtualEquipamento.long = novaPosicao[1];
|
||
|
||
// Rotacionar o marcador para o angulo calculado
|
||
marcadorEquipamento.setRotationAngle(angulo);
|
||
|
||
adicionarCoordenada("Tj", [novaLongitude, novaLatitude]);
|
||
}
|
||
|
||
if (foco) {
|
||
map_9558959a04ba909ac452b2d760d4fcd2.setView(novaPosicao, map_9558959a04ba909ac452b2d760d4fcd2.getZoom());
|
||
}
|
||
|
||
}
|
||
else if (topic === 'selecao_ruas_mapa') {
|
||
var selecionadas = dados;
|
||
if (selecionadas.length != RuasSelecionadas.length) {
|
||
atualizarSelecaoRuas(selecionadas);
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
// Fun<75><6E>o para atualizar a sele<6C><65>o das ruas e mudar a cor no mapa
|
||
function atualizarSelecaoRuas(selecionadas) {
|
||
selecionadas = JSON.parse(selecionadas);
|
||
RuasSelecionadas = Array.isArray(selecionadas) ? [...selecionadas] : [];
|
||
geo_json_2d5ec7ea69fca7db0e7a7aaa1c4336e5.eachLayer(function (layer) {
|
||
if (RuasSelecionadas.includes(parseInt(layer.feature.id))) {
|
||
layer.setStyle({ color: 'blue' });
|
||
} else {
|
||
layer.setStyle({ color: '#3388ff' }); // Cor original
|
||
}
|
||
});
|
||
}
|
||
|
||
function calcularOrientacao(P1latitude, P1longitude, P2latitude, P2longitude) {
|
||
// Converter latitudes e longitudes de graus para radianos
|
||
const latA = P1latitude * (Math.PI / 180.0);
|
||
const lonA = P1longitude * (Math.PI / 180.0);
|
||
const latB = P2latitude * (Math.PI / 180.0);
|
||
const lonB = P2longitude * (Math.PI / 180.0);
|
||
|
||
// Calcular a diferen<65>a de longitude
|
||
const deltaLon = lonB - lonA;
|
||
|
||
// Calcular a dire<72><65>o
|
||
const y = Math.sin(deltaLon) * Math.cos(latB);
|
||
const x = Math.cos(latA) * Math.sin(latB) - Math.sin(latA) * Math.cos(latB) * Math.cos(deltaLon);
|
||
const direcaoRadianos = Math.atan2(y, x);
|
||
|
||
// Converter a dire<72><65>o de radianos para graus
|
||
let direcaoGraus = direcaoRadianos * (180.0 / Math.PI);
|
||
|
||
// Normalizar a dire<72><65>o para que esteja no intervalo de 0 a 360 graus
|
||
direcaoGraus = (direcaoGraus + 360) % 360;
|
||
|
||
return direcaoGraus;
|
||
}
|
||
|
||
</script>
|
||
</html> |