Skip to content

feat: add map height legend to Tools > Units > Altitude - #1423

Open
Avengium wants to merge 8 commits into
Azgaar:masterfrom
Avengium:Altitude-legend
Open

feat: add map height legend to Tools > Units > Altitude#1423
Avengium wants to merge 8 commits into
Azgaar:masterfrom
Avengium:Altitude-legend

Conversation

@Avengium

@Avengium Avengium commented May 7, 2026

Copy link
Copy Markdown
Contributor

Description

A new button has been added to the altitude settings section that displays a visual legend. This legend helps users interpret the different elevation levels represented on the map.

Changes:

UI: A "View Legend" button has been added to Tools > Units > Altitude.

Component: New map legend pop-up that displays the color scale and its corresponding altitude values.

Logic: The legend chooses some representative points. Also updates the unit system that is shown (meters/feet).

How to test:
Go to the side menu and select Tools. Enter Units and then Altitude. Click it and confirm that the legend matches the colors displayed on the map. Switch from meters to feet and verify that the legend values ​​update correctly.

Screenshot

FMG altitude legend 2026-05-07
FMG-altitude-legend-2026-05-07-01jpg

Avengium added 2 commits May 7, 2026 19:26
Added a button on tools > units > altitude that shows a legend for different heights on the map.
@netlify

netlify Bot commented May 7, 2026

Copy link
Copy Markdown

Deploy Preview for afmg ready!

Name Link
🔨 Latest commit 2157fb4
🔍 Latest deploy log https://app.netlify.com/projects/afmg/deploys/6a26b47b9eaf210008f42966
😎 Deploy Preview https://deploy-preview-1423--afmg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Azgaar

Azgaar commented May 7, 2026

Copy link
Copy Markdown
Owner

For water we can show depth, like we do in Cell Details dialog.

@Azgaar

Azgaar commented May 7, 2026

Copy link
Copy Markdown
Owner

For the button - please just add it to other buttons at the bottom for now.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a “View Legend” control under Tools → Units → Altitude to show an on-map legend intended to help interpret the heightmap’s elevation colors, and updates legend contents when altitude exponent changes.

Changes:

  • Add a new “Height legend” button to the Units Editor (Altitude section) in src/index.html.
  • Wire up the button in public/modules/ui/units-editor.js to toggle a legend and generate representative height samples + labels.
  • Refresh the legend when the altitude exponent slider changes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.

File Description
src/index.html Adds the “Height legend” UI button in the Altitude (Units Editor) section.
public/modules/ui/units-editor.js Adds legend toggle + legend generation logic and refresh behavior tied to altitude exponent changes.

Comment thread src/index.html Outdated
Comment thread src/index.html Outdated
Comment thread public/modules/ui/units-editor.js Outdated
Comment thread public/modules/ui/units-editor.js Outdated
Comment thread public/modules/ui/units-editor.js Outdated
Comment thread public/modules/ui/units-editor.js Outdated
Comment on lines +166 to +172
const data = sampled.map(c => [rn(c.height, 0), c.color, rn(c.altitude, 1)]);

// Set the number of items per column
styleLegendColItems.value = data.length;

drawLegend(`Heights (in ${heightUnitName})`, data);

Comment thread public/modules/ui/units-editor.js
Comment thread public/modules/ui/units-editor.js
Comment thread public/modules/ui/units-editor.js Outdated
Comment thread public/modules/ui/units-editor.js Outdated
As suggested by Copilot.
Read the current heightmap scheme from the same source used by drawHeightmap (e.g., terrs.select(...).attr("scheme") or the style control) and pass it to getColorScheme.
So the colors used to represent different heights update with different style presets.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Avengium

Avengium commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

I don't know how to do any of these suggestions. Reading the comments, it seems there are many things I haven't considered. If anyone wants to carry out this PR, go ahead.

Avengium added 3 commits May 9, 2026 13:58
Deleted manual legend repositioning that overrides fitLegendBox() behavior.
On: public/modules/ui/editors.js
Cached the height counts/levels and only recompute the parts that depend on the exponent/unit.
* Labels now use the same calculation/conversion used by getHeight.
* Ocean height display correctly.
* legend has the unit close to each legend item.
@Avengium

Avengium commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

For water we can show depth, like we do in Cell Details dialog.

Done. With the new commit, ocean depth is measured too. And changes in units are updated.


For the button - please just add it to other buttons at the bottom for now.

Don't you think it makes more sense to keep the altitude button in the altitude section? Maybe putting it some pixels to the right, so it follows the indentation style.

Or would you prefer it to appear as a general feature unrelated to altitude?
I ask because if you change the altitude exponent or the altitude units, it changes in the legend.

I also planned to add a "slider" where the user can introduce the "amount" of representative heights the user can see on the legend (the amount of legend items). But the current option of a fixed "10 items" is fine too. Because there are only these colors.

@Avengium

Avengium commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

To find out what still needs updating, could you collapse the Copilot comments that have already been resolved and run Copilot again to check for any comments that still need to be implemented?

When changing the Height unit (m/ft/f), the legend also refreshes by doing that.
Without needing to delete and invoke the legend again.
@Avengium

Copy link
Copy Markdown
Contributor Author

This PR only adressess the heigthmap legend of issue 904 Add Keys for Climate and Height Maps #904
The key for a "climate" that is based on climate and not on biome will have to wait.

Moved id="altitudeLegend" button to unitsBottom section.
@Avengium

Avengium commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

I've moved the show/hide altitude legend button to the unitsbottom area.

What are the next steps to merge this PR?

FMG 1 122 Altitude Legend 2026-06-08 01

@Azgaar

Azgaar commented Jun 8, 2026

Copy link
Copy Markdown
Owner

I've moved the show/hide altitude legend button to the unitsbottom area.

What are the next steps to merge this PR?

Would need to review and test it properly. The idea is good, but implementation is not ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants