Opened 9 months ago

Closed 6 months 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:


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)

josm-units.patch (4.7 KB) - added by anonymous 9 months ago.
Core patch for UnitScale plugin
UnitScale.tgz (8.8 KB) - added by anonymous 9 months ago.
UnitScale plugin source code

Download all attachments as: .zip

Change History (8)

comment:1 Changed 9 months ago by anonymous

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.

Changed 9 months ago by anonymous

Attachment: josm-units.patch added

Core patch for UnitScale plugin

Changed 9 months ago by anonymous

Attachment: UnitScale.tgz added

UnitScale plugin source code

comment:2 Changed 9 months ago by anonymous

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 Changed 9 months ago by skyper

Summary: Add ability to add systems of measurement at runtime[Patch] Add ability to add systems of measurement at runtime

comment:4 Changed 9 months ago by anonymous

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 Changed 8 months ago by simon04

Owner: changed from team to anonymous
Status: newneedinfo

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/

    diff --git a/src/org/openstreetmap/josm/data/ b/src/org/openstreetmap/josm/data/
    index 61c80604c..86a93c882 100644
    a b  
    7474     * Known systems of measurement.
    7575     * @since 3406
    7676     */
    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;
     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    }
    8186    /**
    8287     * Preferences entry for system of measurement.

comment:6 Changed 6 months ago by simon04

Resolution: needinfo
Status: needinfoclosed

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain anonymous.
as The resolution will be set.
The resolution will be deleted.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.