Modify

Opened 8 weeks ago

Closed 3 weeks ago

Last modified 3 weeks ago

#19197 closed enhancement (fixed)

[RFC PATCH] Check if a pref could be converted to a color instead of a string

Reported by: taylor.smock Owned by: team
Priority: normal Milestone: 20.06
Component: Core mappaint Version:
Keywords: Cc:

Description

Example mapcss code:

way[regexp_test(concat("^(", JOSM_pref("mapwithai.mappaint.sources", "microsoft|digitalglobe"), ")$"), tag("source"))][setting("show_new")]:new {
    set .mapwithai;
    set_color: JOSM_pref(concat("mapwithai.mappaint.", tag("source"), "_new"), #FF00FF);
}
way[regexp_test(concat("^(", JOSM_pref("mapwithai.mappaint.sources", "microsoft|digitalglobe"), ")$"), tag("source"))][setting("show_old")]!:new!:modified {
    set .mapwithai;
    set_color: JOSM_pref(concat("mapwithai.mappaint.", tag("source"), "_old"), #FF00FF);
}
way[regexp_test(concat("^(", JOSM_pref("mapwithai.mappaint.sources", "microsoft|digitalglobe"), ")$"), tag("source"))][setting("show_modified")]:modified {
    set .mapwithai;
    set_color: JOSM_pref(concat("mapwithai.mappaint.", tag("source"), "_modified"), #FF00FF);
}

way.mapwithai {
    color: prop("set_color");
}

I would have preferred to do something like the following:

way[regexp_test(concat("^(", JOSM_pref("mapwithai.mappaint.sources", "microsoft|digitalglobe"), ")$"), tag("source"))][setting("show_new")]:new {
    set .mapwithai;
    set_color: concat("sources", "_new");
}
way[regexp_test(concat("^(", JOSM_pref("mapwithai.mappaint.sources", "microsoft|digitalglobe"), ")$"), tag("source"))][setting("show_old")]!:new!:modified {
    set .mapwithai;
    set_color: concat("sources", "_old");
}
way[regexp_test(concat("^(", JOSM_pref("mapwithai.mappaint.sources", "microsoft|digitalglobe"), ")$"), tag("source"))][setting("show_modified")]:modified {
    set .mapwithai;
    set_color: concat("sources", "_modified");
}

way.mapwithai {
    color: prop("set_color")#FF00FF;
}

Unfortunately, the latter doesn't work well (I've also tried wrapping prop in an eval expression, just in case there was special handling). I tried figuring out if there was a way for me to attempt to evaluate a color expression, when there is a default. I haven't seen one. :(

I am unable to hardcode all of the possible MapWithAI sources (you can add any third-party OSM-XML server source).

Attachments (3)

19197.patch (2.6 KB) - added by taylor.smock 8 weeks ago.
Probably needs some work around NamedColorProperty
19197.1.patch (2.9 KB) - added by taylor.smock 4 weeks ago.
Use ColorHelper. No tests implemented.
19197.2.patch (6.0 KB) - added by taylor.smock 4 weeks ago.
Add tests (extends FunctionsTest.testPref, and abstracts the base code for testing preferences)

Download all attachments as: .zip

Change History (9)

Changed 8 weeks ago by taylor.smock

Attachment: 19197.patch added

Probably needs some work around NamedColorProperty

comment:1 Changed 4 weeks ago by simon04

Unit tests would be very welcome for JOSM_pref/getPreferenceCached.

You might want to use org.openstreetmap.josm.tools.ColorHelper#color2html(java.awt.Color)

Changed 4 weeks ago by taylor.smock

Attachment: 19197.1.patch added

Use ColorHelper. No tests implemented.

comment:2 Changed 4 weeks ago by simon04

In 16583/josm:

see #19197 - Add FunctionsTest.testPref

comment:3 Changed 4 weeks ago by simon04

Milestone: 20.06

Changed 4 weeks ago by taylor.smock

Attachment: 19197.2.patch added

Add tests (extends FunctionsTest.testPref, and abstracts the base code for testing preferences)

comment:4 Changed 3 weeks ago by simon04

Resolution: fixed
Status: newclosed

In 16590/josm:

fix #19197 - MapCSS JOSM_pref: check if a pref could be converted to a color instead of a string (patch by taylor.smock, modified)

comment:5 Changed 3 weeks ago by simon04

Thanks. I've refactored/split the test function since I found hard to see what was actually being tested.

Help/Styles/MapCSSImplementation needs to be updated.

comment:6 Changed 3 weeks ago by taylor.smock

I've updated the JOSM_pref section of the help page. I specified the change, and what it now allows.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
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.