[RFE] feature_label with custom text

classic Classic list List threaded Threaded
8 messages Options
AStef AStef
Reply | Threaded
Open this post in threaded view
|

[RFE] feature_label with custom text

Hi,

This is a small request for enhancement for feature_label model layers.
Style currently support text-attribute with a named style. It would be great to add some sort of customisation to the output text, so more than one attribute can be shown, or a constant text (a symbol for example).
Suggestion:
-keep "text-attribute:name" for basic labels and compatibility
-support "text-attributes:name1,name2,..." along with "text-attributes-format:format" with format a printf like syntax (or even simpler), and nameX the attributes to be used (list be may empty).
Does it make sense? Would it be a valuable contribution or is it too specific/complex to be included?

Thanks you!

Stef
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: [RFE] feature_label with custom text

Stef,

Agreed, this would be valuable. Another approach (vs. the printf-style) would be embedded tags like this, where you just enclose the attribute in square brackets.

    text-content: String containing [attribute] goes here
    text-content: [city], [stabbr]

That sort of thing.

Ultimately I envision full scripting support as well - using Lua for example - so you can do complex manipulations. But for now I think the simple approach is a welcome addition.

Glenn
Glenn Waldron / Pelican Mapping
AStef AStef
Reply | Threaded
Open this post in threaded view
|

Re: [RFE] feature_label with custom text

Hello,

I have done a small implementation based on your suggestion.
Style is completed with text-content and text-content-attribute-delimiter.
eg.:
text-content: City_$name,_$state
text-content-attribute-delimiter:$
($=default value).

Note: styles seems to remove all whitespace. Is this a bug or an oversight?
 
Here is the diff with r1135.
(Please bear with me if this is not the preferred way to suggest code and point me in the right direction)
diff -r src.r1135/osgEarthFeatures/BuildTextOperator.cpp src/osgEarthFeatures/BuildTextOperator.cpp
51d50
< 
54a54,94
> // Parse a content string and replace attributes (marked with delim) with their value
> // eg. "City $name, $state" -> "City San Fransisco, California" if delim is '$'
> // Attributes must be only a-zA-Z
> static std::string parseAttributes(Feature*           feature, 
>                                    const std::string& content,
>                                    const std::string& delim)
> {
>     if (delim.empty())
>         return content;
> 
>     static const std::string attr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
> 
>     std::string out;
>     size_t pos = 0;
>     while(true) {
>         // Search for an attribute delimiter
>         size_t d = content.find_first_of(delim, pos);
>         if (d==std::string::npos) {
>             // No more delimiters? add remaining text and we're done
>             out += content.substr(pos);
>             break;
>         }
>         // An attribute was found!
>         // Add non-attribute text
>         out += content.substr(pos, d-pos);
>         pos = d+1;
>         // Extract attribute name
>         d = content.find_first_not_of(attr, pos);
>         if (d==std::string::npos) {
>             // No more text after attribute? add attribute and we're done
>             out += feature->getAttr(content.substr(pos));
>             break;
>         }
>         // Add attribute and continue
>         out += feature->getAttr(content.substr(pos, d-pos));
>         pos = d;
>     }
> 
>     return out;
> }
> 
83a124,129
>         else if (symbol->content().isSet())
>         {
>             //Get the text from the specified content and referenced attributes
>             std::string content = symbol->content().value();
>             text = parseAttributes(feature, content, symbol->contentAttributeDelimiter().value());
>         }

diff -r src.r1135/osgEarthSymbology/SLD.cpp src/osgEarthSymbology/SLD.cpp
59a60,61
> #define CSS_TEXT_CONTENT          "text-content"
> #define CSS_TEXT_CONTENT_ATTRIBUTE_DELIMITER "text-content-attribute-delimiter"
147a150,159
>         else if (p->first == CSS_TEXT_CONTENT) {
>             if (!text)
>                 text = new TextSymbol;
>             text->content() = p->second;
>         }
>         else if (p->first == CSS_TEXT_CONTENT_ATTRIBUTE_DELIMITER) {
>             if (!text)
>                 text = new TextSymbol;
>             text->contentAttributeDelimiter() = p->second;
>         }

diff -r src.r1135/osgEarthSymbology/Text src/osgEarthSymbology/Text
62a63,68
>         
>         optional<std::string>& content() { return _content; }
>         const optional<std::string> content() const { return _content; }
>         
>         optional<std::string>& contentAttributeDelimiter() { return _contentAttributeDelimiter; }
>         const optional<std::string> contentAttributeDelimiter() const { return _contentAttributeDelimiter; }
93a100,101
>         optional<std::string>     _content;
>         optional<std::string>     _contentAttributeDelimiter;

diff -r src.r1135/osgEarthSymbology/Text.cpp src/osgEarthSymbology/Text.cpp
26a27
> _contentAttributeDelimiter( "$" ),
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: [RFE] feature_label with custom text

Stef,

This is a good start, however I do think the embedded attribute needs to have a beginning and an end delimiter, whether is be the same character (like $name$) or brackets (like [name]). Personally I prefer the latter but that is just me. You are assuming that attribute names can only consist of alphabetic characters but I don't think we can impose that restriction.

The value string should support whitespace; if it doesn't, this is a bug.

BTW for submissions you can just attach the whole file or files using the More Options -> Upload File feature. Thanks.

Glenn
Glenn Waldron / Pelican Mapping
AStef AStef
Reply | Threaded
Open this post in threaded view
|

Re: [RFE] feature_label with custom text

Hi,

I changed the code to reflect your suggestions. Actually, you are right, having an end delimiter is less restrictive on attribute name.

So now, there is for example:
text-content: City_[name],_[state]
text-content-attribute-delimiter: []
[] is the default value

Here is the patch from 1135:
diff1135.txt

I do confirm all whitespace are removed from value string. This is a separate issue and needs a fix.

Thank you.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: [RFE] feature_label with custom text

Thanks Stef.

If you don't mind, can you attach the full files that you changed? It's easier than processing the diff on my end. Thanks.

Glenn
Glenn Waldron / Pelican Mapping
AStef AStef
Reply | Threaded
Open this post in threaded view
|

Re: [RFE] feature_label with custom text

Sure,
here is a tar.gz of modified files.
from1135.tar.gz

BTW, you may want to remove support for text-attribute, so edit as you like :)

Stef.

gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: [RFE] feature_label with custom text

Stef,
This is committed. Thanks again.

Glenn
Glenn Waldron / Pelican Mapping