label with mapscript

joerg pfeiffer superbla3000 at GMX.NET
Thu Jul 5 14:52:37 PDT 2007


Hey Pietro,

thanks for your help. It seems my mapscript version is not up to date, 
so it doesn't know the ms_shapeObjFromWkt function. But I got it working 
with the following code. Only problem: It only prints one label, not as 
many labels, as I have in the array:

$LabelLayerObj = $this->map->getLayerByName($layername);
$labelpointObj = ms_newPointObj();
$labelLineObj = ms_newLineObj();
	
for ($i = 0; $i < count($pointlist); $i++){
			
	$labelpointObj->setXY(100+($i*2),100+($i*2));
	$labelLineObj ->add($labelpointObj);
	$labelshp = ms_newShapeObj(MS_SHAPE_POINT);
	$labelshp->set("text", $pointlist[$i] );
	$labelshp->add($labelLineObj);
}
		
$LabelLayerObj->addFeature($labelshp);

So if I know how to print more than one label, I would be very happy! :-)

cheers
Joerg






pgiannini at bytewise.it schrieb:
> Hi Joerg,
> 
> try:
> 
> 	$oMap = ms_newMapObj("your.map");
> 	// obtain the layer object:
> 	$oLay = $oMap->getLayerByName("citylabels");
> 	// obtain a shape object with the fields of a form (in this case they are
> named 'X' and 'Y'):
> 	$oShape = ms_shapeObjFromWkt("POINT(".$_REQUEST['X']."
> ".$_REQUEST['Y'].")");
> 	// set the text property of the shape object:
> 	$oShape->set("text","ciao");
> 	// add the shape to the layer:
> 	$oLay->addFeature($oShape);
> 	// draw the map:
> 	$oImage = $oMap->draw();
> 	$mapImage_url = $oImage->saveWebImage();
> 
> I tried and it works well.
> You can create how many features you want.
> Hope it is useful...
> 
> ciao
> .............................pg
> 
> 
> 
> 
> Pietro Giannini
> Bytewise srl - Area GIS
> 41°50'38.58"N 12°29'13.39"E
> 
> 
> 
> 
>> Hello,
>>
>> I have this simple layer:
>> LAYER
>> 	NAME "citylabels"
>> 	STATUS DEFAULT
>> 	TRANSFORM FALSE
>> 	TYPE ANNOTATION
>> 	FEATURE
>> 		POINTS
>> 			200 150
>> 		END
>> 		TEXT 'Hello world.  Mapserver rocks.'
>> 	END
>> 	CLASS
>> 		LABEL
>> 			TYPE BITMAP
>> 			COLOR 0 0 0
>> 		END
>> 	END
>> END
>>
>> and would like to set the place and the text dynamically with
>> php-mapscript.
>> Does anybody have a simple codesnippet?
>>
>> best regrads
>> Joerg
>>
> 
> 
> Pietro Giannini
> Bytewise srl - Area GIS
> 41°50'38.58"N 12°29'13.39"E
> 
> 



More information about the MapServer-users mailing list