Added code for building data files

This commit is contained in:
Martin Asprusten
2025-07-12 11:27:24 +02:00
parent 32ed39c61a
commit 4c914996a2
5 changed files with 586 additions and 14 deletions
+17 -14
View File
@@ -4,6 +4,7 @@ import proj4 from 'proj4';
import type { Endpoint, Message, PathSegment, Polygon, SearchAreaResultEntry } from '../../interfaces';
var dataLoaded = false;
var fileEpsg: string;
var module: MainModule | undefined = undefined;
function sendErrorMessage(error: string): void {
@@ -19,9 +20,9 @@ function createCMultiPolygon(module: MainModule, polygons: Polygon[]): MultiPoly
let cRing = new module.Ring();
ring.coordinates.forEach(coordinate => {
let polygonCoordinate = new module.PolygonCoordinate();
let utmCoordinates = proj4('EPSG:4326', 'EPSG:32633', [coordinate.longitude, coordinate.latitude]);
polygonCoordinate.x = utmCoordinates[0];
polygonCoordinate.y = utmCoordinates[1];
let fileCoordinates = proj4('EPSG:4326', fileEpsg, [coordinate.longitude, coordinate.latitude]);
polygonCoordinate.x = fileCoordinates[0];
polygonCoordinate.y = fileCoordinates[1];
cRing.push_back(polygonCoordinate);
});
cPolygon.push_back(cRing);
@@ -36,8 +37,8 @@ function getAreaSearchResults(searchedNodes: AreaSearchEntries): SearchAreaResul
for (var i = 0; i < searchedNodes.size(); i++) {
let searchedNode = searchedNodes.get(i);
if (searchedNode != null) {
let utmCoordinates = [searchedNode.positionX, searchedNode.positionY];
let lngLatCoordinates = proj4('EPSG:32633', 'EPSG:4326', utmCoordinates);
let fileCoordinates = [searchedNode.positionX, searchedNode.positionY];
let lngLatCoordinates = proj4(fileEpsg, 'EPSG:4326', fileCoordinates);
searchResults.push({
nodeId: searchedNode.nodeId,
latitude: lngLatCoordinates[1],
@@ -61,6 +62,8 @@ onmessage = async (e) => {
module.loadData('roads.dat');
dataLoaded = true;
fileEpsg = module.getEpsgCode();
let returnMessage: Message = {dataLoaded: {}}
postMessage(returnMessage);
return;
@@ -74,11 +77,11 @@ onmessage = async (e) => {
if (message.findClosestNode != null) {
let lngLatCoordinates = [message.findClosestNode.longitude, message.findClosestNode.latitude];
let utmCoordinates = proj4('EPSG:4326', 'EPSG:32633', lngLatCoordinates);
let node = module.findClosestNode(utmCoordinates[0], utmCoordinates[1]);
let fileCoordinates = proj4('EPSG:4326', fileEpsg, lngLatCoordinates);
let node = module.findClosestNode(fileCoordinates[0], fileCoordinates[1]);
let nodeUtmCoordinates = [node.positionX, node.positionY];
let nodeLngLatCoordinates = proj4('EPSG:32633', 'EPSG:4326', nodeUtmCoordinates);
let nodeFileCoordinates = [node.positionX, node.positionY];
let nodeLngLatCoordinates = proj4(fileEpsg, 'EPSG:4326', nodeFileCoordinates);
let returnMessage: Message = {
foundClosestNode: {
@@ -115,7 +118,7 @@ onmessage = async (e) => {
return;
}
let coordinates = [nodeData.positionX, nodeData.positionY];
let lngLatCoordinates = proj4('EPSG:32633', 'EPSG:4326', coordinates);
let lngLatCoordinates = proj4(fileEpsg, 'EPSG:4326', coordinates);
endpoints.push({
nodeId: nodeData.nodeId,
latitude: lngLatCoordinates[1],
@@ -146,11 +149,11 @@ onmessage = async (e) => {
if (!previousPoint) {
continue;
}
let previousUtm = [previousPoint.positionX, previousPoint.positionY];
let currentUtm = [currentPoint.positionX, currentPoint.positionY];
let previousFileCoordinates = [previousPoint.positionX, previousPoint.positionY];
let currentFileCoordinates = [currentPoint.positionX, currentPoint.positionY];
let previousLngLat = proj4('EPSG:32633', 'EPSG:4326', previousUtm);
let currentLngLat = proj4('EPSG:32633', 'EPSG:4326', currentUtm);
let previousLngLat = proj4(fileEpsg, 'EPSG:4326', previousFileCoordinates);
let currentLngLat = proj4(fileEpsg, 'EPSG:4326', currentFileCoordinates);
let speed = Math.max(previousPoint.currentSpeed, currentPoint.currentSpeed);
let requiredSpeed = Math.max(previousPoint.requiredSpeed, currentPoint.requiredSpeed);