Modify

Opened 4 years ago

Closed 4 years ago

Last modified 4 years 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 4 years ago.
Probably needs some work around NamedColorProperty
19197.1.patch (2.9 KB ) - added by taylor.smock 4 years ago.
Use ColorHelper. No tests implemented.
19197.2.patch (6.0 KB ) - added by taylor.smock 4 years ago.
Add tests (extends FunctionsTest.testPref, and abstracts the base code for testing preferences)

Download all attachments as: .zip

Change History (9)

by taylor.smock, 4 years ago

Attachment: 19197.patch added

Probably needs some work around NamedColorProperty

comment:1 by simon04, 4 years ago

Unit tests would be very welcome for JOSM_pref/getPreferenceCached.

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

by taylor.smock, 4 years ago

Attachment: 19197.1.patch added

Use ColorHelper. No tests implemented.

comment:2 by simon04, 4 years ago

In 16583/josm:

see #19197 - Add FunctionsTest.testPref

comment:3 by simon04, 4 years ago

Milestone: 20.06

by taylor.smock, 4 years ago

Attachment: 19197.2.patch added

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

comment:4 by simon04, 4 years ago

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 by simon04, 4 years ago

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 by taylor.smock, 4 years ago

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. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.