Opened 5 years ago
Closed 4 years ago
#19545 closed enhancement (needinfo)
[Patch] Add ability to add systems of measurement at runtime
Reported by: | anonymous | Owned by: | anonymous |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Core | Version: | |
Keywords: | units, plugin | Cc: |
Description
The current system of measurement system works great but it's impossible to add systems outside of hardcoding them in the class. This is a problem for fantasy mappers who create maps of planets other than Earth or who simply use units other than the common ones and don't know how to write Java.
My (very limited) knowledge of Java tells me that the ALL_SYSTEMS variable in the SystemsOfMeasurement class could be made to a regular map and an addSystem or w/e method could be added for plugins to use. This would allow the addition of arbitrary units like an adjusted meter for fantasy worlds or entirely custom units.
Attachments (2)
Change History (8)
comment:1 by , 5 years ago
comment:2 by , 5 years ago
I have attached the necessary modifications to allow units to be editable as well as a change to the OSM XML format which adds a scale= parameter corresponding to the circumference relative to Earth the map represents.
I have also attached a plugin (UnitScale) that uses the changes to add a scale planet dialog that scales the planet by scaling all units, as well as a preference tab that allows someone to add units.
comment:3 by , 5 years ago
Summary: | Add ability to add systems of measurement at runtime → [Patch] Add ability to add systems of measurement at runtime |
---|
comment:4 by , 5 years ago
Here's a bit of a usage guide for UnitScale:
To scale the planet create a new layer or open an existing one then click Data/Unit scale and fill out the details about the planet size. Once filled out it will save the details to the currently edited layer (if present). Once the layer is saved the planet scale is also saved, and will automatically be scaled to the correct size when loaded.
To edit units (or create new ones) go to Edit/Preferences and click on the tab with no icon titled "Change units" and fill out the details. Click on the first combo box and set to New unit if you want to create a new unit. Changes are saved when OK is pressed. The unit change tab lets you define units in terms of other systems as well.
comment:5 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → needinfo |
Both of your changes in attachment:josm-units.patch introduce a bunch of problems / maintenance efforts without any gain for the OpenStreetMap project.
For the system of measurement, we could add a static initializer which obtains a supplementary from the preferences: –
-
src/org/openstreetmap/josm/data/SystemOfMeasurement.java
diff --git a/src/org/openstreetmap/josm/data/SystemOfMeasurement.java b/src/org/openstreetmap/josm/data/SystemOfMeasurement.java index 61c80604c..86a93c882 100644
a b 74 74 * Known systems of measurement. 75 75 * @since 3406 76 76 */ 77 public static final Map<String, SystemOfMeasurement> ALL_SYSTEMS = Collections.unmodifiableMap( 78 Stream.of(METRIC, CHINESE, IMPERIAL, NAUTICAL_MILE) 79 .collect(Collectors.toMap(SystemOfMeasurement::getName, Function.identity()))); 77 public static final Map<String, SystemOfMeasurement> ALL_SYSTEMS; 78 79 static { 80 // TODO add supplementary system using Config.getPref() 81 ALL_SYSTEMS = Collections.unmodifiableMap( 82 Stream.of(METRIC, CHINESE, IMPERIAL, NAUTICAL_MILE) 83 .collect(Collectors.toMap(SystemOfMeasurement::getName, Function.identity()))); 84 } 80 85 81 86 /** 82 87 * Preferences entry for system of measurement.
comment:6 by , 4 years ago
Resolution: | → needinfo |
---|---|
Status: | needinfo → closed |
After experimenting removing the final from the ALL_SYSTEMS variable and making it a normal map allows for a plugin to add a system of measurement dynamically. This could be wrapped in a nice config GUI for better use. In this bare state systems of measurement can also be removed. It should be put behind an adder/remover probably.