diff --git a/modules/export.js b/modules/export.js index 86e746cd..4a9abd9f 100644 --- a/modules/export.js +++ b/modules/export.js @@ -450,7 +450,7 @@ function saveGeoJSON_Rivers() { function saveGeoJSON_Markers() { const features = pack.markers.map(marker => { const {i, type, icon, x, y, size, fill, stroke} = marker; - const coordinates = getQGIScoordinates(x, y); + const coordinates = getCoordinates(x, y, 4); const id = `marker${i}`; const note = notes.find(note => note.id === id); const properties = {id, type, icon, ...note, size, fill, stroke}; @@ -465,7 +465,7 @@ function saveGeoJSON_Markers() { function getCellCoordinates(vertices) { const p = pack.vertices.p; - const coordinates = vertices.map(n => getQGIScoordinates(p[n][0], p[n][1])); + const coordinates = vertices.map(n => getCoordinates(p[n][0], p[n][1], 2)); return [coordinates.concat([coordinates[0]])]; } @@ -475,7 +475,7 @@ function getRoutePoints(node) { const increment = l / Math.ceil(l / 2); for (let i = 0; i <= l; i += increment) { const p = node.getPointAtLength(i); - points.push(getQGIScoordinates(p.x, p.y)); + points.push(getCoordinates(p.x, p.y, 4)); } return points; } @@ -487,7 +487,7 @@ function getRiverPoints(node) { for (let i = l, c = i; i >= 0; i -= increment, c += increment) { const p1 = node.getPointAtLength(i); const p2 = node.getPointAtLength(c); - const [x, y] = getQGIScoordinates((p1.x + p2.x) / 2, (p1.y + p2.y) / 2); + const [x, y] = getCoordinates((p1.x + p2.x) / 2, (p1.y + p2.y) / 2, 4); points.push([x, y]); } return points; diff --git a/modules/ui/burgs-overview.js b/modules/ui/burgs-overview.js index 5d02930b..9b6e0d9e 100644 --- a/modules/ui/burgs-overview.js +++ b/modules/ui/burgs-overview.js @@ -456,7 +456,7 @@ function overviewBurgs() { } function downloadBurgsData() { - let data = `Id,Burg,Province,Province Full Name,State,State Full Name,Culture,Religion,Population,Longitude,Latitude,Elevation (${heightUnit.value}),Capital,Port,Citadel,Walls,Plaza,Temple,Shanty Town`; // headers + let data = `Id,Burg,Province,Province Full Name,State,State Full Name,Culture,Religion,Population,Latitude,Longitude,Elevation (${heightUnit.value}),Capital,Port,Citadel,Walls,Plaza,Temple,Shanty Town`; // headers if (options.showMFCGMap) data += `,City Generator Link`; data += "\n"; @@ -475,8 +475,8 @@ function overviewBurgs() { data += rn(b.population * populationRate * urbanization) + ","; // add geography data - data += mapCoordinates.lonW + (b.x / graphWidth) * mapCoordinates.lonT + ","; - data += mapCoordinates.latN - (b.y / graphHeight) * mapCoordinates.latT + ","; // this is inverted in QGIS otherwise + data += getLatitude(b.y, 2) + ","; + data += getLongitude(b.x, 2) + ","; data += parseInt(getHeight(pack.cells.h[b.cell])) + ","; // add status data diff --git a/modules/ui/general.js b/modules/ui/general.js index 51d0ae1e..356b3668 100644 --- a/modules/ui/general.js +++ b/modules/ui/general.js @@ -228,8 +228,8 @@ function updateCellInfo(point, i, g) { const x = (infoX.innerHTML = rn(point[0])); const y = (infoY.innerHTML = rn(point[1])); const f = cells.f[i]; - infoLat.innerHTML = toDMS(mapCoordinates.latN - (y / graphHeight) * mapCoordinates.latT, "lat"); - infoLon.innerHTML = toDMS(mapCoordinates.lonW + (x / graphWidth) * mapCoordinates.lonT, "lon"); + infoLat.innerHTML = toDMS(getLatitude(y, 4), "lat"); + infoLon.innerHTML = toDMS(getLongitude(x, 4), "lon"); infoCell.innerHTML = i; const unit = areaUnit.value === "square" ? " " + distanceUnitInput.value + "²" : " " + areaUnit.value; diff --git a/utils/commonUtils.js b/utils/commonUtils.js index a88c75f6..5f6c5742 100644 --- a/utils/commonUtils.js +++ b/utils/commonUtils.js @@ -137,10 +137,16 @@ function generateDate(from = 100, to = 1000) { return new Date(rand(from, to), rand(12), rand(31)).toLocaleDateString("en", {year: "numeric", month: "long", day: "numeric"}); } -function getQGIScoordinates(x, y) { - const cx = mapCoordinates.lonW + (x / graphWidth) * mapCoordinates.lonT; - const cy = mapCoordinates.latN - (y / graphHeight) * mapCoordinates.latT; // this is inverted in QGIS otherwise - return [cx, cy]; +function getLongitude(x, decimals = 2) { + return rn(mapCoordinates.lonW + (x / graphWidth) * mapCoordinates.lonT, decimals); +} + +function getLatitude(y, decimals = 2) { + return rn(mapCoordinates.latN - (y / graphHeight) * mapCoordinates.latT, decimals); +} + +function getCoordinates(x, y, decimals = 2) { + return [getLongitude(x, decimals), getLatitude(y, decimals)]; } // prompt replacer (prompt does not work in Electron)