Merge branch 'temp-branch2' into feature/main-contextmenu-line

This commit is contained in:
ISA
2024-09-02 20:46:09 +02:00
5 changed files with 79 additions and 123 deletions

View File

@@ -1,5 +1,22 @@
// utils/geometryUtils.js
/**
* Parses a point string in the format "POINT (longitude latitude)" and returns an object with latitude and longitude as numbers.
* @param {string} position - The position string in the format "POINT (longitude latitude)".
* @returns {{latitude: number, longitude: number}} An object containing the latitude and longitude as numbers.
*/
export const parsePoint = (position) => {
const [longitude, latitude] = position.slice(6, -1).split(" ");
return { latitude: parseFloat(latitude), longitude: parseFloat(longitude) };
};
/**
* Finds the closest points on a polyline to a new point.
* @param {Array} coordinates - The coordinates of the polyline.
* @param {Object} newPoint - The new point (with latitude and longitude).
* @param {Object} map - The map object.
* @returns {Array} The closest pair of points on the polyline.
*/
export const findClosestPoints = (coordinates, newPoint, map) => {
if (!map) {
console.error("Map is not defined. Cannot find closest points.");