#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)
Change History (9)
by , 5 years ago
Attachment: | 19197.patch added |
---|
comment:1 by , 5 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)
comment:3 by , 5 years ago
Milestone: | → 20.06 |
---|
by , 5 years ago
Attachment: | 19197.2.patch added |
---|
Add tests (extends FunctionsTest.testPref
, and abstracts the base code for testing preferences)
comment:5 by , 5 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 , 5 years ago
I've updated the JOSM_pref
section of the help page. I specified the change, and what it now allows.
Probably needs some work around NamedColorProperty