[mapserver-users] MapScript PHP label with expression and linebreak

Stephen Woodbridge stephenwoodbridge37 at gmail.com
Sat Mar 28 07:43:47 PDT 2020


When labeling with linebreaks, I insert an unique character like '@', so 
"[field1]@[field2]" and then on the label block add
WRAP "@"

Try that and see if it works for you.

-Steve W

On 3/28/2020 10:22 AM, Jean-Philippe Chenel wrote:
> Hi,
>
> Using MapScript PHP API, I want to create a label object (using 
> tostring expression) and put 2 columns with a linebreak between them.
> The example above is working well on a single line, but I don’t know 
> how to make the linebreak (carriage return).
>
> $text = "(tostring([vol],'%.2f')+'[vol]')";
> $classObj = new classObj($layer);
> $classObj->setText($text);
> $classObj->addLabel(CreateNewLabel($labelProperties));
>
> I've tried multiple combination of \r\n but none of them work (map 
> rendering work, but the label completely disappear).
> $text = "(tostring([vol],'%.2f') + '\r\n[vol]')";
> $text = "(tostring([vol],'%.2f') + '\r\n' + '[vol]')";
>
> If I don’t use the expression, the line break work
> $text = "'[vol]\r\n[vol]'";
>
> By the way, the TEXT property is on the classObj, the setText method 
> doesn’t work on the labelObj.
>
> With best regards,
>
> MapServer 7.4.4 (under ubuntu 16.04)
> PHP 5.6.40
>
> Jean-Philippe
>
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/mapserver-users



More information about the mapserver-users mailing list