#6122 closed enhancement (fixed)
allow concat function in mapcss expressions
Reported by: | cmuelle8 | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Core mappaint | Version: | |
Keywords: | Cc: |
Description (last modified by )
- allow concat(Object... args) in mapcss to enable composing freeform labels
- word split the string in Label Composer
- if a word is a key for the prop, substitute the value
- else append the word as is
e.g.
text: eval(concat("smoothness -- ", "surface"));
will render something like "bad -- asphalt" if the tags are set accordingly.
Greetings
cmuelle8
Attachments (1)
Change History (20)
by , 14 years ago
Attachment: | mapcss-concat.patch added |
---|
comment:1 by , 14 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
comment:3 by , 14 years ago
Resolution: | duplicate |
---|---|
Status: | closed → reopened |
follow-up: 5 comment:4 by , 14 years ago
I'd like to use this ticket to discuss label composer part of the patch.
First question: What is the difference between
text: eval(concat("smoothness -- ", "surface"));
and
text: "smoothness -- surface";
?
follow-up: 6 comment:5 by , 14 years ago
None, it was just an example to explain it's use - usually, you would nest functions into the concat arguments, like
concat("way with surface: ", prop(surface-text), " and smoothness: ", prop(smoothness-text), " and width ", get_tag_value(width));
Replying to bastiK:
I'd like to use this ticket to discuss label composer part of the patch.
First question: What is the difference between
text: eval(concat("smoothness -- ", "surface"));and
text: "smoothness -- surface";?
comment:6 by , 14 years ago
Oh, maybe you read the explanation too quick. Again, the label composer will take any string
text1: "halli galli war auch mal name eines kartenspiels"; text2: "symbol und name sind osm tags";
Let's say an osm object is tagged with symbol=green_fence and name=Pfad, then the result for the texts will be
text1: "halli galli war auch mal Pfad eines kartenspiels"; text2: "green_fence und Pfad sind osm tags";
Concat is completely unrelated to what the label composer does, it just adds the string parts of it's arguments to form one, new concatenated string..
Greets
follow-up: 8 comment:7 by , 14 years ago
What if you want
node[amenity=restaurant][cuisine] { text: "\"name\" (cuisine)"; }
or something with colon, slash, comma or semicolon?
follow-up: 9 comment:8 by , 14 years ago
You can very easily do:
node[amenity=restaurant][cuisine] { text: "\" name \" ( cuisine )"; }
Tokens are determined by a simple space now. Of course you can always change the code to determine the words you do a tag lookup for with another grammar, like "${KEY}" (${KEY2}). Whoever needs it, can write a patch to modify and enhance current code. This is (was?) an OSS paradigm. There is always room for improvement, in any patch..
Most simple thing to realize the behavior you want, is to kill the last "space" in res and not append a new one for _any_ (but only if) substitution done. You would still need to correctly "space" the rule, but the result will be what you want..
Greetings
Replying to bastiK:
What if you want
node[amenity=restaurant][cuisine] { text: "\"name\" (cuisine)"; }or something with colon, slash, comma or semicolon?
comment:9 by , 14 years ago
Replying to anonymous:
You can very easily do:
node[amenity=restaurant][cuisine] { text: "\" name \" ( cuisine )"; }Tokens are determined by a simple space now. Of course you can always change the code to determine the words you do a tag lookup for with another grammar, like "${KEY}" (${KEY2}). Whoever needs it, can write a patch to modify and enhance current code. This is (was?) an OSS paradigm. There is always room for improvement, in any patch..
With your patch you implicitly propose an extension to the MapCSS standard. People will start to use the feature and it may find its way in other MapCSS implementations. Standards can evolve as well, of course, but it's much more painful when you have to break backwards compatibility. This is why I would prefer a more fully developed solution that we can be satisfied with, as it stands.
If it was called
text-format-by-christian: "smoothness -- surface";
it couldn't say much against it because it would be obvious that it's one method among others.
follow-up: 11 comment:10 by , 14 years ago
For the record, it would be useful to have something like:
text-...: "smoothness - {smoothness}, surface - {surface}";
Where the Strings in curly brackets get replaced. AFAIK, with you patch you have to write "SMOOTHNESS - smoothness , SURFACE - surface" or something like that.
comment:11 by , 14 years ago
Replying to bastiK:
For the record, it would be useful to have something like:
text-...: "smoothness - {smoothness}, surface - {surface}";Where the Strings in curly brackets get replaced. AFAIK, with you patch you have to write "SMOOTHNESS - smoothness , SURFACE - surface" or something like that.
right, or append a colon. your arguments about evolving standards are very plausible, thx. but then, if we want to do best we can, question is, how is variable substitution done elsewhere in the mapcss / JOSM / OSM universe? is using curly braces found elsewhere? or what about other CSS implementations? if not, I suggest using sh shell compatibility - ${var}. for me curly braces would suffice, you know if this method is found some place else?
comment:12 by , 14 years ago
I'm not aware of something like this in any MapCSS implementation or elsewhere in OSM (but I don't know much of this universe :) ). In JOSM, the TMS URL is created like this:
tms:http://oatile1.mqcdn.com/naip/{zoom}/{x}/{y}.png
But I suppose this is not a strong argument.
Regarding Shell compatibility: The analogy is only limited as shell variables must be C identifiers but a tag key can be an arbitrary string. Colon and dash are quite common actually. I think this syntax is inspired by Perl hashes, where you would write $tags{smoothness
} or $tags->{smoothness
}. (But in Perl it has to be quoted if the key is not an identifier.)
comment:15 by , 14 years ago
see #6150
text: ...
is a little overloaded by now, so the following syntax would be an alternative:
text: format; text-format: ...;
comment:16 by , 14 years ago
Type: | defect → enhancement |
---|
comment:17 by , 14 years ago
Summary: | [PATCH] allow concat function in mapcss expressions → allow concat function in mapcss expressions |
---|
comment:18 by , 10 years ago
Description: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | reopened → closed |
comment:19 by , 10 years ago
Component: | Core → Core mappaint |
---|
superseded by #6129