341 lines
18 KiB
HTML
341 lines
18 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_648581987b0328ec9ebae256b8a1dfbb {
|
||
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_648581987b0328ec9ebae256b8a1dfbb" ></div>
|
||
|
||
</body>
|
||
<script>
|
||
|
||
|
||
var map_648581987b0328ec9ebae256b8a1dfbb = L.map(
|
||
"map_648581987b0328ec9ebae256b8a1dfbb",
|
||
{
|
||
center: [-22.2133965, -47.381378416666664],
|
||
crs: L.CRS.EPSG3857,
|
||
zoom: 12,
|
||
zoomControl: true,
|
||
preferCanvas: false,
|
||
}
|
||
);
|
||
|
||
|
||
|
||
|
||
|
||
var tile_layer_c1f109314d25166dde4a722d722568a1 = L.tileLayer(
|
||
"https://tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||
{"attribution": "\u0026copy; \u003ca href=\"https://www.openstreetmap.org/copyright\"\u003eOpenStreetMap\u003c/a\u003e contributors", "detectRetina": false, "maxNativeZoom": 19, "maxZoom": 19, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}
|
||
);
|
||
|
||
|
||
tile_layer_c1f109314d25166dde4a722d722568a1.addTo(map_648581987b0328ec9ebae256b8a1dfbb);
|
||
|
||
|
||
|
||
|
||
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_bbb1ddb6da0aeff35e91f065a6140eca_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_bbb1ddb6da0aeff35e91f065a6140eca = L.geoJson(null, {
|
||
onEachFeature: geo_json_bbb1ddb6da0aeff35e91f065a6140eca_onEachFeature,
|
||
|
||
});
|
||
|
||
function geo_json_bbb1ddb6da0aeff35e91f065a6140eca_add (data) {
|
||
geo_json_bbb1ddb6da0aeff35e91f065a6140eca
|
||
.addData(data);
|
||
}
|
||
geo_json_bbb1ddb6da0aeff35e91f065a6140eca_add({"features": [{"geometry": {"coordinates": [[-47.381499166666664, -22.213093166666667], [-47.38149416666667, -22.213095833333334], [-47.3814855, -22.213100166666667], [-47.381475, -22.213104333333334], [-47.381464, -22.213109166666666], [-47.38145333333333, -22.213116333333332], [-47.381445, -22.2131235], [-47.381438, -22.213131833333332], [-47.38143216666667, -22.213141], [-47.38142633333333, -22.21315], [-47.38141916666667, -22.213158333333332], [-47.381412, -22.213166833333332], [-47.381405, -22.213175666666668], [-47.381397166666666, -22.213185], [-47.381389666666664, -22.213194333333334], [-47.38138266666667, -22.213204], [-47.38137583333334, -22.213213], [-47.381367833333336, -22.2132225], [-47.3813595, -22.213232], [-47.381352, -22.213241833333335], [-47.3813465, -22.213252833333332], [-47.38134183333333, -22.213264], [-47.381337, -22.213274666666667], [-47.381332666666665, -22.213284833333333], [-47.38132916666667, -22.213295666666667], [-47.381327166666665, -22.213306833333334], [-47.38132733333333, -22.213317666666665], [-47.381330166666665, -22.213328166666667], [-47.381334333333335, -22.213338666666665], [-47.3813385, -22.213349333333333], [-47.38134316666667, -22.213360333333334], [-47.381349, -22.213370833333332], [-47.38135483333333, -22.213380666666666], [-47.38136083333333, -22.213391], [-47.38136733333333, -22.213401166666667], [-47.3813745, -22.213410333333332], [-47.381381166666664, -22.213420833333334], [-47.38138766666667, -22.213431833333335], [-47.38139433333333, -22.213442666666666], [-47.38140033333333, -22.2134535], [-47.38140666666666, -22.213464333333334], [-47.3814135, -22.213474833333333], [-47.38142116666667, -22.213484833333332], [-47.3814275, -22.213496], [-47.381435333333336, -22.213505666666666], [-47.38144283333333, -22.213515666666666], [-47.38145, -22.2135265], [-47.3814565, -22.213537833333334], [-47.38146283333333, -22.213548833333334], [-47.3814695, -22.213559], [-47.38147816666667, -22.213569166666666], [-47.381487666666665, -22.213578], [-47.38149516666667, -22.213587], [-47.381502, -22.213596333333335], [-47.381507666666664, -22.213604333333333]], "id": null, "type": "LineString"}, "id": 0, "properties": {"Dist1": 0.0, "Dist2": 0.0, "Id": "1517", "Length": 69.0588486447104, "Name": "Projeto"}, "type": "Feature"}, {"geometry": {"coordinates": [[-47.381513166666664, -22.213679], [-47.38149133333334, -22.213692833333333], [-47.381484666666665, -22.213698166666667], [-47.381481666666666, -22.213699833333333], [-47.38148116666667, -22.2136995], [-47.381477333333336, -22.213695666666666], [-47.38147083333333, -22.2136885], [-47.381464666666666, -22.2136795], [-47.3814595, -22.213669333333332], [-47.381454166666664, -22.213659833333335], [-47.381449, -22.213650333333334], [-47.38144283333333, -22.213640666666667], [-47.381437, -22.2136315], [-47.381431166666665, -22.213622166666667], [-47.38142583333333, -22.213612166666667], [-47.38142033333333, -22.2136015], [-47.38141433333333, -22.2135915], [-47.381408666666665, -22.213581333333334], [-47.381402666666666, -22.213571666666667], [-47.381396333333335, -22.213562], [-47.38139116666667, -22.213552166666666], [-47.381384833333335, -22.2135415], [-47.38137833333333, -22.213531166666666], [-47.381372, -22.2135225], [-47.3813655, -22.213513166666665], [-47.38135833333333, -22.213503666666668], [-47.381351, -22.213494333333333], [-47.381344166666665, -22.213485666666667], [-47.381337333333335, -22.213476], [-47.381331, -22.213465833333334], [-47.38132516666667, -22.213455333333332], [-47.381318666666665, -22.213445], [-47.3813125, -22.213434833333334], [-47.381305, -22.213425], [-47.3812975, -22.213415], [-47.381290166666666, -22.2134045], [-47.381284, -22.213394], [-47.38127716666666, -22.2133835], [-47.381271166666664, -22.213373166666667], [-47.381265, -22.213363333333334], [-47.381257833333336, -22.213354166666665], [-47.381250333333334, -22.213345666666665], [-47.38124533333333, -22.213336666666667], [-47.38124366666667, -22.213326666666667], [-47.381246, -22.21331483333333], [-47.3812515, -22.213303833333335], [-47.381257833333336, -22.213293333333333], [-47.38126333333334, -22.213282666666668], [-47.38126833333333, -22.213272], [-47.381273166666666, -22.213261833333334], [-47.381278333333334, -22.213252], [-47.38128566666666, -22.213243333333335], [-47.38129416666666, -22.213234833333335], [-47.38130233333333, -22.213226166666665], [-47.38131033333333, -22.213217], [-47.381318666666665, -22.213207833333332], [-47.38132733333333, -22.213199666666668], [-47.38133633333333, -22.213190833333332], [-47.381346, -22.2131815], [-47.38135533333333, -22.213172], [-47.381364833333336, -22.213162333333333], [-47.381373833333335, -22.213152333333333], [-47.3813835, -22.213143], [-47.38139266666666, -22.213134333333333]], "id": null, "type": "LineString"}, "id": 1, "properties": {"Dist1": 0.0, "Dist2": 0.0, "Id": "1517", "Length": 79.15564220298654, "Name": "Projeto"}, "type": "Feature"}], "type": "FeatureCollection"});
|
||
|
||
|
||
|
||
geo_json_bbb1ddb6da0aeff35e91f065a6140eca.addTo(map_648581987b0328ec9ebae256b8a1dfbb);
|
||
|
||
</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_648581987b0328ec9ebae256b8a1dfbb);
|
||
|
||
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_648581987b0328ec9ebae256b8a1dfbb);
|
||
|
||
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 posicaoAtual = {
|
||
lat: 0,
|
||
long: 0
|
||
};
|
||
|
||
var customIcon = L.icon({
|
||
iconUrl: 'folium/images/position_marker.png',
|
||
iconSize: [32, 32],
|
||
iconAnchor: [16, 16],
|
||
popupAnchor: [0, -16]
|
||
});
|
||
|
||
var marcadorDinamico = L.marker([0, 0], {
|
||
icon: customIcon
|
||
}).addTo(map_648581987b0328ec9ebae256b8a1dfbb);
|
||
|
||
// 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);
|
||
}
|
||
});
|
||
});
|
||
|
||
// 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 novaLatitude = dados.latitude;
|
||
var novaLongitude = dados.longitude;
|
||
var novaPosicao = [novaLatitude, novaLongitude];
|
||
marcadorDinamico.setLatLng(novaPosicao);
|
||
|
||
// Calcular angulo de rotacao
|
||
var angulo = calcularOrientacao(novaPosicao[0], novaPosicao[1], posicaoAtual.lat, posicaoAtual.long);
|
||
|
||
posicaoAtual.lat = novaPosicao[0];
|
||
posicaoAtual.long = novaPosicao[1];
|
||
|
||
// Rotacionar o marcador para o angulo calculado
|
||
marcadorDinamico.setRotationAngle(angulo);
|
||
|
||
adicionarCoordenada("Tj", [novaLongitude, novaLatitude]);
|
||
map_648581987b0328ec9ebae256b8a1dfbb.setView(novaPosicao, map_648581987b0328ec9ebae256b8a1dfbb.getZoom());
|
||
}
|
||
|
||
});
|
||
|
||
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> |