[Mapserver-users] Getting Position of the Label text as MS will place it

PATTERSON KENNETH ALLEN kapatter at srpnet.com
Thu Apr 29 18:27:12 EDT 2004


Yes Lowell your example got me going, thanks. 

The most unfortunate thing is that I'll have to calculate the size of the bounding box.  It sure seems as if the intent is to have member labelCacheMemberObj->{poly} provide this information.  "poly" does seem to be filled in.  Unless you know otherwise, I'll have to calculate the bounding box.  The only way I can think to do this is get the label feature min/max size and the "scale data" doing some calculations. (??)

I can get the upper left pixel point (I think) of the text label (pointObj) and I can correlate the label drawn to the layer and class (layerindex).  The following code helped me get the values of the labelCacheMemberObj object once the MS object has been drawn.

sub ProcessLabelCache {
	my $map = shift;
	my $label;
	
	print "In ProcessLableCahe( $map )\n";
	while ( $label = $map->nextLabel() ) {
	 	print "\t\tlabel Cach: \n";
		print "\t\t\tclassindex=$label->{classindex}\n";
		print "\t\t\tfeaturesize=$label->{featuresize}\n";
		print "\t\t\ttileindex=$label->{tileindex}\n";
		print "\t\t\tlabel=$label->{label}\n";	  
		print "\t\t\t\tlabel->{sizescaled}=$label->{label}->{sizescaled}\n"; 
		print "\t\t\t\tlabel->{font}=$label->{label}->{font}\n"; 
		print "\t\t\t\tlabel->{min/maxsize}=$label->{label}->{minsize}, $label->{label}->{maxsize}\n"; 
		my $layer = $map->getLayer( $label->{layerindex} );
		print "\t\t\tlayerindex=$label->{layerindex}, name=$layer->{name}\n";
		print "\t\t\tnumstyles=$label->{numstyles}\n";		  
		print "\t\t\tshapeindex=$label->{shapeindex}\n";		  
		print "\t\t\tstatus=$label->{status}\n";
		print "\t\t\tstring=$label->{string}\n";
		my $shape = $label->{poly};	
		print "\t\t\tpoly=$label->{poly}\n";		
		print "\t\t\t\tbounds = $shape->{bounds}: $shape->{bounds}->{minx}, $shape->{bounds}->{maxx} $shape->{bounds}->{miny}, $shape->{bounds}->{maxy}\n";
		print "\t\t\t\tclassindex = $shape->{classindex}\n";
		print "\t\t\t\tindex = $shape->{index}\n";
		print "\t\t\t\tline = $shape->{line}\n";
		print "\t\t\t\ttext = $shape->{text}\n";
		print "\t\t\t\ttype = $shape->{type}\n";
		print "\t\t\t\tvalues = $shape->{values}\n";
		print "\t\t\tpoint=$label->{point}: $label->{point}->{x}, $label->{point}->{y}\n";		
		print "\t\t\tstyles=$label->{styles}\n";			
	}

}

The documentation is close but not quite right.  Is their a preferred method for updateing the docs?  

	There is no member labelCacheMemberObj->{class}.
	Member labelCacheMemberObj->{layeridx} is labelCacheMemberObj->{layerindex}

3) Not much (if any) of the labelCacheMemberObj member {poly} is getting filled in.

	labelCacheMemberObj->{poly} is not filed in.


Thanks,
	Ken

-----Original Message-----
From: Lowell Filak [mailto:lfilak at medinaco.org]
Sent: Thursday, April 29, 2004 12:54 PM
To: PATTERSON KENNETH ALLEN; mapserver-users at lists.gis.umn.edu
Subject: Re: [Mapserver-users] Getting Position of the Label text as MS
will place it


If you incorporate mapscript you can loop through each label in the
labelcache and pickup the polygon (shapeobj) for each of them.
The following code is a quick cut from a 3.6 app but I believe it should
work with 4 & remember to alter the code to use the label
(labelcachememberobject) polygon instead of the point.

#
# Loop through each label in the cache and print string and point x,y.
while ( $label = $map->nextLabel() ) {
  if ( $label->{status} ) {
    my $point = $label->{point};
    #
    # Create the imagemap box for the label.
    $bminx[$spncnt] = $point->{x} - 15;
    $bminy[$spncnt] = $point->{y} - 10;
    $bmaxx[$spncnt] = $point->{x} + 15;
    $bmaxy[$spncnt] = $point->{y} + 10;
    $ppn[$spncnt] = $label->{shapeidx};
    $spncnt = $spncnt + 1;
  }
}

HTH

Lowell

The following message was sent by "PATTERSON KENNETH ALLEN"
<kapatter at srpnet.com> on Thu, 29 Apr 2004 11:11:39 -0700.

> 
> In our app we create a HTML map used to position popup information
when the cursor is positions at a specific place on the image.  The user
can hover the cursor over a point and information will display.  We use
Perl to program the site.  
> 
> It would be very useful for us if we can query the position that MS
draws the labels at.  Use the following layer definition as the example:
 How can we get each  bounding box of the text label that is drawn (i.e.
TEXT "Col_label_nm")?
> 
> We are able to get the shape index from the query result set etc.. 
I'm guessing that since we can't find anything exposed we will need to
do the same calculations that MS is doing to get the text bounding box.
 Is this going to get way to tricky?  Should we find another UI
solution?  Anybody done this before?  Suggestions?
> 
> Thanks,
> 	Ken
> 
> 
> LAYER
>    NAME "Stuff"
>    GROUP Geographical
>    TYPE  POLYGON
>    STATUS on
>    template "dummy"
>    DATA "/.../stuff.shp"
>    CLASS
>     	NAME 'aclass'
>    	OUTLINECOLOR 200 200 200
> 	TEXT ([Col_label_nm])
>     	LABEL
> 	  	TYPE TRUETYPE
> 	  	FONT helmetBI
> 	  	antialias off
> 	  	COLOR 255 0 0  
> 		MINSIZE 10
> 		MAXSIZE 14
> 		POSITION AUTO
> 		PARTIALS FALSE
> 	END # Label
>   END # Class
> END # Stuff Layer
> 
> 
> 
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users







More information about the mapserver-users mailing list