diff --git a/index.html b/index.html index 90af6a46..c469499a 100644 --- a/index.html +++ b/index.html @@ -3221,8 +3221,9 @@
Cell: 0
-Coord: 0/0
+Cell: X: Y:
+Latitude:
+Longitude:
Area: 0
Type: n/a
Precipitation: 0
diff --git a/modules/ui/general.js b/modules/ui/general.js index b5c34aba..51048f76 100644 --- a/modules/ui/general.js +++ b/modules/ui/general.js @@ -128,8 +128,11 @@ function getRiverName(id) { // get cell info on mouse move function updateCellInfo(point, i, g) { const cells = pack.cells; - infoX.innerHTML = rn(point[0]); - infoY.innerHTML = rn(point[1]); + const x = infoX.innerHTML = rn(point[0]); + const y = infoY.innerHTML = rn(point[1]); + infoLat.innerHTML = toDMS(mapCoordinates.latN - (y / graphHeight) * mapCoordinates.latT, "lat"); + infoLon.innerHTML = toDMS(mapCoordinates.lonW + (x / graphWidth) * mapCoordinates.lonT, "lon"); + infoCell.innerHTML = i; const unit = areaUnit.value === "square" ? " " + distanceUnitInput.value + "²" : " " + areaUnit.value; infoArea.innerHTML = cells.area[i] ? si(cells.area[i] * distanceScaleInput.value ** 2) + unit : "n/a"; @@ -149,6 +152,16 @@ function updateCellInfo(point, i, g) { infoBiome.innerHTML = biomesData.name[cells.biome[i]]; } +// convert coordinate to DMS format +function toDMS(coord, c) { + const degrees = Math.floor(Math.abs(coord)); + const minutesNotTruncated = (Math.abs(coord) - degrees) * 60; + const minutes = Math.floor(minutesNotTruncated); + const seconds = Math.floor((minutesNotTruncated - minutes) * 60); + const cardinal = c === "lat" ? coord >= 0 ? "N" : "S" : coord >= 0 ? "E" : "W"; + return degrees + "° " + minutes + "′ " + seconds + "″ " + cardinal; +} + // get user-friendly (real-world) height value from map data function getFriendlyHeight(p) { const packH = pack.cells.h[findCell(p[0], p[1])]; diff --git a/modules/ui/heightmap-editor.js b/modules/ui/heightmap-editor.js index fb867b7a..fd70c905 100644 --- a/modules/ui/heightmap-editor.js +++ b/modules/ui/heightmap-editor.js @@ -307,9 +307,20 @@ function editHeightmap() { pack.cells.religion[i] = religion[g]; } + // find closest land cell to burg + const findBurgCell = function(x, y) { + let i = findCell(x, y); + if (pack.cells.h[i] >= 20) return i; + const dist = pack.cells.c[i].map(c => + pack.cells.h[c] < 20 ? Infinity : (pack.cells.p[c][0] - x) ** 2 + (pack.cells.p[c][1] - y) ** 2 + ); + return pack.cells.c[i][d3.scan(dist)]; + } + + // find best cell for burgs for (const b of pack.burgs) { if (!b.i || b.removed) continue; - b.cell = findCell(b.x, b.y); + b.cell = findBurgCell(b.x, b.y); b.feature = pack.cells.f[b.cell]; pack.cells.burg[b.cell] = b.i; if (!b.capital && pack.cells.h[b.cell] < 20) removeBurg(b.i);