<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:"Comic Sans MS";
panose-1:3 15 7 2 3 3 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal;
font-family:"Times New Roman";
color:windowtext;
font-weight:normal;
font-style:normal;
text-decoration:none none;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Comic Sans MS";
color:blue;
font-weight:normal;
font-style:normal;
text-decoration:none none;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=3 color=blue face="Comic Sans MS"><span
style='font-size:12.0pt;font-family:"Comic Sans MS";color:blue'>I think that
you need to add a class with a label definition to your layer.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Comic Sans MS"><span
style='font-size:12.0pt;font-family:"Comic Sans MS";color:blue'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Comic Sans MS"><span
style='font-size:12.0pt;font-family:"Comic Sans MS";color:blue'>Here is how I
add a set of virtual layers to my map object before drawing it. I’m sorry I do
not have time this afternoon to distill it down to just the information you are
looking for. Things to notice that I am using update from string to update my
layer with a class which has style and label information. I have found that
the SYMBOL part of the updateFromText does not work thus the<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Comic Sans MS"><span
style='font-size:12.0pt;font-family:"Comic Sans MS";color:blue'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Comic Sans MS"><span
style='font-size:12.0pt;font-family:"Comic Sans MS";color:blue'> “</span></font><font
color=blue face="Courier New"><span style='font-family:"Courier New";
color:blue'>$style->set('symbolname',$virtualLayers[$i]->symbol);”<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Comic Sans MS"><span
style='font-size:12.0pt;font-family:"Comic Sans MS";color:blue'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Comic Sans MS"><span
style='font-size:12.0pt;font-family:"Comic Sans MS";color:blue'>statement which
would seem redundant but is necessary. Let me know if you cannot get the
required information from this example and I’ll help more.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>function
addVirtualLayers($ms, $virtualLayers) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> if
(isset($virtualLayers)) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> $newLayer =
array();<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> for ($i=0; $i
< sizeof($virtualLayers); $i++) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> $newLayer[$i]
= ms_newLayerObj($ms);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
$newLayer[$i]->set('type',$virtualLayers[$i]->layerType);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
#echo('layer type='.$virtualLayers[$i]->layerType);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
if($virtualLayers[$i]->layerType == MS_LAYER_POINT) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> $string =
'LAYER NAME VirtualLayer'.$i.' CLASS NAME SELECTEDPTS STYLE SYMBOL CROSS COLOR
255 0 200 SIZE 8 END LABEL TYPE truetype MINFEATURESIZE 50 MINDISTANCE 0
POSITION CR FONT vera SIZE 7 COLOR 255 0 255 END END END';<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> } else if
($virtualLayers[$i]->layerType == MS_LAYER_POLYGON) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> $string =
'LAYER NAME VirtualLayer'.$i.' CLASS NAME SELECTEDPOLYGONS STYLE OUTLINECOLOR
255 0 200 WIDTH 3 END LABEL TYPE truetype MINFEATURESIZE 50 MINDISTANCE 0
POSITION LC FONT vera SIZE 7 COLOR 255 0 255 END END END';<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> } else if
($virtualLayers[$i]->layerType == MS_LAYER_LINE) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> $string =
'LAYER NAME VirtualLayer'.$i.' CLASS NAME SELECTEDPOLYGONS STYLE COLOR 255 0 0
WIDTH 3 END LABEL TYPE truetype MINFEATURESIZE 50 MINDISTANCE 0 POSITION LC
FONT vera SIZE 7 COLOR 255 0 255 END END END';<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> }<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
$newLayer[$i]->updateFromString($string);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
#echo('layer type2 ='.$newLayer[$i]->type);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
$newLayer[$i]->set('status',MS_ON);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> $class =
$newLayer[$i]->getClass(0);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>#echo($virtualLayers[$i]->class);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
$class->updateFromString($virtualLayers[$i]->class); //returns
MS_SUCCESS | MS_FAILURE<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
if(isset($virtualLayers[$i]->symbol)) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> $style =
$class->getStyle($class->numstyles-1);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
$style->set('symbolname',$virtualLayers[$i]->symbol);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> }<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> $shape =
ms_shapeObjFromWkt($virtualLayers[$i]->shapeWkt);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>#
$shape->set('text', $i);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
if(isset($virtualLayers[$i]->labelText)) {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
$shape->set('text', $virtualLayers[$i]->labelText);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> }<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>
$newLayer[$i]->addFeature($shape);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> }<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'> }<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>}<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'>?><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New";color:blue'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Comic Sans MS"><span
style='font-size:12.0pt;font-family:"Comic Sans MS";color:blue'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=blue face="Comic Sans MS"><span
style='font-size:12.0pt;font-family:"Comic Sans MS";color:blue'><o:p> </o:p></span></font></p>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
mapserver-users-bounces@lists.osgeo.org
[mailto:mapserver-users-bounces@lists.osgeo.org] <b><span style='font-weight:
bold'>On Behalf Of </span></b>Helen Eskina<br>
<b><span style='font-weight:bold'>Sent:</span></b> Thursday, December 03, 2009
11:13 AM<br>
<b><span style='font-weight:bold'>To:</span></b>
mapserver-users@lists.osgeo.org<br>
<b><span style='font-weight:bold'>Subject:</span></b> [mapserver-users] How to
set Labels dynamically?</span></font><o:p></o:p></p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Hello,<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>I couldn’t find documentation how to set the text labels dynamically
using MapScript. <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>My application should show points with labels on the map. Points and labels
are obtained dynamically from the database or some text file.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>I add the points to the layer and draw layer as following:<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>$my_point = ms_newpointObj();<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> $my_point->setXY(-75.895, 45.9227);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> $my_point->project($projInObj,$projOutObj);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> $line = ms_newLineObj();<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>$line->add($my_point);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> $shape = ms_newShapeObj(MS_SHAPE_POINT);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> $shape->add($line);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> $shape->set(text, 'new point');<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> $daLayer->addFeature($shape);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>$image=$map->draw();<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>$daLayer->draw($image);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> $image_url=$image->saveWebImage();<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Points are displayed on the map, but no text. What am I doing wrong?<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>I will appreciate any help,<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Helen<o:p></o:p></span></font></p>
</div>
</body>
</html>
<P><FONT SIZE=2 FACE="Arial">No virus found in this incoming message.<BR>
Checked by AVG - www.avg.com<BR>
Version: 9.0.709 / Virus Database: 270.14.91/2542 - Release Date: 12/03/09 02:32:00<BR>
</FONT></P>
<P><FONT SIZE=2 FACE="Arial"> </FONT> </P>