Hi Helen,
this sample-script should work:
---schnipp------
<?php
//1. Map-Object and Image
$blank_map_object = ms_newMapObj('your path to the sample mapfile below');
$blank_map_object->preparequery();
$blank_map_image = $blank_map_object->prepareImage();
//2. LAYER
$draw_layer = ms_newLayerObj($blank_map_object);
$draw_layer->set('type', MS_LAYER_POINT);
$draw_layer->set('status', MS_ON);
//3. CLASS, STYLE and LABEL
$new_class = ms_newClassObj($draw_layer);
$new_style = ms_newStyleObj($new_class);
$label_obj = $new_class->label;
$label_obj->set('size', 25);
$label_obj->set('type', MS_TRUETYPE);
//Path to arial.ttf must be defined in test_fontset.txt
$label_obj->set('font', 'arial');
$label_obj->set('angle', 30);
//0x007E is the "~" sign
$label_obj->set('wrap', 0x007E);
$label_obj->color->setRGB(0,255,0);
$label_obj->backgroundcolor->setRGB(0,0,255);
$label_obj->backgroundshadowcolor->setRGB(200,200,200);
$label_obj->set('backgroundshadowsizex', 15);
$label_obj->set('backgroundshadowsizey', 15);
//...and so on
//4. Shape with label
$draw_shape = ms_shapeObjFromWkt('POINT(2502500 5602500)');
$draw_shape->set('text', ' ~ Hello World!~ Mapserver is cool... ~');
$draw_layer->addFeature($draw_shape);
$draw_layer->draw($blank_map_image);
//5. Shape to Image
$blank_map_object->drawLabelCache($blank_map_image);
$blank_map_object->labelcache->free();
//6. ready
$image_url=$blank_map_image->saveWebImage();
echo "<img src='$image_url'/>";
?>
---schnapp------

With mini-mapfile:
---schnipp------
MAP
   name "test"
   fontset "your path to the fontset"
   units meters
   extent 2500000 5600000 2505000 5605000
   size 800 600
   imagecolor 255 255 255
   WEB
       imagepath "your path to tmp-directory"
       imageurl "your url to tmp-directory"
   END
END
---schnapp------

Regards
Ludwig


Helen Eskina schrieb:
Hi,

My $daLayer is defined dynamically. How should I define Label-Section in
this case?
$daLayer->set("type", MS_LAYER_POINT);
$daLayer->set("status", MS_ON);
 $class = ms_newClassObj($daLayer);
 $style = ms_newStyleObj($class);
 $style->color->setRGB(255,0,0);
 $style->set("symbolname", "circle");
 $style->set("size", 10);

Thank you,
Helen
-----Original Message-----
From: Ludwig Kniprath [mailto:lud...@kni-online.de]
Sent: Thursday, December 03, 2009 4:57 PM
To: Helen Eskina; mapserver-users@lists.osgeo.org
Subject: Re: How to set Labels dynamically

Oops, you're right, "drawLabelCache" is a method of the map-object, but
all the same it works for me!
Perhaps a missing LABEL-Section in the mapfile-definition of your
$daLayer?
Regards
Ludwig

Helen Eskina schrieb:
Hi Ludwig,

Layer object doesn't have DrawLabelCache method. I've tried this line
and
got an error. I'm using Mapserver installed with fgs 5.4.2.

I've tried
 $map-> drawLabelCache($image);
But it doesn't make any difference.

Helen
-----Original Message-----
From: Ludwig Kniprath [mailto:lud...@kni-online.de]
Sent: Thursday, December 03, 2009 12:13 PM
To: mapserver-users@lists.osgeo.org
Cc: hesk...@ubitech.com
Subject: RE: How to set Labels dynamically

Hi,
I think there's only one line missing after $daLayer->draw($image):

$daLayer->drawLabelCache($image);

Regards
Ludwig


Message: 6
Date: Thu, 3 Dec 2009 11:13:10 -0500
From: Helen Eskina <hesk...@ubitech.com>
Subject: [mapserver-users] How to set Labels dynamically?
To: mapserver-users@lists.osgeo.org
Message-ID: <5cde4e2f906f4ce9b22afedb42cd0...@skysource>
Content-Type: text/plain; charset="windows-1252"

Hello,



I couldn't find documentation how to set the text labels dynamically

using

MapScript.

My application should show points with labels on the map. Points and

labels

are obtained dynamically from the database or some text file.

I add the points to the layer and draw layer as following:



$my_point = ms_newpointObj();



$my_point->setXY(-75.895, 45.9227);

$my_point->project($projInObj,$projOutObj);



$line = ms_newLineObj();

$line->add($my_point);

$shape = ms_newShapeObj(MS_SHAPE_POINT);

$shape->add($line);

$shape->set(text, 'new point');

$daLayer->addFeature($shape);



$image=$map->draw();

$daLayer->draw($image);

$image_url=$image->saveWebImage();



Points are displayed on the map, but no text. What am I doing wrong?



I will appreciate any help,

Helen


_______________________________________________
mapserver-users mailing list
mapserver-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-users

Reply via email to